aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/app/src/com
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2010-05-19 07:37:12 +0200
committerRaphael Moll <ralf@android.com>2010-05-19 07:49:03 +0200
commit1e8a0225f544baa63098badd68a25e69dfd966bc (patch)
tree083440ad751b1832fe3cc9dffe277ebaa5325b7e /sdkmanager/app/src/com
parentfc58ae598819fac0fce2f47816dd2a92a4d5b4e0 (diff)
downloadsdk-1e8a0225f544baa63098badd68a25e69dfd966bc.zip
sdk-1e8a0225f544baa63098badd68a25e69dfd966bc.tar.gz
sdk-1e8a0225f544baa63098badd68a25e69dfd966bc.tar.bz2
Fix error detection for invalid command line arguments.
This fixes 2 edge cases: - when an unknown extra parameter is given (it was simply ignored before) e.g.: "android update sdk foo" => foo is extra. - when a 1-argument parameter is used and no argument is actually given but instead the next dash-parameter is found. e.g.: "android update sdk --filter (missing value) --somearg" Change-Id: Idc34f61728411aceaf1cf33f070ac275b3798019
Diffstat (limited to 'sdkmanager/app/src/com')
-rw-r--r--sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
index 6536baa..7edee3a 100644
--- a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
+++ b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
@@ -257,7 +257,7 @@ class CommandLineProcessor {
a);
return;
} else {
- // It looks like a dashed parameter and but it is unknown by this
+ // It looks like a dashed parameter but it is unknown by this
// verb-object combination
errorMsg = String.format(
@@ -309,6 +309,12 @@ class CommandLineProcessor {
return;
}
+ } else {
+ // The argument is not a dashed parameter and we already
+ // have a verb/object. Must be some extra unknown argument.
+ errorMsg = String.format(
+ "Argument '%1$s' is not recognized.",
+ a);
}
} else if (arg != null) {
// This argument was present on the command line
@@ -321,8 +327,22 @@ class CommandLineProcessor {
errorMsg = String.format("Missing argument for flag %1$s.", a);
return;
}
+ String b = args[i];
+
+ Arg dummyArg = null;
+ if (b.startsWith("--")) {
+ dummyArg = findLongArg(verb, directObject, b.substring(2));
+ } else if (b.startsWith("-")) {
+ dummyArg = findShortArg(verb, directObject, b.substring(1));
+ }
+ if (dummyArg != null) {
+ errorMsg = String.format(
+ "Oops, it looks like you didn't provide an argument for '%1$s'.\n'%2$s' was found instead.",
+ a, b);
+ return;
+ }
- error = arg.getMode().process(arg, args[i]);
+ error = arg.getMode().process(arg, b);
} else {
error = arg.getMode().process(arg, null);