[sheepdog] [PATCH] collie: correct command-line options parser

輕微 cz at de3eb.cn
Fri Mar 15 08:17:34 CET 2013


the option "-p, --port" was list in the usage, so i think i can specify a different daemon port except 7000.


so, i think "expected behavior" should be:


[root at de3eb sheepdog]# ./collie/collie cluster recover disable -p7001
Cluster recovery: disable


-p option work just like:


[root at de3eb sheepdog]# ./collie/collie node list -p7001
M   Id   Host:Port         V-Nodes       Zone
-    0   127.0.0.1:7001         64          3
-    1   127.0.0.1:7002         64          1
-    2   127.0.0.1:7004         64          4




isn't it?


Thanks,
ChenZhe
 
------------------ Original ------------------
From:  "Liu Yuan"<namei.unix at gmail.com>;
Date:  Fri, Mar 15, 2013 02:28 PM
To:  "ChenZhe"<cz at de3eb.cn>; 
Cc:  "sheepdog"<sheepdog at lists.wpkg.org>; "ChenZhe"<chenzhe at xinnet.com>; 
Subject:  Re: [sheepdog] [PATCH] collie: correct command-line options parser

 
On 03/15/2013 02:00 PM, ChenZhe wrote:
> From: ChenZhe <chenzhe at xinnet.com>
> 
> "collie cluster recover disable -p7001" not work.
> getopt_long() will reorder the options in argv.
> so, we need to skip one more argument before getopt() for the subcmd who need third arg.
> 
> Signed-off-by: ChenZhe <chenzhe at xinnet.com>
> Signed-off-by: ChenZhe <cz at de3eb.cn>
> ---
>  collie/collie.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/collie/collie.c b/collie/collie.c
> index 08c78eb..2d05f3d 100644
> --- a/collie/collie.c
> +++ b/collie/collie.c
> @@ -348,6 +348,9 @@ int main(int argc, char **argv)
>  	long_options = build_long_options(sd_opts);
>  	short_options = build_short_options(sd_opts);
>  
> +	if(flags & SUBCMD_FLAG_NEED_THIRD_ARG && argc > 3)
> +		optind++;
> +
>  	while ((ch = getopt_long(argc, argv, short_options, long_options,
>  				&longindex)) >= 0) {
>  
> @@ -391,7 +394,7 @@ int main(int argc, char **argv)
>  		}
>  	}
>  
> -	if (flags & SUBCMD_FLAG_NEED_THIRD_ARG && argc == optind)
> +	if (flags & SUBCMD_FLAG_NEED_THIRD_ARG && optind <= 3)
>  		subcommand_usage(argv[1], argv[2], EXIT_USAGE);
>  
>  	return command_fn(argc, argv);
> 

yliu at K55VM-ubuntu:~/sheepdog$ collie/collie cluster recover disable -p7001
Usage: collie cluster recover {force|enable|disable} [-a address] [-f] [-p port] [-h]
Available subcommands:
  force                   force recover cluster immediately
  enable                  enable automatic recovery and run once recover if necessary
  disable                 disable automatic recovery
Options:
  -a, --address           specify the daemon address (default: localhost)
  -f, --force             do not prompt for confirmation
  -p, --port              specify the daemon port
  -h, --help              display this help and exit

So '-p7001' will catch the wrong option and report the usage, isn't this expected behavior?

Thanks,
Yuan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/sheepdog/attachments/20130315/0a21acb8/attachment-0003.html>


More information about the sheepdog mailing list