diff options
author | Ferris Tseng <ferristseng@fastmail.fm> | 2017-11-25 10:59:27 -0500 |
---|---|---|
committer | Ferris Tseng <ferristseng@fastmail.fm> | 2017-11-25 10:59:27 -0500 |
commit | b2ba32dcd849732d62eaed5940f5db5367e42fe1 (patch) | |
tree | 2e33b4545b7557c1e8f7b4f59ff0f17d8b708c07 /ipfs-cli/src/command/dag.rs | |
parent | 9f4887d08a712646d5c9afc37737a267474b0905 (diff) |
refactoring, and add new commands
Diffstat (limited to 'ipfs-cli/src/command/dag.rs')
-rw-r--r-- | ipfs-cli/src/command/dag.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ipfs-cli/src/command/dag.rs b/ipfs-cli/src/command/dag.rs new file mode 100644 index 0000000..e27375f --- /dev/null +++ b/ipfs-cli/src/command/dag.rs @@ -0,0 +1,46 @@ +// Copyright 2017 rust-ipfs-api Developers +// +// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or +// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or +// http://opensource.org/licenses/MIT>, at your option. This file may not be +// 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 dag => + (@setting SubcommandRequiredElseHelp) + (@subcommand get => + (about: "Get a dag node from IPFS") + (@arg KEY: +required "The key of the object to get") + ) + ) +} + + +pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) { + match args.subcommand() { + ("get", Some(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!(""); + } + _ => unreachable!(), + } +} |