From 004005688eff68d12043cc388146af30819f4b00 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 20 Dec 2018 15:11:17 +0100 Subject: Use clap for command line parsing. --- src/main.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 0c7e74d..063db5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use clap::{self, crate_name, crate_authors, crate_version, crate_description}; use hound; use std::io::Read; use std::iter::FromIterator; @@ -79,7 +80,26 @@ fn print_wavspec(spec: &hound::WavSpec, r: &hound::WavReader) { } fn main() { - let filename = "test.wav"; + let m = clap::app_from_crate!() + .arg(clap::Arg::with_name("sample") + .short("s") + .long("sample") + .value_name("SAMPLE_FILE") + .help("The sample to replace when trigged.") + .takes_value(true) + .required(true)) + .arg(clap::Arg::with_name("output") + .short("o") + .long("output") + .value_name("OUTPUT_FILE") + .help("Where to store the result.") + .takes_value(true)) + .arg(clap::Arg::with_name("INPUT") + .help("The input file") + .required(true)) + .get_matches(); + + let filename = m.value_of("INPUT").unwrap(); let mut reader = hound::WavReader::open(&filename).unwrap(); println!("Reading file {}:", &filename); @@ -87,13 +107,15 @@ fn main() { let spec = reader.spec(); print_wavspec(&spec, &reader); - println!("Using sample file: {}", "bd.wav"); - let mut sample_file = hound::WavReader::open("bd.wav").unwrap(); + let sample_filename = m.value_of("sample").unwrap(); + println!("Using sample file: {}", sample_filename); + let mut sample_file = hound::WavReader::open(sample_filename).unwrap(); print_wavspec(&sample_file.spec(), &sample_file); - println!("Writing to output: {}", "output.wav"); - let mut output = hound::WavWriter::create("output.wav", spec).unwrap(); + let output_filename = m.value_of("output").unwrap_or("output.wav"); + println!("Writing to output: {}", output_filename); + let mut output = hound::WavWriter::create(output_filename, spec).unwrap(); let samples = reader.samples::(); let mut triggey = Trigger::new(sample_file); -- cgit v1.2.3