From 99f77b44c9641412b4dea7975de6eaf3cfa043f0 Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Tue, 24 Dec 2019 12:07:39 -0500 Subject: remove ipfs-cli; too much of a maintenance burden --- Cargo.toml | 3 +- ipfs-cli/Cargo.toml | 15 --- ipfs-cli/src/command/add.rs | 45 --------- ipfs-cli/src/command/bitswap.rs | 111 ----------------------- ipfs-cli/src/command/block.rs | 92 ------------------- ipfs-cli/src/command/bootstrap.rs | 65 ------------- ipfs-cli/src/command/cat.rs | 36 -------- ipfs-cli/src/command/commands.rs | 50 ---------- ipfs-cli/src/command/config.rs | 51 ----------- ipfs-cli/src/command/dag.rs | 48 ---------- ipfs-cli/src/command/dht.rs | 104 --------------------- ipfs-cli/src/command/diag.rs | 81 ----------------- ipfs-cli/src/command/dns.rs | 40 -------- ipfs-cli/src/command/file.rs | 65 ------------- ipfs-cli/src/command/files.rs | 186 -------------------------------------- ipfs-cli/src/command/filestore.rs | 83 ----------------- ipfs-cli/src/command/mod.rs | 160 -------------------------------- ipfs-cli/src/command/shutdown.rs | 30 ------ ipfs-cli/src/command/version.rs | 38 -------- ipfs-cli/src/main.rs | 53 ----------- 20 files changed, 1 insertion(+), 1355 deletions(-) delete mode 100644 ipfs-cli/Cargo.toml delete mode 100644 ipfs-cli/src/command/add.rs delete mode 100644 ipfs-cli/src/command/bitswap.rs delete mode 100644 ipfs-cli/src/command/block.rs delete mode 100644 ipfs-cli/src/command/bootstrap.rs delete mode 100644 ipfs-cli/src/command/cat.rs delete mode 100644 ipfs-cli/src/command/commands.rs delete mode 100644 ipfs-cli/src/command/config.rs delete mode 100644 ipfs-cli/src/command/dag.rs delete mode 100644 ipfs-cli/src/command/dht.rs delete mode 100644 ipfs-cli/src/command/diag.rs delete mode 100644 ipfs-cli/src/command/dns.rs delete mode 100644 ipfs-cli/src/command/file.rs delete mode 100644 ipfs-cli/src/command/files.rs delete mode 100644 ipfs-cli/src/command/filestore.rs delete mode 100644 ipfs-cli/src/command/mod.rs delete mode 100644 ipfs-cli/src/command/shutdown.rs delete mode 100644 ipfs-cli/src/command/version.rs delete mode 100644 ipfs-cli/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 43c422b..e37572d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "ipfs-api", - "ipfs-cli" + "ipfs-api" ] diff --git a/ipfs-cli/Cargo.toml b/ipfs-cli/Cargo.toml deleted file mode 100644 index e3e1343..0000000 --- a/ipfs-cli/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "ipfs-cli" -description = "A CLI to interact with IPFS" -authors = ["Ferris Tseng "] -edition = "2018" -repository = "https://github.com/ferristseng/rust-ipfs-api" -version = "0.4.1" -readme = "../README.md" -license = "MIT OR Apache-2.0" - -[dependencies] -clap = "2.33" -futures = "0.3" -hyper = "0.13" -ipfs-api = { path = "../ipfs-api" } diff --git a/ipfs-cli/src/command/add.rs b/ipfs-cli/src/command/add.rs deleted file mode 100644 index 16411dd..0000000 --- a/ipfs-cli/src/command/add.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::{CliCommand, EXPECTED_FILE}; -use clap::App; -use futures::Future; -use std::path::Path; - -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 "File to add") - (@arg recursive: -r --recursive "Add directory paths recursively. Default: false") - ) - } - - handle!( - (args, client) => { - let path = args.value_of("INPUT").unwrap(); - if !args.is_present("recursive") && Path::new(path).is_dir() { - panic!(EXPECTED_FILE); - } - client - .add_path(path) - .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 deleted file mode 100644 index 5438d98..0000000 --- a/ipfs-cli/src/command/bitswap.rs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "bitswap"; - - 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") - ) - ) - } - - handle!( - client; - ("ledger", args) => { - let peer = args.value_of("PEER").unwrap(); - - 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(); - - client - .bitswap_unwant(key) - .map(|_| { - println!(); - println!(" OK"); - println!(); - }) - }, - ("wantlist", args) => { - let peer = args.value_of("PEER"); - - client - .bitswap_wantlist(peer) - .map(|wantlist| { - println!(); - println!(" wantlist :"); - for key in wantlist.keys { - println!(" {}", key); - } - println!(); - }) - } - ); -} diff --git a/ipfs-cli/src/command/block.rs b/ipfs-cli/src/command/block.rs deleted file mode 100644 index c477583..0000000 --- a/ipfs-cli/src/command/block.rs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::{verify_file, CliCommand, EXPECTED_FILE}; -use clap::App; -use futures::{Future, Stream}; -use std::fs::File; -use std::io::{self, Write}; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "block"; - - 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(); - - 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); - - 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(); - - 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(); - - client - .block_stat(key) - .map(|stat| { - println!(); - println!(" key : {}", stat.key); - println!(" size : {}", stat.size); - println!(); - }) - } - ); -} diff --git a/ipfs-cli/src/command/bootstrap.rs b/ipfs-cli/src/command/bootstrap.rs deleted file mode 100644 index 550a8a1..0000000 --- a/ipfs-cli/src/command/bootstrap.rs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; - -fn print_peers(peers: &[String]) { - println!(); - println!(" peers :"); - for peer in peers { - println!(" {}", peer); - } - println!(); -} - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "bootstrap"; - - 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") - ) - ) - ) - } - - handle!( - client; - ("add") => { - ("default", _args) => { - client.bootstrap_add_default().map(|peers| print_peers(&peers.peers)) - } - }, - ("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 deleted file mode 100644 index a04d661..0000000 --- a/ipfs-cli/src/command/cat.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::{Future, Stream}; -use std::io::{self, Write}; - -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") - ) - } - - handle!( - (args, client) => { - let path = args.value_of("PATH").unwrap(); - - 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 deleted file mode 100644 index 9092306..0000000 --- a/ipfs-cli/src/command/commands.rs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; -use ipfs_api::response::CommandsResponse; - -fn recursive_print_commands(cmd: CommandsResponse, stack: &mut Vec) { - if cmd.subcommands.is_empty() { - println!(" {} {}", stack.join(" "), cmd.name); - } else { - let (name, subcommands) = (cmd.name, cmd.subcommands); - - stack.push(name); - - for subcommand in subcommands { - recursive_print_commands(subcommand, stack); - } - - stack.pop(); - } -} - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "commands"; - - 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 deleted file mode 100644 index 03ea490..0000000 --- a/ipfs-cli/src/command/config.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::{verify_file, CliCommand, EXPECTED_FILE}; -use clap::App; -use futures::Future; -use std::fs::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") - ) - ) - } - - 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); - - client.config_replace(config).map(|_| ()) - }, - ("show", _args) => { - client.config_show().map(|config| println!("{}", config)) - } - ); -} diff --git a/ipfs-cli/src/command/dag.rs b/ipfs-cli/src/command/dag.rs deleted file mode 100644 index 529892f..0000000 --- a/ipfs-cli/src/command/dag.rs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "dag"; - - 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(); - - 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!(); - }) - } - ); -} diff --git a/ipfs-cli/src/command/dht.rs b/ipfs-cli/src/command/dht.rs deleted file mode 100644 index 72501cb..0000000 --- a/ipfs-cli/src/command/dht.rs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::{Future, Stream}; -use ipfs_api::response::DhtMessage; - -fn print_dht_response(res: DhtMessage) -> Result<(), E> { - println!(); - println!(" id : {}", res.id); - println!(" type : {:?}", res.typ); - println!(" responses :"); - for peer_res in res.responses { - println!(" id : {}", peer_res.id); - println!(" addrs :"); - for addr in peer_res.addrs { - println!(" {}", addr); - } - println!(); - } - println!(" extra : {}", res.extra); - println!(); - - Ok(()) -} - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "dht"; - - 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") - (@arg PEER: +required "The peer to run the query against") - ) - ) - } - - handle!( - client; - ("findpeer", args) => { - let peer = args.value_of("PEER").unwrap(); - - client.dht_findpeer(peer).for_each(print_dht_response) - }, - ("findprovs", args) => { - let key = args.value_of("KEY").unwrap(); - - client.dht_findprovs(key).for_each(print_dht_response) - }, - ("get", args) => { - let key = args.value_of("KEY").unwrap(); - - client.dht_get(key).for_each(print_dht_response) - }, - ("provide", args) => { - let key = args.value_of("KEY").unwrap(); - - client.dht_provide(&key).for_each(print_dht_response) - }, - ("put", args) => { - let key = args.value_of("KEY").unwrap(); - let val = args.value_of("VALUE").unwrap(); - - client.dht_put(key, val).for_each(print_dht_response) - }, - ("query", args) => { - let peer = args.value_of("PEER").unwrap(); - - client.dht_query(peer).for_each(print_dht_response) - } - ); -} diff --git a/ipfs-cli/src/command/diag.rs b/ipfs-cli/src/command/diag.rs deleted file mode 100644 index 4004441..0000000 --- a/ipfs-cli/src/command/diag.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::{App, Arg, SubCommand}; -use futures::Future; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "diag"; - - fn signature<'a, 'b>() -> App<'a, 'b> { - // The clap macro does not allow hyphenated command names, - // so the `set-time` command has to be manually instantiated. - // - let set_time_command = SubCommand::with_name("set-time") - .about("Set how long to keep inactive requests in the log") - .arg( - Arg::with_name("TIME") - .required(true) - .index(1) - .help("Time to keep inactive requests in the log"), - ); - - clap_app!( - @subcommand diag => - (@setting SubcommandRequiredElseHelp) - (@subcommand cmds => - (@setting SubcommandRequiredElseHelp) - (@subcommand clear => - (about: "Clear inactive requests from the log") - ) - (subcommand: set_time_command) - ) - (@subcommand sys => - (about: "Print system diagnostic information") - ) - ) - } - - handle!( - client; - ("cmds") => { - ("clear", _args) => { - client - .diag_cmds_clear() - .map(|_| { - println!(""); - println!(" OK"); - println!(""); - }) - }, - ("set-time", args) => { - let time = args.value_of("TIME").unwrap(); - - client - .diag_cmds_set_time(&time) - .map(|_| { - println!(""); - println!(" OK"); - println!(""); - }) - } - }, - ("sys", _args) => { - client - .diag_sys() - .map(|sys| { - println!(); - println!(" {}", sys); - println!(); - }) - } - ); -} diff --git a/ipfs-cli/src/command/dns.rs b/ipfs-cli/src/command/dns.rs deleted file mode 100644 index ded4fe4..0000000 --- a/ipfs-cli/src/command/dns.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "dns"; - - fn signature<'a, 'b>() -> App<'a, 'b> { - clap_app!( - @subcommand dns => - (about: "Resolve a DNS link") - (@arg PATH: +required "The domain name to resolve") - (@arg recursive: -r --recursive "Resolve until the result is not a DNS link") - ) - } - - handle!( - (args, client) => { - let path = args.value_of("PATH").unwrap(); - - client - .dns(path, args.is_present("recursive")) - .map(|res| { - println!(); - println!(" path : {}", res.path); - println!(); - }) - } - ); -} diff --git a/ipfs-cli/src/command/file.rs b/ipfs-cli/src/command/file.rs deleted file mode 100644 index b663a69..0000000 --- a/ipfs-cli/src/command/file.rs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "file"; - - fn signature<'a, 'b>() -> App<'a, 'b> { - clap_app!( - @subcommand file => - (@setting SubcommandRequiredElseHelp) - (@subcommand ls => - (about: "List directory contents for Unix filesystem objects") - (@arg PATH: +required "The path to list links from") - ) - ) - } - - handle!( - client; - ("ls", args) => { - let path = args.value_of("PATH").unwrap(); - - client - .file_ls(path) - .map(|ls| { - println!(); - println!(" arguments :"); - for (k, arg) in ls.arguments { - println!(" arg : {}", k); - println!(" value : {}", arg); - println!(); - } - println!(" objects :"); - for (k, obj) in ls.objects { - println!(" key : {}", k); - println!(" hash : {}", obj.hash); - println!(" size : {}", obj.size); - println!(" type : {}", obj.typ); - println!(" links :"); - for link in obj.links { - println!(" name : {}", link.name); - println!(" hash : {}", link.hash); - println!(" size : {}", link.size); - if let Some(ref typ) = link.typ { - println!(" type : {}", typ); - } - println!(); - } - } - println!(); - }) - } - ); -} diff --git a/ipfs-cli/src/command/files.rs b/ipfs-cli/src/command/files.rs deleted file mode 100644 index 91142c4..0000000 --- a/ipfs-cli/src/command/files.rs +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::{verify_file, CliCommand, EXPECTED_FILE}; -use clap::App; -use futures::{Future, Stream}; -use std::fs::File; -use std::io::{self, Write}; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "files"; - - fn signature<'a, 'b>() -> App<'a, 'b> { - clap_app!( - @subcommand files => - (@setting SubcommandRequiredElseHelp) - (@subcommand cp => - (about: "Copy files in MFS") - (@arg SRC: +required "The source object to copy") - (@arg DEST: +required "The destination to copy the object to") - ) - (@subcommand flush => - (about: "Flush a path's data to disk") - (@arg PATH: "The path to flush") - ) - (@subcommand ls => - (about: "List directories in MFS") - (@arg PATH: "The past to list") - ) - (@subcommand mkdir => - (about: "Make directories in MFS") - (@arg PATH: +required "The directory to create") - (@arg parents: -p --parents "Create parents if the directory \ - does not already exist") - ) - (@subcommand mv => - (about: "Move files in MFS") - (@arg SRC: +required "The source object to move") - (@arg DEST: +required "The destination to move the object to") - ) - (@subcommand read => - (about: "Read a file in MFS") - (@arg PATH: +required "The path to read") - ) - (@subcommand rm => - (about: "Remove a file in MFS") - (@arg PATH: +required "The file to remove") - (@arg recursive: -r --recursive "Recursively remove directories") - ) - (@subcommand stat => - (about: "Display status for a file in MFS") - (@arg PATH: +required "The file to get status for") - ) - (@subcommand write => - (about: "Write a file to MFS") - (@arg DEST: +required "The path to write to") - (@arg INPUT: +required {verify_file} "The file to write") - (@arg create: --create "Create the file if it does not exist") - (@arg truncate: --truncate "Truncate the file before writing") - ) - ) - } - - handle!( - client; - ("cp", args) => { - let src = args.value_of("SRC").unwrap(); - let dest = args.value_of("DEST").unwrap(); - - client - .files_cp(src, dest) - .map(|_| { - println!(); - println!(" OK"); - println!(); - }) - }, - ("flush", args) => { - let path = args.value_of("PATH"); - - client - .files_flush(path) - .map(|_| { - println!(); - println!(" OK"); - println!(); - }) - }, - ("ls", args) => { - let path = args.value_of("PATH"); - - client - .files_ls(path) - .map(|ls| { - println!(); - println!(" entries :"); - for entry in ls.entries { - println!(" name : {}", entry.name); - println!(" type : {}", entry.typ); - println!(" size : {}", entry.size); - println!(" hash : {}", entry.hash); - println!(); - } - println!(); - }) - }, - ("mkdir", args) => { - let path = args.value_of("PATH").unwrap(); - - client - .files_mkdir(path, args.is_present("parents")) - .map(|_| { - println!(); - println!(" OK"); - println!(); - }) - }, - ("mv", args) => { - let src = args.value_of("SRC").unwrap(); - let dest = args.value_of("DEST").unwrap(); - - client - .files_mv(src, dest) - .map(|_| { - println!(); - println!(" OK"); - println!(); - }) - }, - ("read", args) => { - let path = args.value_of("PATH").unwrap(); - - client - .files_read(path) - .for_each(|chunk| io::stdout().write_all(&chunk).map_err(From::from)) - }, - ("rm", args) => { - let path = args.value_of("PATH").unwrap(); - - client - .files_rm(path, args.is_present("recursive")) - .map(|_| { - println!(); - println!(" OK"); - println!(); - }) - }, - ("stat", args) => { - let path = args.value_of("PATH").unwrap(); - client - .files_stat(path) - .map(|stat| { - println!(); - println!(" hash : {}", stat.hash); - println!(" size : {}", stat.size); - println!(" cumulative_size : {}", stat.cumulative_size); - println!(" blocks : {}", stat.blocks); - println!(" type : {}", stat.typ); - println!(); - }) - }, - ("write", args) => { - let dest = args.value_of("DEST").unwrap(); - let path = args.value_of("INPUT").unwrap(); - let file = File::open(path).expect(EXPECTED_FILE); - - client.files_write( - dest, - args.is_present("create"), - args.is_present("truncate"), - file, - ).map(|_| { - println!(); - println!(" OK"); - println!(); - }) - } - ); -} diff --git a/ipfs-cli/src/command/filestore.rs b/ipfs-cli/src/command/filestore.rs deleted file mode 100644 index f503300..0000000 --- a/ipfs-cli/src/command/filestore.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::{Future, Stream}; -use ipfs_api::response::FilestoreObject; - -fn print_filestore_object(obj: FilestoreObject) -> Result<(), E> { - println!(" status : {}", obj.status); - println!(" error_msg : {}", obj.error_msg); - println!(" key : {}", obj.key); - println!(" file_path : {}", obj.file_path); - println!(" offset : {}", obj.offset); - println!(" size : {}", obj.size); - println!(); - - Ok(()) -} - -pub struct Command; - -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!(); - - client - .filestore_dups() - .for_each(|dup| { - println!(" ref : {}", dup.reference); - println!(" err : {}", dup.err); - println!(); - - Ok(()) - }) - }, - ("ls", args) => { - let cid = args.value_of("CID"); - - println!(); - - client - .filestore_ls(cid) - .for_each(print_filestore_object) - }, - ("verify", args) => { - let cid = args.value_of("CID"); - - println!(); - - client - .filestore_verify(cid) - .for_each(print_filestore_object) - } - ); -} diff --git a/ipfs-cli/src/command/mod.rs b/ipfs-cli/src/command/mod.rs deleted file mode 100644 index 7e2e99d..0000000 --- a/ipfs-cli/src/command/mod.rs +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use clap::{App, ArgMatches}; -use futures::Future; -use ipfs_api::IpfsClient; -use std::error::Error; -use std::fs; -use std::path::Path; - -pub type CommandExecutable = Box + 'static + Send>; - -pub const EXPECTED_FILE: &str = "expected to read input file"; - -/// Verifies that a path points to a file that exists, and not a directory. -/// -pub fn verify_file

(path: P) -> Result<(), String> -where - P: AsRef, -{ - match fs::metadata(path) { - Ok(ref metadata) if metadata.is_file() => Ok(()), - Ok(_) => Err("file must not be a directory".into()), - Err(e) => Err(e.description().into()), - } -} - -pub trait CliCommand { - /// Name of the command. - /// - const NAME: &'static str; - - /// Returns the signature of the application. - /// - fn signature<'a, 'b>() -> App<'a, 'b>; - - /// Creates a future representing the request to make. - /// - fn handle(client: &IpfsClient, args: &ArgMatches) -> CommandExecutable; -} - -macro_rules! handle_case { - // Base macro case. Converts an expression into a boxed future. - // - ($run: expr) => { - { - let future = $run; - - return Box::new(future.map_err(|e| eprintln!("{}", e))) - } - }; - // Base case for nested subcommand (e.g. /bootstrap/add). - // - ( - $subcommand: ident; - ($key: pat) => { $(($inner_key: pat, $args: ident) => $run: expr),* } - ) => { - if let ($key, Some(args)) = $subcommand { - let inner_subcommand = args.subcommand(); - - $( - handle_case!(inner_subcommand; ($inner_key, $args) => $run); - )* - } - }; - // Base case for subcommand. - // - ( - $subcommand: ident; - ($key: pat, $args: pat) => $run: expr - ) => { - if let ($key, Some($args)) = $subcommand { - handle_case!($run) - } - }; - // Recursive case for nested subcommand. - // - ( - $subcommand: ident; - ($key: pat) => { $(($inner_key: pat, $args: ident) => $run: expr),* }, - $($rest_args: tt => $rest_run: tt),* - ) => { - handle_case!($subcommand; ($key) => { $(($inner_key, $args) => $run),* }); - - $( - handle_case!($subcommand; $rest_args => $rest_run); - )* - }; - // Recursive case fo subcommand. - // - ( - $subcommand: ident; - ($key: pat, $args: pat) => $run: expr, - $($rest_args: tt => $rest_run: tt),* - ) => { - handle_case!($subcommand; ($key, $args) => $run); - - $( - handle_case!($subcommand; $rest_args => $rest_run); - )* - } -} - -macro_rules! handle { - // Command with no subcommands. - // - ( - ($args: ident, $client: ident) => $run: expr - ) => { - fn handle( - client: &::ipfs_api::IpfsClient, - args: &::clap::ArgMatches, - ) -> crate::command::CommandExecutable { - let $args = args; - let $client = client; - - handle_case!($run) - } - }; - // Command with one or more subcommands. - // - ( - $client: ident; - $($args: tt => $run: tt),* - ) => { - fn handle( - client: &::ipfs_api::IpfsClient, - args: &::clap::ArgMatches, - ) -> crate::command::CommandExecutable { - let $client = client; - let subcommand = args.subcommand(); - - handle_case!(subcommand; $($args => $run),*); - - unreachable!() - } - } -} - -pub mod add; -pub mod bitswap; -pub mod block; -pub mod bootstrap; -pub mod cat; -pub mod commands; -pub mod config; -pub mod dag; -pub mod dht; -pub mod diag; -pub mod dns; -pub mod file; -pub mod files; -pub mod filestore; -pub mod shutdown; -pub mod version; diff --git a/ipfs-cli/src/command/shutdown.rs b/ipfs-cli/src/command/shutdown.rs deleted file mode 100644 index 057ea37..0000000 --- a/ipfs-cli/src/command/shutdown.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "shutdown"; - - fn signature<'a, 'b>() -> App<'a, 'b> { - clap_app!( - @subcommand shutdown => - (about: "Shutdown IPFS daemon") - ) - } - - handle!( - (_args, client) => { - client.shutdown().map(|_| ()) - } - ); -} diff --git a/ipfs-cli/src/command/version.rs b/ipfs-cli/src/command/version.rs deleted file mode 100644 index b4ada31..0000000 --- a/ipfs-cli/src/command/version.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use crate::command::CliCommand; -use clap::App; -use futures::Future; - -pub struct Command; - -impl CliCommand for Command { - const NAME: &'static str = "version"; - - fn signature<'a, 'b>() -> App<'a, 'b> { - clap_app!( - @subcommand version => - (about: "Show ipfs version information") - ) - } - - handle!( - (_args, client) => { - client.version().map(|version| { - println!(); - println!(" version : {}", version.version); - println!(" commit : {}", version.commit); - println!(" repo : {}", version.repo); - println!(" system : {}", version.system); - println!(" golang : {}", version.golang); - println!(); - }) - } - ); -} diff --git a/ipfs-cli/src/main.rs b/ipfs-cli/src/main.rs deleted file mode 100644 index 9bae5e3..0000000 --- a/ipfs-cli/src/main.rs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -#[macro_use] -extern crate clap; - -use crate::command::CliCommand; -use ipfs_api::IpfsClient; - -mod command; - -macro_rules! main { - ($($cmd:ident);*) => { - fn main() { - let matches = clap_app!( - app => - (name: "IPFS CLI") - (about: "CLI for Go IPFS") - (version: crate_version!()) - (author: "Ferris T. ") - (@setting SubcommandRequiredElseHelp) - $((subcommand: ::signature()))* - ).get_matches(); - - let client = IpfsClient::default(); - let command = match matches.subcommand() { - $( - (::NAME, Some(args)) => { - ::handle(&client, args) - } - )* - _ => unreachable!(), - }; - - hyper::rt::run(command); - } - } -} - -main!( - add; - bitswap; block; bootstrap; - cat; commands; config; - dag; dht; diag; dns; - file; files; filestore; - shutdown; - version -); -- cgit v1.2.3