[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH v3 2/2] mllib: Getopt: support hidden options



On Wed, Jul 13, 2016 at 04:23:52PM +0200, Pino Toscano wrote:
> Add a dummy description value to mark an option as "hidden", so it will
> not be shown in the help text.
> 
> Mark few options as hidden:
> - common: --short-options, --long-options
> - virt-sysprep: --dump-pod, --dump-pod-options
> ---
> 
> Related question: should --debug-gc be considered really internal,
> thus marked as such and removed from the documentations?

Yes.

There are also a few deprecated options around, although I can't
recall now if they are in the any of the OCaml tools.

Rich.

> 
>  mllib/getopt.ml  | 13 ++++++++++---
>  mllib/getopt.mli |  4 ++++
>  sysprep/main.ml  |  4 ++--
>  3 files changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/mllib/getopt.ml b/mllib/getopt.ml
> index 90f4c44..550baa4 100644
> --- a/mllib/getopt.ml
> +++ b/mllib/getopt.ml
> @@ -43,6 +43,8 @@ type t = {
>    usage_msg : usage_msg;
>  }
>  
> +let hidden_option_description = ""
> +
>  external getopt_parse : string array -> (c_keys * spec * doc) array -> ?anon_fun:anon_fun -> usage_msg -> unit = "guestfs_int_mllib_getopt_parse"
>  
>  let column_wrap = 38
> @@ -56,6 +58,11 @@ let show_help h () =
>    let prologue = sprintf (f_"%s\nOptions:\n") h.usage_msg in
>    Buffer.add_string b prologue;
>  
> +  let specs = List.filter (
> +    fun (_, _, doc) ->
> +      doc <> hidden_option_description
> +  ) h.specs in
> +
>    List.iter (
>      fun (keys, spec, doc) ->
>        let columns = ref 0 in
> @@ -88,7 +95,7 @@ let show_help h () =
>        );
>        Buffer.add_string b doc;
>        Buffer.add_char b '\n';
> -  ) h.specs;
> +  ) specs;
>  
>    Buffer.output_buffer stdout b;
>    exit 0
> @@ -158,8 +165,8 @@ let create specs ?anon_fun usage_msg =
>      } in
>  
>    let specs = specs @ [
> -    [ "--short-options" ], Unit (display_short_options t), s_"List short options (internal)";
> -    [ "--long-options" ], Unit (display_long_options t), s_"List long options (internal)";
> +    [ "--short-options" ], Unit (display_short_options t), hidden_option_description;
> +    [ "--long-options" ], Unit (display_long_options t), hidden_option_description;
>    ] in
>  
>    (* Decide whether the help option can be added, and which switches use.  *)
> diff --git a/mllib/getopt.mli b/mllib/getopt.mli
> index 9d9737e..2a8bada 100644
> --- a/mllib/getopt.mli
> +++ b/mllib/getopt.mli
> @@ -47,6 +47,8 @@ type anon_fun = (string -> unit)
>  
>  type speclist = (keys * spec * doc) list
>  
> +val hidden_option_description : string
> +
>  val compare_command_line_args : string -> string -> int
>  (** Compare command line arguments for equality, ignoring any leading [-]s. *)
>  
> @@ -60,6 +62,8 @@ val create : speclist -> ?anon_fun:anon_fun -> usage_msg -> t
>      [speclist] is a list of triples [(keys, spec, doc)]: [keys] is a
>      list of options, [spec] is the associated action, and [doc] is
>      the help text.
> +    If [doc] is [Getopt.hidden_option_description], then the option
> +    is considered internal, and it is not shown in the help text.
>  
>      [anon_fun] is an optional function to handle non-option arguments;
>      not specifying one means that only options are allowed, and
> diff --git a/sysprep/main.ml b/sysprep/main.ml
> index 3259d0d..b2df880 100644
> --- a/sysprep/main.ml
> +++ b/sysprep/main.ml
> @@ -121,8 +121,8 @@ let main () =
>        [ "-c"; "--connect" ],        Getopt.Set_string (s_"uri", libvirturi),  s_"Set libvirt URI";
>        [ "-d"; "--domain" ],        Getopt.String (s_"domain", set_domain),      s_"Set libvirt guest name";
>        [ "-n"; "--dryrun"; "--dry-run" ],        Getopt.Set dryrun,            s_"Perform a dry run";
> -      [ "--dump-pod" ], Getopt.Unit dump_pod,        s_"Dump POD (internal)";
> -      [ "--dump-pod-options" ], Getopt.Unit dump_pod_options, s_"Dump POD for options (internal)";
> +      [ "--dump-pod" ], Getopt.Unit dump_pod,        Getopt.hidden_option_description;
> +      [ "--dump-pod-options" ], Getopt.Unit dump_pod_options, Getopt.hidden_option_description;
>        [ "--enable" ],  Getopt.String (s_"operations", set_enable),      s_"Enable specific operations";
>        [ "--format" ],  Getopt.String (s_"format", set_format),      s_"Set format (default: auto)";
>        [ "--list-operations" ], Getopt.Unit list_operations, s_"List supported operations";
> -- 
> 2.7.4
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs redhat com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]