The `cli` method exposed to handle all the cli commands, ideally from main. # Examples Sample usage: ```ignore # to start the daemon with ipc-client daemon ./config/template.toml ``` To register a new command, add the command to ```ignore pub async fn cli() { // ... other code let r = match &args.command { // ... other existing commands Commands::NewCommand => NewCommand::handle(n).await, };
()
| 128 | /// } |
| 129 | /// ``` |
| 130 | pub async fn cli() -> anyhow::Result<()> { |
| 131 | let global = GlobalOptions::parse(); |
| 132 | set_current_network(global.global_params.network()); |
| 133 | |
| 134 | // parse the arguments |
| 135 | let args = IPCAgentCliCommands::parse(); |
| 136 | |
| 137 | if let Some(generator) = args.generator { |
| 138 | let mut cmd = IPCAgentCliCommands::command(); |
| 139 | print_completions(generator, &mut cmd); |
| 140 | Ok(()) |
| 141 | } else { |
| 142 | let global = &args.global_params; |
| 143 | if let Some(c) = &args.command { |
| 144 | if !matches!(c, Commands::Node(_)) { |
| 145 | default_subscriber(); |
| 146 | } |
| 147 | |
| 148 | let r = match &c { |
| 149 | // Commands::Daemon(args) => LaunchDaemon::handle(global, args).await, |
| 150 | Commands::Config(args) => args.handle(global).await, |
| 151 | Commands::Subnet(args) => args.handle(global).await, |
| 152 | Commands::CrossMsg(args) => args.handle(global).await, |
| 153 | Commands::Wallet(args) => args.handle(global).await, |
| 154 | Commands::Checkpoint(args) => args.handle(global).await, |
| 155 | Commands::Util(args) => args.handle(global).await, |
| 156 | Commands::Validator(args) => args.handle(global).await, |
| 157 | Commands::Deploy(args) => DeployCommand::handle(global, args).await, |
| 158 | Commands::Ui(args) => run_ui_command(global.clone(), args.clone()).await, |
| 159 | Commands::Node(args) => args.handle(global).await, |
| 160 | }; |
| 161 | |
| 162 | r.with_context(|| format!("error processing command {:?}", args.command)) |
| 163 | } else { |
| 164 | Ok(()) |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | pub fn default_subscriber() { |
| 170 | tracing_subscriber::registry() |
no test coverage detected