[go: nahoru, domu]

Skip to content

Commit

Permalink
Added CLI functionality to myceliumd-private to list, add, remove pee…
Browse files Browse the repository at this point in the history
…rs + list selected, fallback routes
  • Loading branch information
maximevanhees authored and LeeSmet committed Jun 6, 2024
1 parent 98bdb3b commit c62def9
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions myceliumd-private/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ pub enum Command {
#[command(subcommand)]
command: MessageCommand,
},

/// Actions related to peers (list, remove, add)
Peers {
#[command(subcommand)]
command: PeersCommand,
},

/// Actions related to routes (selected, fallback)
Routes {
#[command(subcommand)]
command: RoutesCommand,
},
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -126,6 +138,36 @@ pub enum MessageCommand {
},
}

#[derive(Debug, Subcommand)]
pub enum PeersCommand {
/// List the connected peers
List {
/// Print the peers list in JSON format
#[arg(long = "json", default_value_t = false)]
json: bool,
},
/// Add peer(s)
Add { peers: Vec<String> },
/// Remove peer(s)
Remove { peers: Vec<String> },
}

#[derive(Debug, Subcommand)]
pub enum RoutesCommand {
/// Print all selected routes
Selected {
/// Print selected routes in JSON format
#[arg(long = "json", default_value_t = false)]
json: bool,
},
/// Print all fallback routes
Fallback {
/// Print fallback routes in JSON format
#[arg(long = "json", default_value_t = false)]
json: bool,
},
}

#[derive(Debug, Args)]
pub struct NodeArguments {
/// Peers to connect to.
Expand Down Expand Up @@ -302,6 +344,25 @@ async fn main() -> Result<(), Box<dyn Error>> {
.await
}
},
Command::Peers { command } => match command {
PeersCommand::List { json } => {
return mycelium_cli::list_peers(cli.node_args.api_addr, json).await;
}
PeersCommand::Add { peers } => {
return mycelium_cli::add_peers(cli.node_args.api_addr, peers).await;
}
PeersCommand::Remove { peers } => {
return mycelium_cli::remove_peers(cli.node_args.api_addr, peers).await;
}
},
Command::Routes { command } => match command {
RoutesCommand::Selected { json } => {
return mycelium_cli::list_selected_routes(cli.node_args.api_addr, json).await;
}
RoutesCommand::Fallback { json } => {
return mycelium_cli::list_fallback_routes(cli.node_args.api_addr, json).await;
}
},
}
}

Expand Down

0 comments on commit c62def9

Please sign in to comment.