summaryrefslogtreecommitdiffstats
path: root/ipfs-cli/src/command/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ipfs-cli/src/command/config.rs')
-rw-r--r--ipfs-cli/src/command/config.rs67
1 files changed, 35 insertions, 32 deletions
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!(),
- }
+ );
}