Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: tools/flags/SkCommandLineFlags.cpp

Issue 854193003: tool --help alphabetizes command line flags (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Another Patch Set Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/flags.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/flags/SkCommandLineFlags.cpp
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index c25fec5343cb04f2b3744c248b163a314090b80e..dc99fec8cd17175e3891c7c5b23d62f67b9caf16 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -7,6 +7,7 @@
#include "SkCommandLineFlags.h"
#include "SkTDArray.h"
+#include "SkTSort.h"
DEFINE_bool(undefok, false, "Silently ignore unknown flags instead of crashing.");
@@ -191,6 +192,14 @@ static void print_help_for_flag(const SkFlagInfo* flag) {
SkDebugf("\n");
}
+namespace {
+struct CompareFlagsByName {
+ bool operator()(SkFlagInfo* a, SkFlagInfo* b) const {
+ return strcmp(a->name().c_str(), b->name().c_str()) < 0;
+ }
+};
+} // namespace
+
void SkCommandLineFlags::Parse(int argc, char** argv) {
// Only allow calling this function once.
static bool gOnce;
@@ -218,24 +227,31 @@ void SkCommandLineFlags::Parse(int argc, char** argv) {
SkDebugf("%s\n%s\n", argv[0], gUsage.c_str());
}
SkDebugf("Flags:\n");
- SkFlagInfo* flag = SkCommandLineFlags::gHead;
- while (flag != NULL) {
+
+ if (0 == helpFlags.count()) {
// If no flags followed --help, print them all
- bool printFlag = 0 == helpFlags.count();
- if (!printFlag) {
+ SkTDArray<SkFlagInfo*> allFlags;
+ for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag;
+ flag = flag->next()) {
+ allFlags.push(flag);
+ }
+ SkTQSort(&allFlags[0], &allFlags[allFlags.count() - 1],
+ CompareFlagsByName());
+ for (int i = 0; i < allFlags.count(); ++i) {
+ print_help_for_flag(allFlags[i]);
+ }
+ } else {
+ for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag;
+ flag = flag->next()) {
for (int k = 0; k < helpFlags.count(); k++) {
if (flag->name().equals(helpFlags[k]) ||
flag->shortName().equals(helpFlags[k])) {
- printFlag = true;
+ print_help_for_flag(flag);
helpFlags.remove(k);
break;
}
}
}
- if (printFlag) {
- print_help_for_flag(flag);
- }
- flag = flag->next();
}
if (helpFlags.count() > 0) {
SkDebugf("Requested help for unrecognized flags:\n");
« no previous file with comments | « gyp/flags.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698