···23// cargo-deps: argh = "0.1", cidr = "0.2.1"
45-use argh::FromArgs;
6-use cidr::IpCidr;
7-8use std::net::IpAddr;
9use std::str::FromStr;
0001011#[derive(FromArgs)]
12#[argh(description = "Display the ip range for a CIDR and check if an ip falls within.")]
···18 )]
19 ip: Option<IpAddr>,
2021- #[argh(
22- positional,
23- description = "CIDR to inspect",
24- from_str_fn(parse_cidr)
25- )]
26 cidr: IpCidr,
27}
2829fn main() {
30 let App { ip, cidr } = argh::from_env();
31 println!(
32- "CIDR {} has a range of: {} to {}",
33- cidr,
34- cidr.first_address(),
35 cidr.last_address()
36 );
3738 println!("CIDR {} has a netmask of {}", cidr, cidr.mask());
39-40 if let Some(ip) = ip {
41 print!("IP {}", ip);
42 let falls_within = cidr.contains(&ip);
···46 print!(" does not fall ");
47 }
4849- println!("within {}", cidr);
50 }
51}
52
···23// cargo-deps: argh = "0.1", cidr = "0.2.1"
40005use std::net::IpAddr;
6use std::str::FromStr;
7+8+use argh::FromArgs;
9+use cidr::IpCidr;
1011#[derive(FromArgs)]
12#[argh(description = "Display the ip range for a CIDR and check if an ip falls within.")]
···18 )]
19 ip: Option<IpAddr>,
2021+ #[argh(positional, description = "CIDR to inspect", from_str_fn(parse_cidr))]
000022 cidr: IpCidr,
23}
2425fn main() {
26 let App { ip, cidr } = argh::from_env();
27 println!(
28+ "CIDR {} has a range of: {} to {}",
29+ cidr,
30+ cidr.first_address(),
31 cidr.last_address()
32 );
3334 println!("CIDR {} has a netmask of {}", cidr, cidr.mask());
35+36 if let Some(ip) = ip {
37 print!("IP {}", ip);
38 let falls_within = cidr.contains(&ip);
···42 print!(" does not fall ");
43 }
4445+ println!("within {}", cidr);
46 }
47}
48
+8-9
dbg_server
···23// cargo-deps: argh = "0.1"
45-use argh::FromArgs;
6-7use std::net::TcpListener;
8-use std::io::BufRead;
9-use std::io::BufReader;
10use std::str;
001112#[derive(FromArgs)]
13#[argh(description = "simple debug server which logs the data sent to it.")]
···35 let stream = stream.expect("stream should be present");
36 let mut stream = BufReader::new(stream);
3738- // This is not the "best" way to get the data sent over
39- // but it sure is the easiest :^)
40- let data = stream.fill_buf().expect("should have data");
41- let output = str::from_utf8(data).expect("should be able to parse data as text");
42- println!("{}", output);
43 }
44}
···23// cargo-deps: argh = "0.1"
45+use std::io::{BufRead, BufReader};
06use std::net::TcpListener;
007use std::str;
8+9+use argh::FromArgs;
1011#[derive(FromArgs)]
12#[argh(description = "simple debug server which logs the data sent to it.")]
···34 let stream = stream.expect("stream should be present");
35 let mut stream = BufReader::new(stream);
3637+ // This is not the "best" way to get the data sent over
38+ // but it sure is the easiest :^)
39+ let data = stream.fill_buf().expect("should have data");
40+ let output = str::from_utf8(data).expect("should be able to parse data as text");
41+ println!("{}", output);
42 }
43}
···23// cargo-deps: argh = "0.1"
40005use argh::FromArgs;
6-7-use std::net::Shutdown;
8-use std::net::TcpStream;
9-use std::io::BufRead;
10-use std::io::BufReader;
11-use std::io::Write;
1213const FLUSH_COMMAND: &str = "FLUSHALL\r\n";
14···32 let address = format!("{}:{}", app.host, app.port);
33 let mut stream = TcpStream::connect(address).expect("should be able to connect to redis");
3435- stream.write(FLUSH_COMMAND.as_bytes()).expect("should be able to write flush command");
36- stream.flush().expect("should be able to send flush command");
37- stream.shutdown(Shutdown::Write).expect("should be able to shutdown writer");
0000003839 let mut stream = BufReader::new(stream);
4041 let mut output = String::new();
42- let _ = stream.read_line(&mut output).expect("should be able to read response");
0043 println!("{}", &output);
44}
···23// cargo-deps: argh = "0.1"
45+use std::io::{BufRead, BufReader, Write};
6+use std::net::{Shutdown, TcpStream};
7+8use argh::FromArgs;
000000910const FLUSH_COMMAND: &str = "FLUSHALL\r\n";
11···29 let address = format!("{}:{}", app.host, app.port);
30 let mut stream = TcpStream::connect(address).expect("should be able to connect to redis");
3132+ stream
33+ .write(FLUSH_COMMAND.as_bytes())
34+ .expect("should be able to write flush command");
35+ stream
36+ .flush()
37+ .expect("should be able to send flush command");
38+ stream
39+ .shutdown(Shutdown::Write)
40+ .expect("should be able to shutdown writer");
4142 let mut stream = BufReader::new(stream);
4344 let mut output = String::new();
45+ let _ = stream
46+ .read_line(&mut output)
47+ .expect("should be able to read response");
48 println!("{}", &output);
49}
···23// cargo-deps: argh = "0.1"
45-use argh::FromArgs;
6-7use std::process::{self, Command};
0089#[derive(FromArgs)]
10#[argh(description = "Simple program to kill a process listening on a specific port.")]
···23// cargo-deps: argh = "0.1"
4005use std::process::{self, Command};
6+7+use argh::FromArgs;
89#[derive(FromArgs)]
10#[argh(description = "Simple program to kill a process listening on a specific port.")]
···23// cargo-deps: argh = "0.1", humantime = "2.1.0"
45-use argh::FromArgs;
6-7use std::thread;
8use std::time::{Duration, Instant};
00910#[derive(FromArgs)]
11#[argh(description = "Keep track of how long a task runs or set a timer for some period of time.")]
···23// cargo-deps: argh = "0.1", humantime = "2.1.0"
4005use std::thread;
6use std::time::{Duration, Instant};
7+8+use argh::FromArgs;
910#[derive(FromArgs)]
11#[argh(description = "Keep track of how long a task runs or set a timer for some period of time.")]
···19fn main() {
20 let app: App = argh::from_env();
2122-23- let tag = Utc::now().format(&app.format).to_string();
2425 println!("# Run the following to tag and release this version");
26 println!();
···19fn main() {
20 let app: App = argh::from_env();
2122+ let tag = Utc::now().format(&app.format).to_string();
02324 println!("# Run the following to tag and release this version");
25 println!();