Add command line options to debugger
https://codereview.appspot.com/7221048/
git-svn-id: http://skia.googlecode.com/svn/trunk@7418 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index 4486434..7e04657 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -581,12 +581,15 @@
void SkDebuggerGUI::openFile() {
QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
tr("Files (*.*)"));
+ openFile(temp);
+}
+
+void SkDebuggerGUI::openFile(const QString &filename) {
fDirectoryWidgetActive = false;
- if (!temp.isEmpty()) {
- QFileInfo pathInfo(temp);
- fPath = pathInfo.path();
- loadPicture(SkString(temp.toAscii().data()));
- setupDirectoryWidget();
+ if (!filename.isEmpty()) {
+ QFileInfo pathInfo(filename);
+ loadPicture(SkString(filename.toAscii().data()));
+ setupDirectoryWidget(pathInfo.path());
}
fDirectoryWidgetActive = true;
}
@@ -838,9 +841,8 @@
// TODO(chudy): Remove static call.
fDirectoryWidgetActive = false;
- fPath = "";
fFileName = "";
- setupDirectoryWidget();
+ setupDirectoryWidget("");
fDirectoryWidgetActive = true;
// Menu Bar
@@ -889,8 +891,9 @@
QMetaObject::connectSlotsByName(SkDebuggerGUI);
}
-void SkDebuggerGUI::setupDirectoryWidget() {
- QDir dir(fPath);
+void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
+ fPath = path;
+ QDir dir(path);
QRegExp r(".skp");
fDirectoryWidget.clear();
const QStringList files = dir.entryList();
diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h
index 75d3f28..6d57a8a 100644
--- a/debugger/QT/SkDebuggerGUI.h
+++ b/debugger/QT/SkDebuggerGUI.h
@@ -57,6 +57,17 @@
~SkDebuggerGUI();
+ /**
+ Updates the directory widget with the latest directory path stored in
+ the global class variable fPath.
+ */
+ void setupDirectoryWidget(const QString& path);
+
+ /**
+ Loads the specified file.
+ */
+ void openFile(const QString& filename);
+
signals:
void commandChanged(int command);
@@ -169,7 +180,7 @@
/**
Toggles a dialog with a file browser for navigating to a skpicture. Loads
- the seleced file.
+ the selected file.
*/
void openFile();
@@ -308,12 +319,6 @@
void setupOverviewText(const SkTDArray<double>* typeTimes, double totTime);
/**
- Updates the directory widget with the latest directory path stored in
- the global class variable fPath.
- */
- void setupDirectoryWidget();
-
- /**
Render the supplied picture several times tracking the time consumed
by each command.
*/
diff --git a/debugger/debuggermain.cpp b/debugger/debuggermain.cpp
index 86a4574..8440052 100644
--- a/debugger/debuggermain.cpp
+++ b/debugger/debuggermain.cpp
@@ -9,9 +9,51 @@
#include "SkDebuggerGUI.h"
#include <QApplication>
+static void usage(const char * argv0) {
+ SkDebugf("%s <input> \n", argv0);
+ SkDebugf(" [--help|-h]: show this help message\n");
+ SkDebugf("\n\n");
+ SkDebugf(" input: Either a directory or a single .skp file.\n");
+}
+
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
+
+ QStringList argList = a.arguments();
+
+ if (argList.count() <= 0) {
+ return -1; // should at least have command name
+ }
+
+ SkString input;
+
+ QStringList::const_iterator iter = argList.begin();
+
+ SkString commandName(iter->toAscii());
+ ++iter; // skip the command name
+
+ for ( ; iter != argList.end(); ++iter) {
+ if (0 == iter->compare("--help") || 0 == iter->compare("-h")) {
+ usage(commandName.c_str());
+ return -1;
+ } else if (input.isEmpty()) {
+ input = SkString(iter->toAscii());
+ } else {
+ usage(commandName.c_str());
+ return -1;
+ }
+ }
+
SkDebuggerGUI w;
+
+ if (!input.isEmpty()) {
+ if (SkStrEndsWith(input.c_str(), ".skp")) {
+ w.openFile(input.c_str());
+ } else {
+ w.setupDirectoryWidget(input.c_str());
+ }
+ }
+
w.show();
return a.exec();
}