summaryrefslogtreecommitdiffstats
path: root/ipfs-cli/src/command/dag.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ipfs-cli/src/command/dag.rs')
-rw-r--r--ipfs-cli/src/command/dag.rs64
1 files changed, 34 insertions, 30 deletions
diff --git a/ipfs-cli/src/command/dag.rs b/ipfs-cli/src/command/dag.rs
index c2b4f39..cd070ac 100644
--- a/ipfs-cli/src/command/dag.rs
+++ b/ipfs-cli/src/command/dag.rs
@@ -6,39 +6,43 @@
// 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;
+use clap::App;
+use command::CliCommand;
+use futures::Future;
-pub fn signature<'a, 'b>() -> App<'a, 'b> {
- clap_app!(
- @subcommand dag =>
- (@setting SubcommandRequiredElseHelp)
- (@subcommand get =>
- (about: "Get a dag node from IPFS")
- (@arg KEY: +required "The key of the object to get")
- )
- )
-}
+pub struct Command;
+
+impl CliCommand for Command {
+ const NAME: &'static str = "dag";
-pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
- match args.subcommand() {
- ("get", Some(args)) => {
+ fn signature<'a, 'b>() -> App<'a, 'b> {
+ clap_app!(
+ @subcommand dag =>
+ (@setting SubcommandRequiredElseHelp)
+ (@subcommand get =>
+ (about: "Get a dag node from IPFS")
+ (@arg KEY: +required "The key of the object to get")
+ )
+ )
+ }
+
+ handle!(
+ client;
+ ("get", args) => {
let key = args.value_of("KEY").unwrap();
- let dag = core.run(client.dag_get(key)).expect(EXPECTED_API);
- println!();
- if let Some(data) = dag.data {
- println!(" data :");
- println!("{}", data);
- }
- println!(" links :");
- for link in dag.links {
- println!(" {} ({}) ({:?})", link.name, link.size, link.cid);
- }
- println!();
+ client.dag_get(key).map(|dag| {
+ println!();
+ if let Some(data) = dag.data {
+ println!(" data :");
+ println!("{}", data);
+ }
+ println!(" links :");
+ for link in dag.links {
+ println!(" {} ({}) ({:?})", link.name, link.size, link.cid);
+ }
+ println!();
+ })
}
- _ => unreachable!(),
- }
+ );
}