Client: add placeholders for arguments in help screens

This commit is contained in:
Benjamin Canou 2018-01-27 18:32:40 +01:00 committed by Benjamin Canou
parent 3955b6a61d
commit 02bc0533fa
6 changed files with 42 additions and 16 deletions

View File

@ -145,12 +145,14 @@ let protocol_parameter =
let base_dir_arg =
arg
~parameter:"-base-dir"
~placeholder:"path"
~doc:("The directory where the Tezos client will store all its data. By default "
^ Client_commands.default_base_dir)
string_parameter
let config_file_arg =
arg
~parameter:"-config-file"
~placeholder:"path"
~doc:"The main configuration file."
string_parameter
let timings_switch =
@ -160,12 +162,14 @@ let timings_switch =
let block_arg =
default_arg
~parameter:"-block"
~placeholder:"hash|head|head~n"
~doc:"The block on which to apply contextual commands."
~default:(Block_services.to_string default_cli_args.block)
block_parameter
let protocol_arg =
arg
~parameter:"-protocol"
~placeholder:"hash"
~doc:"Use contextual commands of a specific protocol."
protocol_parameter
let log_requests_switch =
@ -177,11 +181,13 @@ let log_requests_switch =
let addr_arg =
arg
~parameter:"-addr"
~placeholder:"IP addr|host"
~doc:"The IP address of the node."
string_parameter
let port_arg =
arg
~parameter:"-port"
~placeholder:"number"
~doc:"The RPC port of the node."
(parameter
(fun _ x -> try
@ -248,7 +254,8 @@ let commands config_file cfg =
command ~group ~desc:"create a config file based on the current CLI values"
(args1
(default_arg
~parameter:"-path"
~parameter:"-file"
~placeholder:"path"
~doc:"path at which to create the file"
~default:(cfg.base_dir // default_config_file_name)
(parameter (fun _ctx str -> return str))))

View File

@ -108,6 +108,7 @@ let commands () =
arg
~doc:"Write output of debug command to file"
~parameter:"-file"
~placeholder:"path"
@@ parameter (fun _ str -> return str) in
let output_to_ppf = function
| None -> Format.std_formatter

View File

@ -27,23 +27,27 @@ let parameter ?autocomplete converter =
type ('a, 'ctx) arg =
| Arg : { doc : string ;
parameter : string ;
placeholder : string ;
kind : ('p, 'ctx) parameter } ->
('p option, 'ctx) arg
| DefArg : { doc : string ;
parameter : string ;
placeholder : string ;
kind : ('p, 'ctx) parameter ;
default : string } -> ('p, 'ctx) arg
| Switch : { doc : string ;
parameter : string } ->
(bool, 'ctx) arg
let arg ~doc ~parameter kind =
let arg ~doc ~parameter ~placeholder kind =
Arg { doc ;
parameter ;
placeholder ;
kind }
let default_arg ~doc ~parameter ~default kind =
let default_arg ~doc ~parameter ~placeholder ~default kind =
DefArg { doc ;
placeholder ;
parameter ;
kind ;
default }
@ -331,6 +335,7 @@ let rec help_commands commands =
~parameter:"-verbose")
(default_arg
~doc:"Select the manual's output format"
~placeholder: "plain|colors"
~parameter: "-format"
~default: (if Unix.isatty Unix.stdout then "colors" else "plain")
(parameter
@ -525,12 +530,12 @@ let trim s = (* config-file wokaround *)
let print_options_detailed (type ctx) =
let help_option : type a.Format.formatter -> (a, ctx) arg -> unit =
fun ppf -> function
| Arg { parameter ; doc } ->
Format.fprintf ppf "@[<v 2>@{<opt>%s _@}:@,@[<hov 0>%a@]@]"
parameter Format.pp_print_text doc
| DefArg { parameter ; doc ; default } ->
Format.fprintf ppf "@[<v 2>@{<opt>%s _@} (default %s):@,@[<hov 0>%a@]@]"
parameter default Format.pp_print_text doc
| Arg { parameter ; placeholder ; doc } ->
Format.fprintf ppf "@[<v 2>@{<opt>%s <%s>@}:@,@[<hov 0>%a@]@]"
parameter placeholder Format.pp_print_text doc
| DefArg { parameter ; placeholder ; doc ; default } ->
Format.fprintf ppf "@[<v 2>@{<opt>%s <%s>@} (default %s):@,@[<hov 0>%a@]@]"
parameter placeholder default Format.pp_print_text doc
| Switch { parameter ; doc } ->
Format.fprintf ppf "@[<v 2>@{<opt>%s@}:@,@[<hov 0>%a@]@]"
parameter Format.pp_print_text doc
@ -553,10 +558,10 @@ let print_options_brief (type ctx) =
let help_option :
type a. Format.formatter -> (a, ctx) arg -> unit =
fun ppf -> function
| DefArg { parameter } ->
Format.fprintf ppf "[@{<opt>%s _@}]" parameter
| Arg { parameter } ->
Format.fprintf ppf "[@{<opt>%s _@}]" parameter
| DefArg { parameter ; placeholder } ->
Format.fprintf ppf "[@{<opt>%s <%s>@}]" parameter placeholder
| Arg { parameter ; placeholder } ->
Format.fprintf ppf "[@{<opt>%s <%s>@}]" parameter placeholder
| Switch { parameter } ->
Format.fprintf ppf "[@{<opt>%s@}]" parameter
in let rec help : type b. Format.formatter -> (b, ctx) args -> unit =

View File

@ -28,13 +28,19 @@ type ('a, 'ctx) arg
(** [arg ~doc ~parameter converter] creates an argument to a command.
The [~parameter] argument should begin with a [-].
If the argument is not provided, [None] is returned *)
val arg : doc:string -> parameter:string ->
val arg :
doc:string ->
parameter:string ->
placeholder:string ->
('p, 'ctx) parameter ->
('p option, 'ctx) arg
(** Create an argument that will contain the [~default] value if it is not provided.
see arg *)
val default_arg : doc:string -> parameter:string ->
val default_arg :
doc:string ->
parameter:string ->
placeholder:string ->
default:string ->
('p, 'ctx) parameter ->
('p, 'ctx) arg

View File

@ -61,6 +61,7 @@ let string_parameter =
let init_arg =
default_arg
~parameter:"-init"
~placeholder:"data"
~doc:"The initial value of the contract's storage."
~default:"Unit"
string_parameter
@ -68,6 +69,7 @@ let init_arg =
let arg_arg =
default_arg
~parameter:"-arg"
~placeholder:"data"
~doc:"The argument passed to the contract's script, if needed."
~default:"Unit"
string_parameter
@ -75,6 +77,7 @@ let arg_arg =
let delegate_arg =
arg
~parameter:"-delegate"
~placeholder:"identity"
~doc:"Set the delegate of the contract.\
Must be a known identity."
string_parameter
@ -82,6 +85,7 @@ let delegate_arg =
let source_arg =
arg
~parameter:"-source"
~placeholder:"identity"
~doc:"Set the source of the bonds to be paid.\
Must be a known identity."
string_parameter
@ -113,7 +117,7 @@ let tez_parameter param =
| None -> fail (Bad_tez_arg (param, s)))
let tez_arg ~default ~parameter ~doc =
default_arg ~parameter ~doc ~default (tez_parameter parameter)
default_arg ~parameter ~placeholder:"amount" ~doc ~default (tez_parameter parameter)
let tez_param ~name ~desc next =
Cli_entries.param
@ -131,6 +135,7 @@ let fee_arg =
let max_priority_arg =
arg
~parameter:"-max-priority"
~placeholder:"prio"
~doc:"Set the max_priority used when looking for baking slot."
(parameter (fun _ s ->
try return (int_of_string s)
@ -144,6 +149,7 @@ let free_baking_switch =
let endorsement_delay_arg =
default_arg
~parameter:"-endorsement-delay"
~placeholder:"seconds"
~doc:"Set the delay used before to endorse the current block."
~default:"15"
(parameter (fun _ s ->

View File

@ -50,6 +50,7 @@ let commands () =
args1
(arg
~parameter:"-timestamp"
~placeholder:"date"
~doc:"Set the timestamp of the block (and initial time of the chain)"
(parameter (fun _ t ->
match (Time.of_notation t) with