2016-10-25 21:00:03 +04:00
|
|
|
let commands () =
|
|
|
|
let open Cli_entries in
|
|
|
|
let check_dir dn =
|
|
|
|
if Sys.is_directory dn then Lwt.return dn else Lwt.fail_invalid_arg "not a directory"
|
|
|
|
in
|
|
|
|
let check_hash ph = Lwt.wrap1 Protocol_hash.of_b48check ph in
|
|
|
|
register_group "protocols" "Commands for managing protocols" ;
|
|
|
|
[
|
|
|
|
command
|
|
|
|
~group: "protocols"
|
|
|
|
~desc: "list known protocols"
|
|
|
|
(prefixes [ "list" ; "protocols" ] stop)
|
|
|
|
(fun () ->
|
2016-11-22 17:23:40 +04:00
|
|
|
Client_node_rpcs.Protocols.list ~contents:false () >>= fun protos ->
|
|
|
|
Lwt_list.iter_s (fun (ph, _p) -> message "%a" Protocol_hash.pp ph) protos
|
2016-10-25 21:00:03 +04:00
|
|
|
);
|
|
|
|
command
|
|
|
|
~group: "protocols"
|
|
|
|
~desc: "inject a new protocol to the shell database"
|
|
|
|
(prefixes [ "inject" ; "protocol" ]
|
|
|
|
@@ param ~name:"directory containing a protocol" ~desc:"" check_dir
|
|
|
|
@@ stop)
|
|
|
|
(fun dirname () ->
|
|
|
|
Lwt.catch
|
|
|
|
(fun () ->
|
|
|
|
let proto = Tezos_compiler.Protocol.of_dir dirname in
|
|
|
|
Client_node_rpcs.inject_protocol proto >>= function
|
|
|
|
| Ok hash ->
|
2016-11-22 17:23:40 +04:00
|
|
|
message "Injected protocol %a successfully" Protocol_hash.pp_short hash
|
2016-10-25 21:00:03 +04:00
|
|
|
| Error err ->
|
|
|
|
error "Error while injecting protocol from %s: %a"
|
|
|
|
dirname Error_monad.pp_print_error err)
|
|
|
|
(fun exn ->
|
|
|
|
error "Error while injecting protocol from %s: %a"
|
|
|
|
dirname Error_monad.pp_print_error [Error_monad.Exn exn])
|
|
|
|
);
|
|
|
|
command
|
|
|
|
~group: "protocols"
|
|
|
|
~desc: "dump a protocol from the shell database"
|
|
|
|
(prefixes [ "dump" ; "protocol" ]
|
|
|
|
@@ param ~name:"protocol hash" ~desc:"" check_hash
|
|
|
|
@@ stop)
|
|
|
|
(fun ph () ->
|
|
|
|
Client_node_rpcs.Protocols.bytes ph >>= fun { data } -> match data with
|
|
|
|
| Ok proto ->
|
2016-11-22 17:23:40 +04:00
|
|
|
Updater.extract "" ph proto >>= fun () ->
|
2016-10-25 21:00:03 +04:00
|
|
|
message "Extracted protocol %a" Protocol_hash.pp_short ph
|
|
|
|
| Error err ->
|
|
|
|
error "Error while dumping protocol %a: %a"
|
|
|
|
Protocol_hash.pp_short ph Error_monad.pp_print_error err);
|
|
|
|
]
|