Fail if given an unrecognised option.
I renamed UsageError to UsageMsg because it just logs, unlike
ArgumentError which exits the process with an appropriate error
code. Then replaced one case of UsageMsg with ArgumentError where we
should be failing hard.
Also inlined OptionsHelp so the usage an be seen in one place in the code.
Test: odrefresh --foo --compile
Change-Id: If01902ebe652c20949a454e64849e7d39c2b8748
diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc
index 47ac9f0..4e05bf5 100644
--- a/odrefresh/odrefresh_main.cc
+++ b/odrefresh/odrefresh_main.cc
@@ -44,7 +44,7 @@
using ::art::odrefresh::QuotePath;
using ::art::odrefresh::ZygoteKind;
-void UsageErrorV(const char* fmt, va_list ap) {
+void UsageMsgV(const char* fmt, va_list ap) {
std::string error;
android::base::StringAppendV(&error, fmt, ap);
if (isatty(fileno(stderr))) {
@@ -54,19 +54,19 @@
}
}
-void UsageError(const char* fmt, ...) {
+void UsageMsg(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
- UsageErrorV(fmt, ap);
+ UsageMsgV(fmt, ap);
va_end(ap);
}
NO_RETURN void ArgumentError(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
- UsageErrorV(fmt, ap);
+ UsageMsgV(fmt, ap);
va_end(ap);
- UsageError("Try '--help' for more information.");
+ UsageMsg("Try '--help' for more information.");
exit(EX_USAGE);
}
@@ -165,7 +165,7 @@
} else if (ArgumentEquals(arg, "--no-refresh")) {
config->SetRefresh(false);
} else {
- UsageError("Unrecognized argument: '%s'", arg);
+ ArgumentError("Unrecognized argument: '%s'", arg);
}
}
@@ -188,45 +188,41 @@
return n;
}
-void OptionsHelp() {
- UsageError("--dry-run");
- UsageError("--partial-compilation Only generate artifacts that are out-of-date or");
- UsageError(" missing.");
- UsageError("--no-refresh Do not refresh existing artifacts.");
- UsageError("--use-compilation-os=<CID> Run compilation in the VM with the given CID.");
- UsageError(" (0 = do not use VM, -1 = use composd's VM)");
- UsageError("--compilation-os-mode Indicate that odrefresh is running in Compilation");
- UsageError(" OS.");
- UsageError("--dalvik-cache=<DIR> Write artifacts to .../<DIR> rather than");
- UsageError(" .../dalvik-cache");
- UsageError("--max-execution-seconds=<N> Maximum timeout of all compilation combined");
- UsageError("--max-child-process-seconds=<N> Maximum timeout of each compilation task");
- UsageError("--staging-dir=<DIR> Write temporary artifacts to <DIR> rather than");
- UsageError(" .../staging");
- UsageError("--zygote-arch=<STRING> Zygote kind that overrides ro.zygote");
- UsageError("--system-server-compiler-filter=<STRING>");
- UsageError(" Compiler filter that overrides");
- UsageError(" dalvik.vm.systemservercompilerfilter");
-}
-
NO_RETURN void UsageHelp(const char* argv0) {
std::string name(android::base::Basename(argv0));
- UsageError("Usage: %s [OPTION...] ACTION", name.c_str());
- UsageError("On-device refresh tool for boot class path extensions and system server");
- UsageError("following an update of the ART APEX.");
- UsageError("");
- UsageError("Valid ACTION choices are:");
- UsageError("");
- UsageError("--check Check compilation artifacts are up-to-date based on metadata.");
- UsageError("--compile Compile boot class path extensions and system_server jars");
- UsageError(" when necessary.");
- UsageError("--force-compile Unconditionally compile the boot class path extensions and");
- UsageError(" system_server jars.");
- UsageError("--help Display this help information.");
- UsageError("");
- UsageError("Available OPTIONs are:");
- UsageError("");
- OptionsHelp();
+ UsageMsg("Usage: %s [OPTION...] ACTION", name.c_str());
+ UsageMsg("On-device refresh tool for boot class path extensions and system server");
+ UsageMsg("following an update of the ART APEX.");
+ UsageMsg("");
+ UsageMsg("Valid ACTION choices are:");
+ UsageMsg("");
+ UsageMsg("--check Check compilation artifacts are up-to-date based on metadata.");
+ UsageMsg("--compile Compile boot class path extensions and system_server jars");
+ UsageMsg(" when necessary.");
+ UsageMsg("--force-compile Unconditionally compile the boot class path extensions and");
+ UsageMsg(" system_server jars.");
+ UsageMsg("--help Display this help information.");
+ UsageMsg("");
+ UsageMsg("Available OPTIONs are:");
+ UsageMsg("");
+ UsageMsg("--dry-run");
+ UsageMsg("--partial-compilation Only generate artifacts that are out-of-date or");
+ UsageMsg(" missing.");
+ UsageMsg("--no-refresh Do not refresh existing artifacts.");
+ UsageMsg("--use-compilation-os=<CID> Run compilation in the VM with the given CID.");
+ UsageMsg(" (0 = do not use VM, -1 = use composd's VM)");
+ UsageMsg("--compilation-os-mode Indicate that odrefresh is running in Compilation");
+ UsageMsg(" OS.");
+ UsageMsg("--dalvik-cache=<DIR> Write artifacts to .../<DIR> rather than");
+ UsageMsg(" .../dalvik-cache");
+ UsageMsg("--max-execution-seconds=<N> Maximum timeout of all compilation combined");
+ UsageMsg("--max-child-process-seconds=<N> Maximum timeout of each compilation task");
+ UsageMsg("--staging-dir=<DIR> Write temporary artifacts to <DIR> rather than");
+ UsageMsg(" .../staging");
+ UsageMsg("--zygote-arch=<STRING> Zygote kind that overrides ro.zygote");
+ UsageMsg("--system-server-compiler-filter=<STRING>");
+ UsageMsg(" Compiler filter that overrides");
+ UsageMsg(" dalvik.vm.systemservercompilerfilter");
exit(EX_USAGE);
}
@@ -247,8 +243,7 @@
argv += n;
argc -= n;
if (argc != 1) {
- UsageError("Expected 1 argument, but have %d.", argc);
- exit(EX_USAGE);
+ ArgumentError("Expected 1 argument, but have %d.", argc);
}
OdrMetrics metrics(config.GetArtifactDirectory());
@@ -289,7 +284,6 @@
} else if (action == "--help") {
UsageHelp(argv[0]);
} else {
- UsageError("Unknown argument: ", action);
- exit(EX_USAGE);
+ ArgumentError("Unknown argument: ", action);
}
}