Skip to content

Commit

Permalink
Add --help and --version options
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
wezm committed Feb 1, 2020
1 parent 26a045b commit 14af2ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
extern crate titlecase;

use std::env;
use std::io::{self, BufRead};
use titlecase::titlecase;

fn main() {
let stdin = io::stdin();
match env::args().nth(1).as_ref().map(String::as_str) {
Some("-h") | Some("--help") => return help(),
Some("-v") | Some("--version") => return version(),
Some(option) => return eprintln!("unknown option {}", option),
_ => (),
}

let stdin = io::stdin();
for line in stdin.lock().lines() {
match line {
Ok(line) => println!("{}", titlecase(&line)),
Expand All @@ -15,3 +22,21 @@ fn main() {
}
}
}

fn help() {
println!(
"\
Usage: titlecase [OPTIONS]
titlecase reads lines from stdin and applies title casing rules to each line,
outputting the result on stdout.
Optional arguments:
-h, --help print help message
-v, --version print the version"
);
}

fn version() {
println!("titlecase {}", env!("CARGO_PKG_VERSION"));
}

0 comments on commit 14af2ba

Please sign in to comment.