summaryrefslogtreecommitdiffstats
path: root/ipfs-cli/src/command/add.rs
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-24 23:13:55 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-24 23:13:55 -0500
commitfeb3931bd8ebc073e254fed0de966e71a668f71b (patch)
treeccc4b777b4fc2873f3cabc2c5064bc6ff3f80548 /ipfs-cli/src/command/add.rs
parentdcd6f22f7c21ee8985e5de7f962818ac93bc5b26 (diff)
refactoring and new calls
Diffstat (limited to 'ipfs-cli/src/command/add.rs')
-rw-r--r--ipfs-cli/src/command/add.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/ipfs-cli/src/command/add.rs b/ipfs-cli/src/command/add.rs
new file mode 100644
index 0000000..cc5c5e6
--- /dev/null
+++ b/ipfs-cli/src/command/add.rs
@@ -0,0 +1,35 @@
+// 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::{verify_file, EXPECTED_API};
+use ipfs_api::IpfsClient;
+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 fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
+ let path = args.value_of("INPUT").unwrap();
+ let file = File::open(path).expect("expected to read input file");
+ let response = core.run(client.add(file)).expect(EXPECTED_API);
+
+ println!("");
+ println!(" name : {}", response.name);
+ println!(" hash : {}", response.hash);
+ println!(" size : {}", response.size);
+ println!("");
+}