~kf5jwc/callpass-rs

f8493e005176cd66399c06aedad856d950ab26c2 — Kyle Jones 1 year, 1 month ago a5e5f4e v1.0.1
Add the callpass binary
2 files changed, 53 insertions(+), 3 deletions(-)

M Cargo.toml
A src/bin/callpass.rs
M Cargo.toml => Cargo.toml +11 -3
@@ 1,17 1,25 @@
[package]
name = "callpass"
description = "Generate APRS passcodes"
version = "1.0.0"
version = "1.0.1"
authors = ["Kyle Jones <kyle@kf5jwc.us>"]
keywords = ["APRS-IS", "APRS", "amateur", "ham", "radio"]
category = ["algorithms", "data-structures"]
repository = "https://git.kf5jwc.us/kyle/callpass"
license = "GPL-2.0"
epoch = 2019
edition = "2018"

[features]
default = ["std"]
default = ["std", "tools"]
std = []
tools = ["docopt", "serde", "serde_derive"]

[dependencies]
ascii = "0.9.*"
docopt = { version = "^0.8", optional = true }
serde = { version = "^1.0", optional = true }
serde_derive = { version = "^1.0", optional = true }

[[bin]]
name = "callpass"
required-features = ["std", "tools"]

A src/bin/callpass.rs => src/bin/callpass.rs +42 -0
@@ 0,0 1,42 @@
extern crate callpass;
extern crate serde_derive;
extern crate docopt;

use callpass::Callpass;
use serde_derive::Deserialize;
use docopt::Docopt;

const USAGE: &'static str = "
Usage:
    callpass [--verbose] <callsign>...

Options:
    --verbose, -v   Include the callsign after the callpass
";

#[derive(Deserialize)]
struct Args {
    arg_callsign: Vec<String>,
    flag_verbose: bool,
}

pub fn main() {
    let args: Args = Docopt::new(USAGE)
        .and_then(|d| d.deserialize())
        .unwrap_or_else(|e| e.exit());
    for callsign in args.arg_callsign {
        let callpass: Callpass = (&callsign).into();
        show(&callsign, &callpass, &args.flag_verbose)
    }
}

fn show(callsign: &String, callpass: &Callpass, verbose: &bool) {
    match *verbose {
        false => {
            println!("{}", callpass);
        }
        true => {
            println!("{} {}", callpass, callsign);
        }
    }
}