summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2018-06-27 15:54:50 -0400
committerFerris Tseng <ferristseng@fastmail.fm>2018-06-27 15:54:50 -0400
commitb786be1e6087a45f1db236f30d91803710c41274 (patch)
tree71c0b6beaf929c4b846d6719cbecad9bb64bf20b
parent6acbf0e0f710ca1c897b1242e84a908ca32b45c3 (diff)
upgrade for hyper 0.12; use macros to build commands
-rw-r--r--ipfs-cli/Cargo.toml2
-rw-r--r--ipfs-cli/src/command/add.rs50
-rw-r--r--ipfs-cli/src/command/bitswap.rs173
-rw-r--r--ipfs-cli/src/command/block.rs128
-rw-r--r--ipfs-cli/src/command/bootstrap.rs88
-rw-r--r--ipfs-cli/src/command/cat.rs41
-rw-r--r--ipfs-cli/src/command/commands.rs38
-rw-r--r--ipfs-cli/src/command/config.rs67
-rw-r--r--ipfs-cli/src/command/dag.rs64
-rw-r--r--ipfs-cli/src/command/dht.rs121
-rw-r--r--ipfs-cli/src/command/diag.rs117
-rw-r--r--ipfs-cli/src/command/dns.rs47
-rw-r--r--ipfs-cli/src/command/file.rs92
-rw-r--r--ipfs-cli/src/command/files.rs283
-rw-r--r--ipfs-cli/src/command/filestore.rs103
-rw-r--r--ipfs-cli/src/command/mod.rs118
-rw-r--r--ipfs-cli/src/command/shutdown.rs29
-rw-r--r--ipfs-cli/src/command/version.rs43
-rw-r--r--ipfs-cli/src/main.rs82
19 files changed, 942 insertions, 744 deletions
diff --git a/ipfs-cli/Cargo.toml b/ipfs-cli/Cargo.toml
index f7fae2a..e0a11e6 100644
--- a/ipfs-cli/Cargo.toml
+++ b/ipfs-cli/Cargo.toml
@@ -10,5 +10,5 @@ license = "MIT OR Apache-2.0"
[dependencies]
clap = "2.27"
futures = "0.1"
+hyper = "0.12"
ipfs-api = { path = "../ipfs-api" }
-tokio-core = "0.1"
diff --git a/ipfs-cli/src/command/add.rs b/ipfs-cli/src/command/add.rs
index d732091..4382231 100644
--- a/ipfs-cli/src/command/add.rs
+++ b/ipfs-cli/src/command/add.rs
@@ -6,28 +6,38 @@
// 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 add =>
- (about: "Add file to IPFS")
- (@arg INPUT: +required {verify_file} "File to add")
- )
-}
+pub struct Command;
+
+impl CliCommand for Command {
+ const NAME: &'static str = "add";
+
+ fn signature<'a, 'b>() -> App<'a, 'b> {
+ clap_app!(
+ @subcommand add =>
+ (about: "Add file to IPFS")
+ (@arg INPUT: +required {verify_file} "File to add")
+ )
+ }
-pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
- let path = args.value_of("INPUT").unwrap();
- let file = File::open(path).expect(EXPECTED_FILE);
- let response = core.run(client.add(file)).expect(EXPECTED_API);
+ handle!(
+ (args, client) => {
+ let path = args.value_of("INPUT").unwrap();
+ let file = File::open(path).expect(EXPECTED_FILE);
- println!();
- println!(" name : {}", response.name);
- println!(" hash : {}", response.hash);
- println!(" size : {}", response.size);
- println!();
+ client
+ .add(file)
+ .map(|response| {
+ println!();
+ println!(" name : {}", response.name);
+ println!(" hash : {}", response.hash);
+ println!(" size : {}", response.size);
+ println!();
+ })
+ }
+ );
}
diff --git a/ipfs-cli/src/command/bitswap.rs b/ipfs-cli/src/command/bitswap.rs
index a63c21f..95e6752 100644
--- a/ipfs-cli/src/command/bitswap.rs
+++ b/ipfs-cli/src/command/bitswap.rs
@@ -6,93 +6,106 @@
// 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 bitswap =>
- (@setting SubcommandRequiredElseHelp)
- (@subcommand ledger =>
- (about: "Show the current ledger for a peer")
- (@arg PEER: +required "Peer to inspect")
- )
- (@subcommand reprovide =>
- (about: "Triggers a reprovide")
- )
- (@subcommand stat =>
- (about: "Show some diagnostic information on the bitswap agent")
- )
- (@subcommand unwant =>
- (about: "Remove a given block from your wantlist")
- (@arg KEY: +required "Key of the block to remove")
- )
- (@subcommand wantlist =>
- (about: "Shows blocks currently on the wantlist")
- )
- )
-}
+pub struct Command;
-pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
- match args.subcommand() {
- ("ledger", Some(args)) => {
- let peer = args.value_of("PEER").unwrap();
- let ledger = core.run(client.bitswap_ledger(peer)).expect(EXPECTED_API);
+impl CliCommand for Command {
+ const NAME: &'static str = "bitswap";
- println!();
- println!(" peer : {}", ledger.peer);
- println!(" value : {}", ledger.value);
- println!(" sent : {}", ledger.sent);
- println!(" recv : {}", ledger.recv);
- println!(" exchanged : {}", ledger.exchanged);
- println!();
- }
- ("reprovide", _) => {
- core.run(client.bitswap_reprovide()).expect(EXPECTED_API);
- }
- ("stat", _) => {
- let stat = core.run(client.bitswap_stat()).expect(EXPECTED_API);
+ fn signature<'a, 'b>() -> App<'a, 'b> {
+ clap_app!(
+ @subcommand bitswap =>
+ (@setting SubcommandRequiredElseHelp)
+ (@subcommand ledger =>
+ (about: "Show the current ledger for a peer")
+ (@arg PEER: +required "Peer to inspect")
+ )
+ (@subcommand reprovide =>
+ (about: "Triggers a reprovide")
+ )
+ (@subcommand stat =>
+ (about: "Show some diagnostic information on the bitswap agent")
+ )
+ (@subcommand unwant =>
+ (about: "Remove a given block from your wantlist")
+ (@arg KEY: +required "Key of the block to remove")
+ )
+ (@subcommand wantlist =>
+ (about: "Shows blocks currently on the wantlist")
+ )
+ )
+ }
- println!();
- println!(" provide_buf_len : {}", stat.provide_buf_len);
- println!(" wantlist :");
- for want in stat.wantlist {
- println!(" {}", want);
- }
- println!(" peers :");
- for peer in stat.peers {
- println!(" {}", peer);
- }
- println!(" blocks_received : {}", stat.blocks_received);
- println!(" data_received : {}", stat.data_received);
- println!(" blocks_sent : {}", stat.blocks_sent);
- println!(" data_sent : {}", stat.data_sent);
- println!(" dup_blks_received : {}", stat.dup_blks_received);
- println!(" dup_data_received : {}", stat.dup_data_received);
- println!();
- }
- ("unwant", Some(args)) => {
- let key = args.value_of("KEY").unwrap();
+ handle!(
+ client;
+ ("ledger", args) => {
+ let peer = args.value_of("PEER").unwrap();
- core.run(client.bitswap_unwant(key)).expect(EXPECTED_API);
+ client
+ .bitswap_ledger(peer)
+ .map(|ledger| {
+ println!();
+ println!(" peer : {}", ledger.peer);
+ println!(" value : {}", ledger.value);
+ println!(" sent : {}", ledger.sent);
+ println!(" recv : {}", ledger.recv);
+ println!(" exchanged : {}", ledger.exchanged);
+ println!();
+ })
+ },
+ ("reprovide", _args) => {
+ client.bitswap_reprovide().map(|_| ())
+ },
+ ("stat", _args) => {
+ client
+ .bitswap_stat()
+ .map(|stat| {
+ println!();
+ println!(" provide_buf_len : {}", stat.provide_buf_len);
+ println!(" wantlist :");
+ for want in stat.wantlist {
+ println!(" {}", want);
+ }
+ println!(" peers :");
+ for peer in stat.peers {
+ println!(" {}", peer);
+ }
+ println!(" blocks_received : {}", stat.blocks_received);
+ println!(" data_received : {}", stat.data_received);
+ println!(" blocks_sent : {}", stat.blocks_sent);
+ println!(" data_sent : {}", stat.data_sent);
+ println!(" dup_blks_received : {}", stat.dup_blks_received);
+ println!(" dup_data_received : {}", stat.dup_data_received);
+ println!();
+ })
+ },
+ ("unwant", args) => {
+ let key = args.value_of("KEY").unwrap();
- println!();
- println!(" OK");
- println!();
- }
- ("wantlist", Some(args)) => {
+ client
+ .bitswap_unwant(key)
+ .map(|_| {
+ println!();
+ println!(" OK");
+ println!();
+ })
+ },
+ ("wantlist", args) => {
let peer = args.value_of("PEER");
- let wantlist = core.run(client.bitswap_wantlist(peer)).expect(EXPECTED_API);
- println!();
- println!(" wantlist :");
- for key in wantlist.keys {
- println!(" {}", key);
- }
- println!();
+ client
+ .bitswap_wantlist(peer)
+ .map(|wantlist| {
+ println!();
+ println!(" wantlist :");
+ for key in wantlist.keys {
+ println!(" {}", key);
+ }
+ println!();
+ })
}
- _ => unreachable!(),
- }
+ );
}
diff --git a/ipfs-cli/src/command/block.rs b/ipfs-cli/src/command/block.rs
index 7cccb5b..b4ca887 100644
--- a/ipfs-cli/src/command/block.rs
+++ b/ipfs-cli/src/command/block.rs
@@ -6,77 +6,87 @@
// copied, modified, or distributed except according to those terms.
//
-use clap::{App, ArgMatches};
-use command::{verify_file, EXPECTED_API, EXPECTED_FILE};
-use futures::stream::Stream;
-use ipfs_api::IpfsClient;
+use clap::App;
+use command::{verify_file, CliCommand, EXPECTED_FILE};
+use futures::{Future, Stream};
use std::fs::File;
use std::io::{self, Write};
-use tokio_core::reactor::Core;
-pub fn signature<'a, 'b>() -> App<'a, 'b> {
- clap_app!(
- @subcommand block =>
- (@setting SubcommandRequiredElseHelp)
- (@subcommand get =>
- (about: "Get a raw IPFS block")
- (@arg KEY: +required "The base58 multihash of an existing block")
- )
- (@subcommand put =>
- (about: "Store a file as an IPFS block")
- (@arg INPUT: +required {verify_file} "The file to store as an IPFS block")
- )
- (@subcommand rm =>
- (about: "Removes an IPFS block")
- (@arg KEY: +required "The base58 multihash of a block to remove")
- )
- (@subcommand stat =>
- (about: "Get information about a raw IPFS block")
- (@arg KEY: +required "The base58 multihash of the block to retrieve")
- )
- )
-}
+pub struct Command;
+
+impl CliCommand for Command {
+ const NAME: &'static str = "block";
-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 block =>
+ (@setting SubcommandRequiredElseHelp)
+ (@subcommand get =>
+ (about: "Get a raw IPFS block")
+ (@arg KEY: +required "The base58 multihash of an existing block")
+ )
+ (@subcommand put =>
+ (about: "Store a file as an IPFS block")
+ (@arg INPUT: +required {verify_file} "The file to store as an IPFS block")
+ )
+ (@subcommand rm =>
+ (about: "Removes an IPFS block")
+ (@arg KEY: +required "The base58 multihash of a block to remove")
+ )
+ (@subcommand stat =>
+ (about: "Get information about a raw IPFS block")
+ (@arg KEY: +required "The base58 multihash of the block to retrieve")
+ )
+ )
+ }
+
+ handle!(
+ client;
+ ("get", args) => {
let key = args.value_of("KEY").unwrap();
- let req = client
- .block_get(key)
- .for_each(|chunk| io::stdout().write_all(&chunk).map_err(From::from));
- core.run(req).expect(EXPECTED_API);
- }
- ("put", Some(args)) => {
+ client
+ .block_get(key)
+ .for_each(|chunk| io::stdout().write_all(&chunk).map_err(From::from))
+ },
+ ("put", args) => {
let path = args.value_of("INPUT").unwrap();
let file = File::open(path).expect(EXPECTED_FILE);
- let block = core.run(client.block_put(file)).expect(EXPECTED_API);
- println!();
- println!(" key : {}", block.key);
- println!(" size : {}", block.size);
- println!();
- }
- ("rm", Some(args)) => {
+ client
+ .block_put(file)
+ .map(|block| {
+ println!();
+ println!(" key : {}", block.key);
+ println!(" size : {}", block.size);
+ println!();
+ })
+ },
+ ("rm", args) => {
let key = args.value_of("KEY").unwrap();
- let rm = core.run(client.block_rm(key)).expect(EXPECTED_API);
- println!();
- println!(" hash : {}", rm.hash);
- if let Some(error) = rm.error {
- println!(" error : {}", error);
- }
- println!();
- }
- ("stat", Some(args)) => {
+ client
+ .block_rm(key)
+ .map(|rm| {
+ println!();
+ println!(" hash : {}", rm.hash);
+ if let Some(error) = rm.error {
+ println!(" error : {}", error);
+ }
+ println!();
+ })
+ },
+ ("stat", args) => {
let key = args.value_of("KEY").unwrap();
- let stat = core.run(client.block_stat(key)).expect(EXPECTED_API);
- println!();
- println!(" key : {}", stat.key);
- println!(" size : {}", stat.size);
- println!();
+ client
+ .block_stat(key)
+ .map(|stat| {
+ println!();
+ println!(" key : {}", stat.key);
+ println!(" size : {}", stat.size);
+ println!();
+ })
}
- _ => unreachable!(),
- }
+ );
}
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))
+ }
+ }
+ );
}
diff --git a/ipfs-cli/src/command/cat.rs b/ipfs-cli/src/command/cat.rs
index 1f77306..6e8a9e7 100644
--- a/ipfs-cli/src/command/cat.rs
+++ b/ipfs-cli/src/command/cat.rs
@@ -6,26 +6,31 @@
// copied, modified, or distributed except according to those terms.
//
-use clap::{App, ArgMatches};
-use command::EXPECTED_API;
-use futures::stream::Stream;
-use ipfs_api::IpfsClient;
+use clap::App;
+use command::CliCommand;
+use futures::{Future, Stream};
use std::io::{self, Write};
-use tokio_core::reactor::Core;
-pub fn signature<'a, 'b>() -> App<'a, 'b> {
- clap_app!(
- @subcommand cat =>
- (about: "Show IPFS object data")
- (@arg PATH: +required "The path of the IPFS object to get")
- )
-}
+pub struct Command;
+
+impl CliCommand for Command {
+ const NAME: &'static str = "cat";
+
+ fn signature<'a, 'b>() -> App<'a, 'b> {
+ clap_app!(
+ @subcommand cat =>
+ (about: "Show IPFS object data")
+ (@arg PATH: +required "The path of the IPFS object to get")
+ )
+ }
-pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
- let path = args.value_of("PATH").unwrap();
- let req = client
- .cat(&path)
- .for_each(|chunk| io::stdout().write_all(&chunk).map_err(From::from));
+ handle!(
+ (args, client) => {
+ let path = args.value_of("PATH").unwrap();
- core.run(req).expect(EXPECTED_API);
+ client
+ .cat(&path)
+ .for_each(|chunk| io::stdout().write_all(&chunk).map_err(From::from))
+ }
+ );
}
diff --git a/ipfs-cli/src/command/commands.rs b/ipfs-cli/src/command/commands.rs
index ffba5f2..4ded502 100644
--- a/ipfs-cli/src/command/commands.rs
+++ b/ipfs-cli/src/command/commands.rs
@@ -1,5 +1,4 @@
// 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
@@ -7,17 +6,9 @@
//
use clap::App;
-use command::EXPECTED_API;
-use ipfs_api::IpfsClient;
+use command::CliCommand;
+use futures::Future;
use ipfs_api::response::CommandsResponse;
-use tokio_core::reactor::Core;
-
-pub fn signature<'a, 'b>() -> App<'a, 'b> {
- clap_app!(
- @subcommand commands =>
- (about: "List all available commands")
- )
-}
fn recursive_print_commands(cmd: CommandsResponse, stack: &mut Vec<String>) {
if cmd.subcommands.is_empty() {
@@ -35,10 +26,25 @@ fn recursive_print_commands(cmd: CommandsResponse, stack: &mut Vec<String>) {
}
}
-pub fn handle(core: &mut Core, client: &IpfsClient) {
- let commands = core.run(client.commands()).expect(EXPECTED_API);
+pub struct Command;
+
+impl CliCommand for Command {
+ const NAME: &'static str = "commands";
- println!();
- recursive_print_commands(commands, &mut Vec::new());
- println!();
+ fn signature<'a, 'b>() -> App<'a, 'b> {
+ clap_app!(
+ @subcommand commands =>
+ (about: "List all available commands")
+ )
+ }
+
+ handle!(
+ (_args, client) => {
+ client.commands().map(|commands| {
+ println!();
+ recursive_print_commands(commands, &mut Vec::new());
+ println!();
+ })
+ }
+ );
}
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!(),
- }
+ );
}
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!(),
- }
+ );
}
diff --git a/ipfs-cli/src/command/dht.rs b/ipfs-cli/src/command/dht.rs
index 9f95d3a..0e13f22 100644
--- a/ipfs-cli/src/command/dht.rs
+++ b/ipfs-cli/src/command/dht.rs
@@ -6,44 +6,10 @@
// copied, modified, or distributed except according to those terms.
//
-use clap::{App, ArgMatches};
-use command::EXPECTED_API;
-use futures::stream::Stream;
-use ipfs_api::IpfsClient;
+use clap::App;
+use command::CliCommand;
+use futures::{Future, Stream};
use ipfs_api::response::DhtMessage;
-use tokio_core::reactor::Core;
-
-pub fn signature<'a, 'b>() -> App<'a, 'b> {
- clap_app!(
- @subcommand dht =>
- (@setting SubcommandRequiredElseHelp)
- (@subcommand findpeer =>
- (about: "Query the DHT for all of the multiaddresses associated with a Peer ID")
- (@arg PEER: +required "Peer to search for")
- )
- (@subcommand findprovs =>
- (about: "Find peers in the DHT that can provide the given key")
- (@arg KEY: +required "Key to search for")
- )
- (@subcommand get =>
- (about: "Given a key, query the DHT for its best value")
- (@arg KEY: +required "The key search for")
- )
- (@subcommand provide =>
- (about: "Announce to the network that you are providing the given values")
- (@arg KEY: +required "The key you are providing")
- )
- (@subcommand put =>
- (about: "Write a key/value pair to the DHT")
- (@arg KEY: +required "The key to store the value at")
- (@arg VALUE: +required "The value to store")
- )
- (@subcommand query =>
- (about: "Find the closest peer to a given peer by querying the DHT")
-