123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2020 Nomadic Labs, <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)(** Commands *)letshow(args:Shared_arg.t)=letrun=letopenLwt_result_syntaxinlet*!()=Tezos_base_unix.Internal_event_unix.init()inifnot@@Sys.file_existsargs.config_filethenFormat.eprintf"@[<v>@[<v 9>Warning: no configuration file found at %s@,\
displaying the default configuration@]@]@."args.config_file;let*config=Shared_arg.read_and_patch_config_fileargsinprint_endline@@Config_file.to_stringconfig;return_unitinShared_arg.process_commandrunletreset(args:Shared_arg.t)=letrun=letopenLwt_result_syntaxinlet*!()=Tezos_base_unix.Internal_event_unix.init()inifSys.file_existsargs.config_filethenFormat.eprintf"Ignoring previous configuration file: %s.@."args.config_file;let*current_config=Shared_arg.read_config_fileargsin(* Here we set the network of the default config to the current network
to prevent overriding it. *)let*default_config=Shared_arg.patch_networkcurrent_config.blockchain_networkinlet*config=Shared_arg.patch_config~cfg:default_configargsinlet*()=Config_validation.checkconfiginConfig_file.writeargs.config_fileconfiginShared_arg.process_commandrunletinit(args:Shared_arg.t)=letrun=letopenLwt_result_syntaxinlet*!()=Tezos_base_unix.Internal_event_unix.init()inifSys.file_existsargs.config_filethenfailwith"Pre-existing configuration file at %s, use `reset`."args.config_fileelselet*config=Shared_arg.read_and_patch_config_file~may_override_network:trueargsinlet*()=Config_validation.checkconfiginlet*()=Config_file.writeargs.config_fileconfiginletdefault=ifargs.network=Nonethen" default"else""inletalias=matchconfig.blockchain_network.aliaswith|None->(* Cannot happen, as --network cannot take custom networks as arguments. *)""|Somealias->": "^aliasinFormat.eprintf"Created %s for%s network%s.@."args.config_filedefaultalias;return_unitinShared_arg.process_commandrunletupdate(args:Shared_arg.t)=letrun=letopenLwt_result_syntaxinlet*!()=Tezos_base_unix.Internal_event_unix.init()inifnot(Sys.file_existsargs.config_file)thenfailwith"Missing configuration file at %s. Use `%s config init [options]` to \
generate a new file"args.config_fileSys.argv.(0)elselet*config=Shared_arg.read_and_patch_config_fileargsinlet*()=Config_validation.checkconfiginConfig_file.writeargs.config_fileconfiginShared_arg.process_commandrunletvalidate(args:Shared_arg.t)=letrun=letopenLwt_result_syntaxinlet*!()=Tezos_base_unix.Internal_event_unix.init()inifnot(Sys.file_existsargs.config_file)thenFormat.eprintf"@[<v>@[<v 9>Warning: no configuration file found at %s@,\
validating the default configuration@]@]@."args.config_file;let*config=Shared_arg.read_and_patch_config_fileargsinlet*!r=Config_validation.checkconfiginmatchrwith(* Here we do not consider the node configuration file
being invalid as a failure. *)|Error(Config_validation.Invalid_node_configuration::_)|Ok()->return_unit|err->Lwt.returnerrinShared_arg.process_commandrun(** Main *)moduleTerm=structletcmds=letopenCmdlinerin[Cmd.v(Cmd.info~doc:"reads, parses and displays Tezos current config file. Use this \
command to see exactly what config file will be used by Tezos. \
If additional command-line arguments are provided, the displayed \
configuration will be amended accordingly. This is the default \
operation""show")Term.(ret(constshow$Shared_arg.Term.args));Cmd.v(Cmd.info~doc:"will overwrite the current configuration file with a factory \
default one. If additional command-line arguments are provided, \
they will amend the generated file. It assumes that a \
configuration file already exists and will abort otherwise""reset")Term.(ret(constreset$Shared_arg.Term.args));Cmd.v(Cmd.info~doc:"is like reset but assumes that no configuration file is present \
and will abort otherwise""init")Term.(ret(constinit$Shared_arg.Term.args));Cmd.v(Cmd.info~doc:"is the main option to edit the configuration file of Tezos. It \
will parse command line arguments and add or replace \
corresponding entries in the Tezos configuration file""update")Term.(ret(constupdate$Shared_arg.Term.args));Cmd.v(Cmd.info~doc:"verifies that the configuration file parses correctly and \
performs some sanity checks on its values""validate")Term.(ret(constvalidate$Shared_arg.Term.args));]endmoduleManpage=structletcommand_description="The $(b,config) command is meant to inspect and amend the configuration \
of the Tezos node. This command is complementary to manually editing the \
tezos node configuration file. Its arguments are a subset of the $(i,run) \
command ones."letoptions=letschema=Data_encoding.Json.schemaConfig_file.encodinginletschema=Format.asprintf"@[%a@]"Json_schema.ppschemainletschema=String.concat"\\$"(String.split_no_empty'$'schema)in[`S"OPTIONS";`P"All options available in the config file";`Preschema]letman=Shared_arg.Manpage.args@options@Shared_arg.Manpage.bugsletinfo=Cmdliner.Cmd.info~doc:"Manage node configuration"~man"config"endletcmd=Cmdliner.Cmd.groupManpage.infoTerm.cmds