Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iroh-ctl): implement available commands #123

Merged
merged 8 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion iroh-ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = "Client for interacting with running iroh processes."
anyhow = "1.0"
async-trait = "0.1"
futures = "0.3.5"
tokio = "1.0"
tokio = { version = "1.0", features = ["fs", "io-util"] }
tracing = "0.1.34"
clap = { version = "3.1.14", features = ["derive"] }
crossterm = "0.23.2"
Expand All @@ -23,3 +23,7 @@ serde = { version = "1.0", features = ["derive"] }
git-version = "0.3.5"
iroh-metrics = { path = "../iroh-metrics" }
prometheus-client = "0.16.0"
libp2p = "0.47"
cid = "0.8.5"
multiaddr = "0.14.0"
bytes = "1.1.0"
49 changes: 49 additions & 0 deletions iroh-ctl/src/gateway.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use anyhow::Result;
use clap::{Args, Subcommand};
use iroh_rpc_client::Client;

#[derive(Args, Debug, Clone)]
pub struct Gateway {
#[clap(subcommand)]
command: GatewayCommands,
}

#[derive(Subcommand, Debug, Clone)]
pub enum GatewayCommands {
#[clap(about = "Version of the iroh gateway binary")]
Version,
Dev(Dev),
}

#[derive(Args, Debug, Clone)]
#[clap(hide = true)]
pub struct Dev {
#[clap(subcommand)]
command: DevCommands,
}

#[derive(Subcommand, Debug, Clone)]
pub enum DevCommands {
#[clap(hide = true)]
Get { curl: String },
#[clap(hide = true)]
Head,
}

pub async fn run_command(rpc: Client, g: Gateway) -> Result<()> {
match g.command {
GatewayCommands::Version => {
let v = rpc.gateway.version().await?;
println!("v{}", v);
}
GatewayCommands::Dev(dev) => match dev.command {
DevCommands::Get { curl } => {
todo!("Get not yet implemented: {}", curl);
}
DevCommands::Head => {
todo!("Head not yet implemented");
}
},
}
Ok(())
}
3 changes: 3 additions & 0 deletions iroh-ctl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod config;
pub mod gateway;
pub mod metrics;
pub mod p2p;
pub mod status;
pub mod store;
22 changes: 19 additions & 3 deletions iroh-ctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ use std::collections::HashMap;
use std::path::PathBuf;

use clap::{Parser, Subcommand};
use iroh_ctl::metrics;
use iroh_ctl::{
gateway::{run_command as run_gateway_command, Gateway},
metrics,
p2p::{run_command as run_p2p_command, P2p},
store::{run_command as run_store_command, Store},
};
use iroh_rpc_client::Client;
use iroh_util::{iroh_home_path, make_config};
use prometheus_client::registry::Registry;
Expand All @@ -13,7 +18,7 @@ use iroh_ctl::{
};

#[derive(Parser, Debug, Clone)]
#[clap(author, version, about, long_about = None, propagate_version = true)]
#[clap(version, about, long_about = None, propagate_version = true)]
struct Cli {
#[clap(long)]
cfg: Option<PathBuf>,
Expand All @@ -33,12 +38,17 @@ impl Cli {

#[derive(Subcommand, Debug, Clone)]
enum Commands {
/// status checks the health of the differen processes
/// status checks the health of the different processes
#[clap(about = "Check the health of the different iroh processes.")]
Status {
#[clap(short, long)]
/// when true, updates the status table whenever a change in a process's status occurs
watch: bool,
},
Version,
P2p(P2p),
Store(Store),
Gateway(Gateway),
}

#[tokio::main(flavor = "multi_thread")]
Expand Down Expand Up @@ -76,6 +86,12 @@ async fn main() -> anyhow::Result<()> {
Commands::Status { watch } => {
crate::status::status(client, watch).await?;
}
Commands::Version => {
ramfox marked this conversation as resolved.
Show resolved Hide resolved
println!("v{}", env!("CARGO_PKG_VERSION"));
}
Commands::P2p(p2p) => run_p2p_command(client, p2p).await?,
Commands::Store(store) => run_store_command(client, store).await?,
Commands::Gateway(gateway) => run_gateway_command(client, gateway).await?,
};

metrics_handle.shutdown();
Expand Down
Loading