From b786be1e6087a45f1db236f30d91803710c41274 Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Wed, 27 Jun 2018 15:54:50 -0400 Subject: upgrade for hyper 0.12; use macros to build commands --- ipfs-cli/src/command/config.rs | 67 ++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 32 deletions(-) (limited to 'ipfs-cli/src/command/config.rs') diff --git a/ipfs-cli/src/command/config.rs b/ipfs-cli/src/command/config.rs index e778816..1b0cf79 100644 --- a/ipfs-cli/src/command/config.rs +++ b/ipfs-cli/src/command/config.rs @@ -6,43 +6,46 @@ // copied, modified, or distributed except according to those terms. // -use clap::{App, ArgMatches}; -use command::{verify_file, EXPECTED_API, EXPECTED_FILE}; -use ipfs_api::IpfsClient; +use clap::App; +use command::{verify_file, CliCommand, EXPECTED_FILE}; +use futures::Future; use std::fs::File; -use tokio_core::reactor::Core; -pub fn signature<'a, 'b>() -> App<'a, 'b> { - clap_app!( - @subcommand config => - (@setting SubcommandRequiredElseHelp) - (@subcommand edit => - (about: "Open the config file for editing") - ) - (@subcommand replace => - (about: "Replace the config file") - (@arg INPUT: +required {verify_file} "Config file to replace with") - ) - (@subcommand show => - (about: "Show the config file") - ) - ) -} +pub struct Command; + +impl CliCommand for Command { + const NAME: &'static str = "config"; + + fn signature<'a, 'b>() -> App<'a, 'b> { + clap_app!( + @subcommand config => + (@setting SubcommandRequiredElseHelp) + (@subcommand edit => + (about: "Open the config file for editing") + ) + (@subcommand replace => + (about: "Replace the config file") + (@arg INPUT: +required {verify_file} "Config file to replace with") + ) + (@subcommand show => + (about: "Show the config file") + ) + ) + } -pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) { - match args.subcommand() { - ("edit", _) => core.run(client.config_edit()).expect(EXPECTED_API), - ("replace", Some(args)) => { + handle!( + client; + ("edit", _args) => { + client.config_edit().map(|_| ()) + }, + ("replace", args) => { let path = args.value_of("INPUT").unwrap(); let config = File::open(path).expect(EXPECTED_FILE); - core.run(client.config_replace(config)).expect(EXPECTED_API); + client.config_replace(config).map(|_| ()) + }, + ("show", _args) => { + client.config_show().map(|config| println!("{}", config)) } - ("show", _) => { - let config = core.run(client.config_show()).expect(EXPECTED_API); - - println!("{}", config); - } - _ => unreachable!(), - } + ); } -- cgit v1.2.3