Fix bug where alias command options were being duplicated as command arguments as well.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@116316 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectCommands.cpp b/source/Commands/CommandObjectCommands.cpp
index 514d6a4..88f3aeb 100644
--- a/source/Commands/CommandObjectCommands.cpp
+++ b/source/Commands/CommandObjectCommands.cpp
@@ -346,8 +346,9 @@
argc = args.GetArgumentCount();
for (size_t i = 0; i < argc; ++i)
- option_arg_vector->push_back (OptionArgPair ("<argument>",
- std::string (args.GetArgumentAtIndex (i))));
+ if (strcmp (args.GetArgumentAtIndex (i), "") != 0)
+ option_arg_vector->push_back (OptionArgPair ("<argument>",
+ std::string (args.GetArgumentAtIndex (i))));
}
// Create the alias.
diff --git a/source/Interpreter/Args.cpp b/source/Interpreter/Args.cpp
index 62a4e1c..c04c4aa 100644
--- a/source/Interpreter/Args.cpp
+++ b/source/Interpreter/Args.cpp
@@ -802,12 +802,9 @@
}
void
-Args::ParseAliasOptions
-(
- Options &options,
- CommandReturnObject &result,
- OptionArgVector *option_arg_vector
-)
+Args::ParseAliasOptions (Options &options,
+ CommandReturnObject &result,
+ OptionArgVector *option_arg_vector)
{
StreamString sstr;
int i;
@@ -936,6 +933,31 @@
result.AppendErrorWithFormat ("Invalid option with value '%c'.\n", (char) val);
result.SetStatus (eReturnStatusFailed);
}
+
+ if (long_options_index >= 0)
+ {
+ // Find option in the argument list; also see if it was supposed to take an argument and if one was
+ // supplied. Remove option (and argument, if given) from the argument list.
+ StreamString short_opt_str;
+ StreamString long_opt_str;
+ short_opt_str.Printf ("-%c", (char) long_options[long_options_index].val);
+ long_opt_str.Printf ("-%s", long_options[long_options_index].name);
+ bool found = false;
+ size_t end = GetArgumentCount();
+ for (size_t i = 0; i < end && !found; ++i)
+ if ((strcmp (GetArgumentAtIndex (i), short_opt_str.GetData()) == 0)
+ || (strcmp (GetArgumentAtIndex (i), long_opt_str.GetData()) == 0))
+ {
+ found = true;
+ ReplaceArgumentAtIndex (i, "");
+ if ((long_options[long_options_index].has_arg != no_argument)
+ && (optarg != NULL)
+ && (i+1 < end)
+ && (strcmp (optarg, GetArgumentAtIndex(i+1)) == 0))
+ ReplaceArgumentAtIndex (i+1, "");
+ }
+ }
+
if (!result.Succeeded())
break;
}