Switch from structopt to clap to reduce dependencies.
This commit is contained in:
parent
269c60fde0
commit
e76e1de3a3
4 changed files with 112 additions and 33 deletions
|
|
@ -3,30 +3,54 @@
|
|||
//! The input data is recorded to "$CARGO_MANIFEST_DIR/recorded.wav".
|
||||
|
||||
extern crate anyhow;
|
||||
extern crate clap;
|
||||
extern crate cpal;
|
||||
extern crate hound;
|
||||
extern crate structopt;
|
||||
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "beep", about = "Simple example of audio playback.")]
|
||||
#[derive(Debug)]
|
||||
struct Opt {
|
||||
#[cfg(all(
|
||||
any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"),
|
||||
feature = "jack"
|
||||
))]
|
||||
#[structopt(short, long)]
|
||||
jack: bool,
|
||||
|
||||
#[structopt(default_value = "default")]
|
||||
device: String,
|
||||
}
|
||||
|
||||
impl Opt {
|
||||
fn from_args() -> Self {
|
||||
let app = clap::App::new("beep").arg_from_usage("[DEVICE] 'The audio device to use'");
|
||||
#[cfg(all(
|
||||
any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"),
|
||||
feature = "jack"
|
||||
))]
|
||||
let app = app.arg_from_usage("-j, --jack 'Use the JACK host");
|
||||
let matches = app.get_matches();
|
||||
let device = matches.value_of("DEVICE").unwrap_or("default").to_string();
|
||||
|
||||
#[cfg(all(
|
||||
any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"),
|
||||
feature = "jack"
|
||||
))]
|
||||
return Opt {
|
||||
jack: matches.is_present("jack"),
|
||||
device,
|
||||
};
|
||||
|
||||
#[cfg(any(
|
||||
not(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd")),
|
||||
not(feature = "jack")
|
||||
))]
|
||||
Opt { device }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue