diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-12-20 15:11:17 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-12-20 15:11:17 +0100 |
commit | 004005688eff68d12043cc388146af30819f4b00 (patch) | |
tree | a44fbb7c312a5340d1a118be2627245a6e84dcfa /src | |
parent | fc5877b7b8095a6ec0bb11eba2cd16c2ce5e2feb (diff) | |
download | trriggy-004005688eff68d12043cc388146af30819f4b00.tar.gz trriggy-004005688eff68d12043cc388146af30819f4b00.tar.bz2 trriggy-004005688eff68d12043cc388146af30819f4b00.zip |
Use clap for command line parsing.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 32 |
1 files changed, 27 insertions, 5 deletions
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 <https://www.gnu.org/licenses/>. +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<R: Read>(spec: &hound::WavSpec, r: &hound::WavReader<R>) { } 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::<i16>(); let mut triggey = Trigger::new(sample_file); |