diff options
Diffstat (limited to 'ipfs-cli/src/command/bootstrap.rs')
-rw-r--r-- | ipfs-cli/src/command/bootstrap.rs | 88 |
1 files changed, 41 insertions, 47 deletions
diff --git a/ipfs-cli/src/command/bootstrap.rs b/ipfs-cli/src/command/bootstrap.rs index dc3014e..af1e406 100644 --- a/ipfs-cli/src/command/bootstrap.rs +++ b/ipfs-cli/src/command/bootstrap.rs @@ -6,32 +6,9 @@ // copied, modified, or distributed except according to those terms. // -use clap::{App, ArgMatches}; -use command::EXPECTED_API; -use ipfs_api::IpfsClient; -use tokio_core::reactor::Core; - -pub fn signature<'a, 'b>() -> App<'a, 'b> { - clap_app!( - @subcommand bootstrap => - (@setting SubcommandRequiredElseHelp) - (@subcommand add => - (@setting SubcommandRequiredElseHelp) - (@subcommand default => - (about: "Add default peers to the bootstrap list") - ) - ) - (@subcommand list => - (about: "Show peers in the bootstrap list") - ) - (@subcommand rm => - (@setting SubcommandRequiredElseHelp) - (@subcommand all => - (about: "Remove all peers from the bootstrap list") - ) - ) - ) -} +use clap::App; +use command::CliCommand; +use futures::Future; fn print_peers(peers: &[String]) { println!(); @@ -42,30 +19,47 @@ fn print_peers(peers: &[String]) { println!(); } -pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) { - match args.subcommand() { - ("add", Some(add)) => match add.subcommand() { - ("default", _) => { - let peers = core.run(client.bootstrap_add_default()) - .expect(EXPECTED_API); +pub struct Command; - print_peers(&peers.peers); - } - _ => unreachable!(), - }, - ("list", _) => { - let peers = core.run(client.bootstrap_list()).expect(EXPECTED_API); +impl CliCommand for Command { + const NAME: &'static str = "bootstrap"; - print_peers(&peers.peers); - } - ("rm", Some(rm)) => match rm.subcommand() { - ("all", _) => { - let peers = core.run(client.bootstrap_rm_all()).expect(EXPECTED_API); + fn signature<'a, 'b>() -> App<'a, 'b> { + clap_app!( + @subcommand bootstrap => + (@setting SubcommandRequiredElseHelp) + (@subcommand add => + (@setting SubcommandRequiredElseHelp) + (@subcommand default => + (about: "Add default peers to the bootstrap list") + ) + ) + (@subcommand list => + (about: "Show peers in the bootstrap list") + ) + (@subcommand rm => + (@setting SubcommandRequiredElseHelp) + (@subcommand all => + (about: "Remove all peers from the bootstrap list") + ) + ) + ) + } - print_peers(&peers.peers); + handle!( + client; + ("add") => { + ("default", _args) => { + client.bootstrap_add_default().map(|peers| print_peers(&peers.peers)) } - _ => unreachable!(), }, - _ => unreachable!(), - } + ("list", _args) => { + client.bootstrap_list().map(|peers| print_peers(&peers.peers)) + }, + ("rm") => { + ("all", _args) => { + client.bootstrap_rm_all().map(|peers| print_peers(&peers.peers)) + } + } + ); } |