diff options
Diffstat (limited to 'ipfs-cli')
-rw-r--r-- | ipfs-cli/src/command/add.rs | 14 | ||||
-rw-r--r-- | ipfs-cli/src/command/mod.rs | 3 |
2 files changed, 10 insertions, 7 deletions
diff --git a/ipfs-cli/src/command/add.rs b/ipfs-cli/src/command/add.rs index 4382231..52505ef 100644 --- a/ipfs-cli/src/command/add.rs +++ b/ipfs-cli/src/command/add.rs @@ -7,9 +7,9 @@ // use clap::App; -use command::{verify_file, CliCommand, EXPECTED_FILE}; +use command::{CliCommand, EXPECTED_FILE}; use futures::Future; -use std::fs::File; +use std::path::Path; pub struct Command; @@ -20,17 +20,19 @@ impl CliCommand for Command { clap_app!( @subcommand add => (about: "Add file to IPFS") - (@arg INPUT: +required {verify_file} "File to add") + (@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(); - let file = File::open(path).expect(EXPECTED_FILE); - + if !args.is_present("recursive") && Path::new(path).is_dir() { + panic!(EXPECTED_FILE); + } client - .add(file) + .add_path(path) .map(|response| { println!(); println!(" name : {}", response.name); diff --git a/ipfs-cli/src/command/mod.rs b/ipfs-cli/src/command/mod.rs index 3f6d4b3..969f872 100644 --- a/ipfs-cli/src/command/mod.rs +++ b/ipfs-cli/src/command/mod.rs @@ -6,6 +6,7 @@ // copied, modified, or distributed except according to those terms. // +use std::path::Path; use clap::{App, ArgMatches}; use futures::Future; use ipfs_api::IpfsClient; @@ -18,7 +19,7 @@ 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: String) -> Result<(), String> { +pub fn verify_file<P>(path: P) -> Result<(), String> where P: AsRef<Path> { match fs::metadata(path) { Ok(ref metadata) if metadata.is_file() => Ok(()), Ok(_) => Err("file must not be a directory".into()), |