Client: add command "complete".
This commit is contained in:
parent
3f864ae113
commit
69261aa542
@ -345,6 +345,7 @@ CLIENT_LIB_INTFS := \
|
||||
client/client_version.mli \
|
||||
client/client_node_rpcs.mli \
|
||||
client/client_generic_rpcs.mli \
|
||||
client/client_helpers.mli \
|
||||
client/client_aliases.mli \
|
||||
client/client_keys.mli \
|
||||
client/client_protocols.mli \
|
||||
@ -354,6 +355,7 @@ CLIENT_LIB_IMPLS := \
|
||||
client/client_config.ml \
|
||||
client/client_node_rpcs.ml \
|
||||
client/client_generic_rpcs.ml \
|
||||
client/client_helpers.ml \
|
||||
client/client_aliases.ml \
|
||||
client/client_keys.ml \
|
||||
client/client_protocols.ml \
|
||||
|
35
src/client/client_helpers.ml
Normal file
35
src/client/client_helpers.ml
Normal file
@ -0,0 +1,35 @@
|
||||
(**************************************************************************)
|
||||
(* *)
|
||||
(* Copyright (c) 2014 - 2016. *)
|
||||
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||
(* *)
|
||||
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||
(* *)
|
||||
(**************************************************************************)
|
||||
|
||||
let () =
|
||||
let open Cli_entries in
|
||||
register_group "helpers" "Various helpers"
|
||||
|
||||
let unique = ref false
|
||||
let unique_arg =
|
||||
"-unique",
|
||||
Arg.Set unique,
|
||||
"Fail when there is more than one possible completion."
|
||||
|
||||
let commands () = Cli_entries.[
|
||||
command
|
||||
~desc: "Lookup for the possible completion of a \
|
||||
given prefix of Base48Check-encoded hash. This actually \
|
||||
works only for blocks and operations."
|
||||
~args: [unique_arg]
|
||||
(prefixes [ "complete" ] @@ string "prefix" "the prefix of the Base48Check-encoded hash to be completed" @@ stop)
|
||||
(fun prefix () ->
|
||||
Client_node_rpcs.complete prefix >>= fun completions ->
|
||||
match completions with
|
||||
| [] -> Pervasives.exit 3
|
||||
| _ :: _ :: _ when !unique -> Pervasives.exit 3
|
||||
| completions ->
|
||||
List.iter print_endline completions ;
|
||||
Lwt.return_unit)
|
||||
]
|
10
src/client/client_helpers.mli
Normal file
10
src/client/client_helpers.mli
Normal file
@ -0,0 +1,10 @@
|
||||
(**************************************************************************)
|
||||
(* *)
|
||||
(* Copyright (c) 2014 - 2016. *)
|
||||
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||
(* *)
|
||||
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||
(* *)
|
||||
(**************************************************************************)
|
||||
|
||||
val commands: unit -> Cli_entries.command list
|
@ -150,6 +150,8 @@ let inject_operation ?(wait = true) ?force operation =
|
||||
call_service0 Services.inject_operation (operation, wait, force)
|
||||
let inject_protocol ?(wait = true) ?force protocol =
|
||||
call_service0 Services.inject_protocol (protocol, wait, force)
|
||||
let complete prefix =
|
||||
call_service1 Services.complete prefix ()
|
||||
let describe ?recurse path =
|
||||
let prefix, arg = RPC.forge_request Services.describe () recurse in
|
||||
get_json (prefix @ path) arg >>=
|
||||
|
@ -104,6 +104,8 @@ module Protocols : sig
|
||||
(Protocol_hash.t * Store.protocol option) list Lwt.t
|
||||
end
|
||||
|
||||
val complete: string -> string list Lwt.t
|
||||
|
||||
val describe: ?recurse:bool -> string list -> RPC.Description.directory_descr Lwt.t
|
||||
|
||||
(** Low-level *)
|
||||
|
@ -31,6 +31,7 @@ let main () =
|
||||
Client_generic_rpcs.commands @
|
||||
Client_keys.commands () @
|
||||
Client_protocols.commands () @
|
||||
Client_helpers.commands () @
|
||||
Client_version.commands_for_version version in
|
||||
Client_config.parse_args ~version
|
||||
(Cli_entries.usage commands)
|
||||
|
@ -434,6 +434,11 @@ let build_rpc_directory node =
|
||||
let implementation () =
|
||||
RPC.Answer.return Data_encoding.Json.(schema (Error_monad.error_encoding ())) in
|
||||
RPC.register0 dir RPC.Error.service implementation in
|
||||
let dir =
|
||||
RPC.register1 dir Services.complete
|
||||
(fun s () ->
|
||||
Base48.decode_partial s >>= fun l ->
|
||||
RPC.Answer.return (List.map Base48.encode l)) in
|
||||
let dir =
|
||||
RPC.register_describe_directory_service dir Services.describe in
|
||||
dir
|
||||
|
@ -583,6 +583,19 @@ let inject_protocol =
|
||||
(obj1 (req "injectedProtocol" Protocol_hash.encoding)))
|
||||
RPC.Path.(root / "inject_protocol")
|
||||
|
||||
let complete =
|
||||
let prefix_arg =
|
||||
let destruct s = Ok s
|
||||
and construct s = s in
|
||||
RPC.Arg.make ~name:"prefix" ~destruct ~construct () in
|
||||
RPC.service
|
||||
~description: "Try to complete a prefix of a Base48Check-encoded data. \
|
||||
This RPC is actually able to complete hashes of \
|
||||
black and hashes of operations."
|
||||
~input: empty
|
||||
~output: (list string)
|
||||
RPC.Path.(root / "complete" /: prefix_arg )
|
||||
|
||||
let describe =
|
||||
RPC.Description.service
|
||||
~description: "RPCs documentation and input/output schema"
|
||||
|
@ -132,5 +132,7 @@ val inject_protocol:
|
||||
(unit, unit,
|
||||
(Store.protocol * bool * bool option), Protocol_hash.t tzresult) RPC.service
|
||||
|
||||
val complete: (unit, unit * string, unit, string list) RPC.service
|
||||
|
||||
val describe:
|
||||
(unit, unit, bool option, RPC.Description.directory_descr) RPC.service
|
||||
|
Loading…
Reference in New Issue
Block a user