summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-26 13:08:25 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-26 13:08:25 -0500
commit812aab56d2273648f9b5c8468540d4f43de01364 (patch)
tree06d0b8f18e1012bd1da6394e0155c53268fabfc3
parentedcf3de74d9e0b26fe38b4989b6d73395cf8605e (diff)
add cli commands for dns and file
-rw-r--r--ipfs-cli/src/command/dns.rs33
-rw-r--r--ipfs-cli/src/command/file.rs61
-rw-r--r--ipfs-cli/src/command/mod.rs2
-rw-r--r--ipfs-cli/src/main.rs4
4 files changed, 100 insertions, 0 deletions
diff --git a/ipfs-cli/src/command/dns.rs b/ipfs-cli/src/command/dns.rs
new file mode 100644
index 0000000..e9ab0fa
--- /dev/null
+++ b/ipfs-cli/src/command/dns.rs
@@ -0,0 +1,33 @@
+// 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::EXPECTED_API;
+use ipfs_api::IpfsClient;
+use tokio_core::reactor::Core;
+
+
+pub 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")
+ )
+}
+
+
+pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
+ let path = args.value_of("PATH").unwrap();
+ let req = client.dns(&path, args.is_present("recursive"));
+ let res = core.run(req).expect(EXPECTED_API);
+
+ println!("");
+ println!(" path : {}", res.path);
+ println!("");
+}
diff --git a/ipfs-cli/src/command/file.rs b/ipfs-cli/src/command/file.rs
new file mode 100644
index 0000000..4235534
--- /dev/null
+++ b/ipfs-cli/src/command/file.rs
@@ -0,0 +1,61 @@
+// 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::EXPECTED_API;
+use ipfs_api::IpfsClient;
+use tokio_core::reactor::Core;
+
+
+pub 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")
+ )
+ )
+}
+
+
+pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
+ match args.subcommand() {
+ ("ls", Some(args)) => {
+ let path = args.value_of("PATH").unwrap();
+ let ls = core.run(client.file_ls(&path)).expect(EXPECTED_API);
+
+ println!("");
+ println!(" arguments :");
+ for (k, arg) in ls.arguments.iter() {
+ println!(" arg : {}", k);
+ println!(" value : {}", arg);
+ println!("");
+ }
+ println!(" objects :");
+ for (k, obj) in ls.objects.iter() {
+ println!(" key : {}", k);
+ println!(" hash : {}", obj.hash);
+ println!(" size : {}", obj.size);
+ println!(" type : {}", obj.typ);
+ println!(" links :");
+ for link in obj.links.iter() {
+ println!(" name : {}", link.name);
+ println!(" hash : {}", link.hash);
+ println!(" size : {}", link.size);
+ if let Some(ref typ) = link.typ {
+ println!(" type : {}", typ);
+ }
+ println!("");
+ }
+ }
+ println!("");
+ }
+ _ => unreachable!(),
+ }
+}
diff --git a/ipfs-cli/src/command/mod.rs b/ipfs-cli/src/command/mod.rs
index 11df651..208a89f 100644
--- a/ipfs-cli/src/command/mod.rs
+++ b/ipfs-cli/src/command/mod.rs
@@ -35,4 +35,6 @@ pub mod config;
pub mod dag;
pub mod dht;
pub mod diag;
+pub mod dns;
+pub mod file;
pub mod version;
diff --git a/ipfs-cli/src/main.rs b/ipfs-cli/src/main.rs
index a096bc8..1b485ed 100644
--- a/ipfs-cli/src/main.rs
+++ b/ipfs-cli/src/main.rs
@@ -35,6 +35,8 @@ fn main() {
(subcommand: command::dag::signature())
(subcommand: command::dht::signature())
(subcommand: command::diag::signature())
+ (subcommand: command::dns::signature())
+ (subcommand: command::file::signature())
(subcommand: command::version::signature())
).get_matches();
@@ -52,6 +54,8 @@ fn main() {
("dag", Some(args)) => command::dag::handle(&mut core, &client, &args),
("dht", Some(args)) => command::dht::handle(&mut core, &client, &args),
("diag", Some(args)) => command::diag::handle(&mut core, &client, &args),
+ ("dns", Some(args)) => command::dns::handle(&mut core, &client, &args),
+ ("file", Some(args)) => command::file::handle(&mut core, &client, &args),
("version", _) => command::version::handle(&mut core, &client),
_ => unreachable!(),
}