[sheepdog] [PATCH v4 1/3] sheep: add detail help message to sheep options
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Fri Jul 12 08:15:01 CEST 2013
At Thu, 11 Jul 2013 14:05:47 +0800,
Liu Yuan wrote:
>
> This will allow up to date usage about specific options shipped with binary
>
> Usage:
> yliu at ubuntu-precise:~/sheepdog$ sheep/sheep -w
> sheep/sheep: option requires an argument -- 'w'
> Available arguments:
> size=: size of the cache in megabyes
> dir=: path to the location of the cache(default: $STORE/cache)
> directio: use directio mode for cache IO, if not specified use buffered IO
>
> Example:
> $ sheep -w size=200000,dir=/my_ssd,directio ...
> This tries to use /my_ssd as the cache storage with 200G allocted to the cache in directio mode
>
>
> Signed-off-by: Liu Yuan <namei.unix at gmail.com>
> ---
> include/option.h | 2 +
> lib/option.c | 11 ++++++
> sheep/sheep.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++-------
> 3 files changed, 112 insertions(+), 13 deletions(-)
>
> diff --git a/include/option.h b/include/option.h
> index 14c1093..51867fd 100644
> --- a/include/option.h
> +++ b/include/option.h
> @@ -19,10 +19,12 @@ struct sd_option {
> const char *name;
> bool has_arg;
> const char *desc;
> + const char *help;
> };
>
> char *build_short_options(const struct sd_option *opts);
> struct option *build_long_options(const struct sd_option *opts);
> +const char *option_get_help(const struct sd_option *, int);
>
> #define sd_for_each_option(opt, opts) \
> for (opt = (opts); opt->name; opt++)
> diff --git a/lib/option.c b/lib/option.c
> index 461d661..c4b2557 100644
> --- a/lib/option.c
> +++ b/lib/option.c
> @@ -46,3 +46,14 @@ struct option *build_long_options(const struct sd_option *sd_opts)
>
> return lopts;
> }
> +
> +const char *option_get_help(const struct sd_option *sd_opts, int ch)
> +{
> + const struct sd_option *opt;
> +
> + sd_for_each_option(opt, sd_opts) {
> + if (opt->ch == ch)
> + return opt->help;
> + }
> + return NULL;
> +}
> diff --git a/sheep/sheep.c b/sheep/sheep.c
> index 441aa9a..150cce8 100644
> --- a/sheep/sheep.c
> +++ b/sheep/sheep.c
> @@ -24,37 +24,120 @@
> LIST_HEAD(cluster_drivers);
> static const char program_name[] = "sheep";
>
> +static const char bind_help[] =
> +"Example:\n\t$ sheep -b 192.168.1.1 ...\n"
> +"This tries to teach sheep listen to NIC of 192.168.1.1.\n"
> +"\nExample:\n\t$ sheep -b 0.0.0.0 ...\n"
> +"This tries to teach sheep listen to all the NICs available. It can be useful"
> +" when you want sheep to response collie without specified address and port.\n";
> +
> +static const char ioaddr_help[] =
> +"Example:\n\t$ sheep -i host=192.168.1.1,port=7002 ...\n"
> +"This tries to add a dedicated IO NIC of 192.168.1.1:7002 to transfer data."
> +" If IO NIC is down, sheep will fallback to non IO NIC to transfer data.\n";
> +
> +static const char journal_help[] =
> +"Available arguments:\n"
> +"\tsize=: size of the journal in megabyes\n"
> +"\tdir=: path to the location of the journal (default: $STORE)\n"
> +"\tskip: if specified, skip the recovery at startup\n"
> +"\nExample:\n\t$ sheep -j dir=/journal,size=1024\n"
> +"This tries to use /journal as the journal storage of the size 1024M\n";
> +
> +static const char loglevel_help[] =
> +"Available log levels:\n"
> +" # Level Description\n"
> +" 0 SDOG_EMERG system has failed and is unusable\n"
> +" 1 SDOG_ALERT action must be taken immediately\n"
> +" 2 SDOG_CRIT critical conditions\n"
> +" 3 SDOG_ERR error conditions\n"
> +" 4 SDOG_WARNING warning conditions\n"
> +" 5 SDOG_NOTICE normal but significant conditions\n"
> +" 6 SDOG_INFO informational notices\n"
> +" 7 SDOG_DEBUG debugging messages\n"
> +"\nExample:\n\t$ sheep -l 4 ...\n"
> +"This only allows logs with level smaller than SDOG_WARNING to be logged\n";
> +
> +static const char http_help[] =
> +"Example:\n\t$ sheep -r localhost:7001 ...\n"
> +"This tries to enable sheep as http service backend and use localhost:7001 to "
> +"communicate with http server. Not fully implemented yet.\n";
> +
> +static const char myaddr_help[] =
> +"Example:\n\t$ sheep -y 192.168.1.1:7000 ...\n"
> +"This tries to tell other nodes through what address they can talk to this "
> +"sheep.\n";
> +
> +static const char zone_help[] =
> +"Example:\n\t$ sheep -z 1 ...\n"
> +"This tries to set the zone ID of this sheep to 1 and sheepdog won't store "
> +"more than one copy of any object into this same zone\n";
> +
> +static const char cluster_help[] =
> +"Available arguments:\n"
> +"\tlocal: use local driver\n"
> +"\tcorosync: use corosync driver (default)\n"
> +"\tzookeeper: use zookeeper driver, need extra arguments\n"
> +"\n\tzookeeper arguments: address-list,tiemout=value (default as 3000)"
> +"\nExample:\n\t"
> +"$ sheep -c zookeeperr:IP1:PORT1,IP2:PORT2,IP3:PORT3,timeout=1000 ...\n"
> +"This tries to use 3 node zookeeper cluster, which can be reached by IP1:PORT1,"
> +" IP2:PORT2, IP3:PORT3 to manage membership and broadcast message and set the"
> +" timeout of node heartbeat as 1000 milliseconds\n";
> +
> +static const char cache_help[] =
> +"Available arguments:\n"
> +"\tsize=: size of the cache in megabyes\n"
> +"\tdir=: path to the location of the cache (default: $STORE/cache)\n"
> +"\tdirectio: use directio mode for cache IO, "
> +"if not specified use buffered IO\n"
> +"\nExample:\n\t$ sheep -w size=200000,dir=/my_ssd,directio ...\n"
> +"This tries to use /my_ssd as the cache storage with 200G "
> +"allocted to the cache in directio mode\n";
How about adding '\n' for long lines? I think the number of
characters per line should be less than 80.
> @@ -65,8 +148,11 @@ static void usage(int status)
> printf(" -%c, --%-18s%s\n", opt->ch, opt->name,
> opt->desc);
> }
> - }
>
> + printf("\nTry '%s option', for e.g, '%s -w', to get more detail"
> + " about specific option\n", program_name, program_name);
s/%s option/%s <option>/
Because "option" needs to be replaced with the specific option name.
s/for e.g,/e.g.,/
"e.g." itself means "for example", so "for e.g" looks strange.
Thanks,
Kazutaka
More information about the sheepdog
mailing list