summaryrefslogtreecommitdiffstats
path: root/ipfs-cli/src/command/filestore.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ipfs-cli/src/command/filestore.rs')
-rw-r--r--ipfs-cli/src/command/filestore.rs103
1 files changed, 52 insertions, 51 deletions
diff --git a/ipfs-cli/src/command/filestore.rs b/ipfs-cli/src/command/filestore.rs
index bf49c09..f8a275f 100644
--- a/ipfs-cli/src/command/filestore.rs
+++ b/ipfs-cli/src/command/filestore.rs
@@ -6,31 +6,12 @@
// copied, modified, or distributed except according to those terms.
//
-use clap::{App, ArgMatches};
-use command::EXPECTED_API;
-use futures::stream::Stream;
-use ipfs_api::{response, IpfsClient};
-use tokio_core::reactor::Core;
+use clap::App;
+use command::CliCommand;
+use futures::{Future, Stream};
+use ipfs_api::response::FilestoreObject;
-pub fn signature<'a, 'b>() -> App<'a, 'b> {
- clap_app!(
- @subcommand filestore =>
- (@setting SubcommandRequiredElseHelp)
- (@subcommand dups =>
- (about: "List blocks that are both in the filestore and standard block storage")
- )
- (@subcommand ls =>
- (about: "List objects in the filestore")
- (@arg CID: "Cid of the object to list")
- )
- (@subcommand verify =>
- (about: "Verify objects in the filestore")
- (@arg CID: "Cid of the object to verify")
- )
- )
-}
-
-fn print_filestore_object<E>(obj: &response::FilestoreObject) -> Result<(), E> {
+fn print_filestore_object<E>(obj: FilestoreObject) -> Result<(), E> {
println!(" status : {}", obj.status);
println!(" error_msg : {}", obj.error_msg);
println!(" key : {}", obj.key);
@@ -42,41 +23,61 @@ fn print_filestore_object<E>(obj: &response::FilestoreObject) -> Result<(), E> {
Ok(())
}
-pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
- match args.subcommand() {
- ("dups", _) => {
- let req = client.filestore_dups().for_each(|dup| {
- println!(" ref : {}", dup.reference);
- println!(" err : {}", dup.err);
- println!();
+pub struct Command;
- Ok(())
- });
+impl CliCommand for Command {
+ const NAME: &'static str = "filestore";
+ fn signature<'a, 'b>() -> App<'a, 'b> {
+ clap_app!(
+ @subcommand filestore =>
+ (@setting SubcommandRequiredElseHelp)
+ (@subcommand dups =>
+ (about: "List blocks that are both in the filestore and standard block storage")
+ )
+ (@subcommand ls =>
+ (about: "List objects in the filestore")
+ (@arg CID: "Cid of the object to list")
+ )
+ (@subcommand verify =>
+ (about: "Verify objects in the filestore")
+ (@arg CID: "Cid of the object to verify")
+ )
+ )
+ }
+
+ handle!(
+ client;
+ ("dups", _args) => {
println!();
- core.run(req).expect(EXPECTED_API);
- println!();
- }
- ("ls", Some(args)) => {
+
+ client
+ .filestore_dups()
+ .for_each(|dup| {
+ println!(" ref : {}", dup.reference);
+ println!(" err : {}", dup.err);
+ println!();
+
+ Ok(())
+ })
+ },
+ ("ls", args) => {
let cid = args.value_of("CID");
- let req = client
- .filestore_ls(cid)
- .for_each(|res| print_filestore_object(&res));
println!();
- core.run(req).expect(EXPECTED_API);
- println!();
- }
- ("verify", Some(args)) => {
+
+ client
+ .filestore_ls(cid)
+ .for_each(print_filestore_object)
+ },
+ ("verify", args) => {
let cid = args.value_of("CID");
- let req = client
- .filestore_verify(cid)
- .for_each(|obj| print_filestore_object(&obj));
println!();
- core.run(req).expect(EXPECTED_API);
- println!();
+
+ client
+ .filestore_verify(cid)
+ .for_each(print_filestore_object)
}
- _ => unreachable!(),
- }
+ );
}