aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-10-26 21:37:06 -0700
committerBryan Newbold <bnewbold@robocracy.org>2017-10-26 21:37:06 -0700
commitac9e4183c380dcd7c52e9b8f6e07287982a33aac (patch)
tree3324f429af5f341da4755248eb9826d650034cc6 /src/bin
parent430b278e20aa0a205dd38ec97289830cc0f84187 (diff)
downloadgeniza-ac9e4183c380dcd7c52e9b8f6e07287982a33aac.tar.gz
geniza-ac9e4183c380dcd7c52e9b8f6e07287982a33aac.zip
rustfmt
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/geniza-net.rs53
-rw-r--r--src/bin/geniza-sleep.rs79
2 files changed, 71 insertions, 61 deletions
diff --git a/src/bin/geniza-net.rs b/src/bin/geniza-net.rs
index be4dba0..a3abc61 100644
--- a/src/bin/geniza-net.rs
+++ b/src/bin/geniza-net.rs
@@ -1,10 +1,10 @@
-// Free Software under GPL-3.0, see LICENSE
+// Free Software under GPL-3.0, see LICENSE
// Copyright 2017 Bryan Newbold
-#[macro_use]
-extern crate error_chain;
extern crate clap;
extern crate env_logger;
+#[macro_use]
+extern crate error_chain;
extern crate geniza;
// TODO: more careful import
@@ -12,19 +12,22 @@ use geniza::*;
use clap::{App, SubCommand};
fn run() -> Result<()> {
-
env_logger::init().unwrap();
-
+
let matches = App::new("geniza-net")
.version(env!("CARGO_PKG_VERSION"))
- .subcommand(SubCommand::with_name("connect")
- .about("Connects to a peer and exchanges handshake")
- .arg_from_usage("<host_port> 'peer host:port to connect to'")
- .arg_from_usage("<dat_key> 'dat key (public key) to register with'"))
- .subcommand(SubCommand::with_name("receive-all")
- .about("Connects to a peer, pulls all metadata and content")
- .arg_from_usage("<host_port> 'peer host:port to connect to'")
- .arg_from_usage("<dat_key> 'dat key (public key) to register with'"))
+ .subcommand(
+ SubCommand::with_name("connect")
+ .about("Connects to a peer and exchanges handshake")
+ .arg_from_usage("<host_port> 'peer host:port to connect to'")
+ .arg_from_usage("<dat_key> 'dat key (public key) to register with'"),
+ )
+ .subcommand(
+ SubCommand::with_name("receive-all")
+ .about("Connects to a peer, pulls all metadata and content")
+ .arg_from_usage("<host_port> 'peer host:port to connect to'")
+ .arg_from_usage("<dat_key> 'dat key (public key) to register with'"),
+ )
.get_matches();
@@ -32,51 +35,45 @@ fn run() -> Result<()> {
("connect", Some(subm)) => {
let host_port = subm.value_of("host_port").unwrap();
let dat_key = subm.value_of("dat_key").unwrap();
- if dat_key.len() != 32*2 {
+ if dat_key.len() != 32 * 2 {
bail!("dat key not correct length");
}
let mut key_bytes = vec![];
for i in 0..32 {
- let r = u8::from_str_radix(&dat_key[2*i .. 2*i+2], 16);
+ let r = u8::from_str_radix(&dat_key[2 * i..2 * i + 2], 16);
match r {
Ok(b) => key_bytes.push(b),
Err(e) => bail!("Problem with hex: {}", e),
};
}
- DatConnection::connect(
- host_port,
- &key_bytes,
- false)?;
+ DatConnection::connect(host_port, &key_bytes, false)?;
println!("Done!");
- },
+ }
("receive-all", Some(subm)) => {
let host_port = subm.value_of("host_port").unwrap();
let dat_key = subm.value_of("dat_key").unwrap();
- if dat_key.len() != 32*2 {
+ if dat_key.len() != 32 * 2 {
bail!("dat key not correct length");
}
let mut key_bytes = vec![];
for i in 0..32 {
- let r = u8::from_str_radix(&dat_key[2*i .. 2*i+2], 16);
+ let r = u8::from_str_radix(&dat_key[2 * i..2 * i + 2], 16);
match r {
Ok(b) => key_bytes.push(b),
Err(e) => bail!("Problem with hex: {}", e),
};
}
- let mut dc = DatConnection::connect(
- host_port,
- &key_bytes,
- false)?;
+ let mut dc = DatConnection::connect(host_port, &key_bytes, false)?;
// XXX: number here totally arbitrary
dc.receive_all(false, 10)?;
dc.receive_all(true, 10)?;
println!("Done!");
- },
+ }
_ => {
println!("Missing or unimplemented command!");
println!("{}", matches.usage());
::std::process::exit(-1);
- },
+ }
}
Ok(())
}
diff --git a/src/bin/geniza-sleep.rs b/src/bin/geniza-sleep.rs
index 461df0d..1a50d17 100644
--- a/src/bin/geniza-sleep.rs
+++ b/src/bin/geniza-sleep.rs
@@ -1,11 +1,11 @@
-// Free Software under GPL-3.0, see LICENSE
+// Free Software under GPL-3.0, see LICENSE
// Copyright 2017 Bryan Newbold
#[macro_use]
-extern crate error_chain;
-#[macro_use]
extern crate clap;
extern crate env_logger;
+#[macro_use]
+extern crate error_chain;
extern crate geniza;
// TODO: more careful import
@@ -14,31 +14,40 @@ use std::path::Path;
use clap::{App, SubCommand};
fn run() -> Result<()> {
-
env_logger::init().unwrap();
-
+
let matches = App::new("geniza-sleep")
.version(env!("CARGO_PKG_VERSION"))
- .subcommand(SubCommand::with_name("info")
- .about("Reads a SLEEP dir register and shows some basic metadata")
- .arg_from_usage("<DIR> 'directory containing files'")
- .arg_from_usage("<prefix> 'prefix for each data file'"))
- .subcommand(SubCommand::with_name("create")
- .about("Creates an SLEEP directory register (with header)")
- .arg_from_usage("<DIR> 'directory containing files'")
- .arg_from_usage("<prefix> 'prefix for each data file'"))
- .subcommand(SubCommand::with_name("file-info")
- .about("Reads a single SLEEP file and shows some basic metadata")
- .arg_from_usage("<FILE> 'SLEEP file to read'"))
- .subcommand(SubCommand::with_name("file-create")
- .about("Creates an empty single SLEEP file (with header)")
- .arg_from_usage("<FILE> 'SLEEP file to write (can't exist)'")
- .arg_from_usage("<magic> 'Magic word to use (eg, 0x5025700)'")
- .arg_from_usage("<entry_size> 'Size of each entry (bytes)'")
- .arg_from_usage("<algo_name> 'Name of algorithm (empty string for none)'"))
- .subcommand(SubCommand::with_name("read-all")
- .about("Reads a single SLEEP file, iterates through all entries, prints raw bytes")
- .arg_from_usage("<FILE> 'SLEEP file to read'"))
+ .subcommand(
+ SubCommand::with_name("info")
+ .about("Reads a SLEEP dir register and shows some basic metadata")
+ .arg_from_usage("<DIR> 'directory containing files'")
+ .arg_from_usage("<prefix> 'prefix for each data file'"),
+ )
+ .subcommand(
+ SubCommand::with_name("create")
+ .about("Creates an SLEEP directory register (with header)")
+ .arg_from_usage("<DIR> 'directory containing files'")
+ .arg_from_usage("<prefix> 'prefix for each data file'"),
+ )
+ .subcommand(
+ SubCommand::with_name("file-info")
+ .about("Reads a single SLEEP file and shows some basic metadata")
+ .arg_from_usage("<FILE> 'SLEEP file to read'"),
+ )
+ .subcommand(
+ SubCommand::with_name("file-create")
+ .about("Creates an empty single SLEEP file (with header)")
+ .arg_from_usage("<FILE> 'SLEEP file to write (can't exist)'")
+ .arg_from_usage("<magic> 'Magic word to use (eg, 0x5025700)'")
+ .arg_from_usage("<entry_size> 'Size of each entry (bytes)'")
+ .arg_from_usage("<algo_name> 'Name of algorithm (empty string for none)'"),
+ )
+ .subcommand(
+ SubCommand::with_name("read-all")
+ .about("Reads a single SLEEP file, iterates through all entries, prints raw bytes")
+ .arg_from_usage("<FILE> 'SLEEP file to read'"),
+ )
.get_matches();
@@ -50,22 +59,25 @@ fn run() -> Result<()> {
//debug!(println!("{:?}", sdr));
println!("Entry count: {}", sdr.len()?);
println!("Total size (bytes): {}", sdr.len_bytes()?);
- },
+ }
("create", Some(subm)) => {
let dir = Path::new(subm.value_of("DIR").unwrap());
let prefix = subm.value_of("prefix").unwrap();
SleepDirRegister::create(dir, prefix)?;
println!("Done!");
- },
+ }
("file-info", Some(subm)) => {
let path = Path::new(subm.value_of("FILE").unwrap());
let sf = SleepFile::open(path, false)?;
//debug!(println!("{:?}", sf));
println!("Magic: 0x{:X}", sf.get_magic());
- println!("Algorithm: '{}'", sf.get_algorithm().or(Some("".to_string())).unwrap());
+ println!(
+ "Algorithm: '{}'",
+ sf.get_algorithm().or(Some("".to_string())).unwrap()
+ );
println!("Entry Size (bytes): {}", sf.get_entry_size());
println!("Entry count: {}", sf.len()?);
- },
+ }
("file-create", Some(subm)) => {
let path = Path::new(subm.value_of("FILE").unwrap());
let algo_name = subm.value_of("algo_name").unwrap();
@@ -78,21 +90,22 @@ fn run() -> Result<()> {
path,
value_t_or_exit!(subm, "magic", u32),
value_t_or_exit!(subm, "entry_size", u16),
- algo_name)?;
+ algo_name,
+ )?;
println!("Done!");
- },
+ }
("file-read-all", Some(subm)) => {
let path = Path::new(subm.value_of("FILE").unwrap());
let mut sf = SleepFile::open(path, false)?;
for i in 0..sf.len()? {
println!("{}: {:?}", i, sf.read(i));
}
- },
+ }
_ => {
println!("Missing or unimplemented command!");
println!("{}", matches.usage());
::std::process::exit(-1);
- },
+ }
}
Ok(())
}