-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(iroh-cli)!: move net and node cli into iroh-node-util under …
…the cli feature (#2954) ## Description Move net and node cli into iroh-node-util under the cli feature ## Breaking Changes This just affects iroh-cli module iroh-cli::commands::net moved to iroh-node-util::cli::net logic in iroh-cli::commands::rpc moved to iroh-node-util::cli::node ## Notes & open questions Note: this is the last one. ## Change checklist - [x] Self-review. - [x] ~~Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant.~~ - [x] ~~Tests if relevant.~~ - [x] All breaking changes documented. --------- Co-authored-by: dignifiedquire <me@dignifiedquire.com> Co-authored-by: Diva M <divma@protonmail.com>
- Loading branch information
1 parent
63336ab
commit cbf7fd0
Showing
9 changed files
with
95 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! Cli commands. | ||
pub mod net; | ||
pub mod node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! Node commands | ||
use clap::Subcommand; | ||
|
||
use crate::rpc::client::node; | ||
|
||
/// Commands to manage the iroh RPC. | ||
#[derive(Subcommand, Debug, Clone)] | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum NodeCommands { | ||
/// Get statistics and metrics from the running node. | ||
Stats, | ||
/// Get status of the running node. | ||
Status, | ||
/// Shutdown the running node. | ||
Shutdown { | ||
/// Shutdown mode. | ||
/// | ||
/// Hard shutdown will immediately terminate the process, soft shutdown will wait | ||
/// for all connections to close. | ||
#[clap(long, default_value_t = false)] | ||
force: bool, | ||
}, | ||
} | ||
|
||
impl NodeCommands { | ||
/// Run the RPC command given the iroh client and the console environment. | ||
pub async fn run(self, node: &node::Client) -> anyhow::Result<()> { | ||
match self { | ||
Self::Stats => { | ||
let stats = node.stats().await?; | ||
for (name, details) in stats.iter() { | ||
println!( | ||
"{:23} : {:>6} ({})", | ||
name, details.value, details.description | ||
); | ||
} | ||
Ok(()) | ||
} | ||
Self::Shutdown { force } => { | ||
node.shutdown(force).await?; | ||
Ok(()) | ||
} | ||
Self::Status => { | ||
let response = node.status().await?; | ||
println!("Listening addresses: {:#?}", response.listen_addrs); | ||
println!("Node ID: {}", response.addr.node_id); | ||
println!("Version: {}", response.version); | ||
if let Some(addr) = response.rpc_addr { | ||
println!("RPC Addr: {}", addr); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters