Fix double dash handling

Several functions examine argv in order to set options. Only the last
argument parsing pass should remove the '--' from the argument vector.
If it is removed earlier than that, entries may be parsed as options,
when that was not the user's intent.

This changes fixes the common argument parsing loops so that they do not
remove the double dash. It also rearranges some programs so that the
user's argument parsing loop comes last, rather than coming before the
common argument parsing loops.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
This commit is contained in:
Colin Patrick McCabe 2011-09-14 09:53:47 -07:00
parent ffe844aeb6
commit 95a3845bd8
5 changed files with 21 additions and 12 deletions

View File

@ -344,7 +344,10 @@ CephInitParameters ceph_argparse_early_args
CephInitParameters iparams(module_type);
std::string val;
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
if (ceph_argparse_double_dash(args, i)) {
if (strcmp(*i, "--") == 0) {
/* Normally we would use ceph_argparse_double_dash. However, in this
* function we *don't* want to remove the double dash, because later
* argument parses will still need to see it. */
break;
}
else if (ceph_argparse_flag(args, i, "--version", "-v", (char*)NULL)) {

View File

@ -609,7 +609,10 @@ parse_argv(std::vector<const char*>& args)
// observer notifications later.
std::string val;
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
if (ceph_argparse_double_dash(args, i)) {
if (strcmp(*i, "--") == 0) {
/* Normally we would use ceph_argparse_double_dash. However, in this
* function we *don't* want to remove the double dash, because later
* argument parses will still need to see it. */
break;
}
else if (ceph_argparse_flag(args, i, "--show_conf", (char*)NULL)) {

View File

@ -42,9 +42,15 @@ int main(int argc, const char **argv)
bool opt_version = false;
bool opt_vernum = false;
global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
common_init_finish(g_ceph_context);
for (std::vector<const char*>::iterator i = args.begin();
i != args.end(); ) {
if (strcmp(*i, "--version") == 0) {
if (strcmp(*i, "--") == 0) {
break;
}
else if (strcmp(*i, "--version") == 0) {
opt_version = true;
i = args.erase(i);
}
@ -56,9 +62,6 @@ int main(int argc, const char **argv)
++i;
}
global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
common_init_finish(g_ceph_context);
if (!opt_version && !opt_vernum)
usage_exit();

View File

@ -117,14 +117,14 @@ int main(int argc, const char **argv)
argv_to_vec(argc, argv, args);
env_to_vec(args);
// parse user input
bool concise = false;
parse_cmd_args(args, &in_file, &out_file, &mode, &concise);
// initialize globals
global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
common_init_finish(g_ceph_context);
// parse user input
bool concise = false;
parse_cmd_args(args, &in_file, &out_file, &mode, &concise);
// input
bufferlist indata;
if (!in_file.empty()) {

View File

@ -79,10 +79,9 @@ int main(int argc, const char **argv)
argv_to_vec(argc, argv, args);
env_to_vec(args);
parse_gceph_args(args);
global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
common_init_finish(g_ceph_context);
vec_to_argv(args, argc, argv);
parse_gceph_args(args);
ctx = ceph_tool_common_init(CEPH_TOOL_MODE_GUI, false);
if (!ctx) {
@ -92,6 +91,7 @@ int main(int argc, const char **argv)
atexit(ceph_tool_common_shutdown_wrapper);
vec_to_argv(args, argc, argv);
if (cephtool_run_gui(ctx, argc, argv))
ret = 1;