Compare commits

..

No commits in common. "7b52fc000ded6e24ce322e71c57616d6d803bdd4" and "2ac18bb6402fee0587594c5640cf0a4e5bb3a2a3" have entirely different histories.

3 changed files with 6 additions and 44 deletions

View file

@ -5,15 +5,11 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
cfg-if = "1.0.0"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
fasteval = "0.2.4" fasteval = "0.2.4"
tinyaudio = { version = "0.1", optional = true } tinyaudio = { version = "0.1", optional = true }
[features] [features]
# default = []
# default = ["save"]
# default = ["play"]
default = ["play", "save"] default = ["play", "save"]
play = ["dep:tinyaudio"] play = ["dep:tinyaudio"]
save = [] save = []

View file

@ -1,54 +1,21 @@
use std::{fs::read_to_string, ops::Deref, path::Path, str::FromStr}; use std::{fs::read_to_string, ops::Deref, path::Path, str::FromStr};
cfg_if! {
if #[cfg(save)] {
use std::path::PathBuf;
}
}
use anyhow::{Context, Error}; use anyhow::{Context, Error};
use cfg_if::cfg_if;
use clap::Parser; use clap::Parser;
#[derive(Parser)] #[derive(Parser)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub(super) struct Args { pub(super) struct Args {
#[arg(short, long, value_parser = Instrument::from_str)] #[arg(short, long, value_parser = Instrument::from_str)]
instrument: Option<Instrument>, instrument: Instrument,
#[cfg(save)]
#[arg(short, long)]
output: Option<PathBuf>,
#[cfg(play)]
#[arg(short, long)]
silent: bool,
score: Score,
} }
#[derive(Clone)] impl Args {
#[cfg_attr(debug_assertions, derive(Debug))] pub(super) fn instrument(&self) -> &<Instrument as Deref>::Target {
pub(super) struct Score(String); &self.instrument
impl FromStr for Score {
type Err = Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let maybe_a_path = Path::new(&value);
Ok(Score(if maybe_a_path.is_file() {
read_to_string(maybe_a_path)
.context("you gave me the path of a real file but reading it is hard!")?
} else {
value.to_owned() // hope it's a good one
}))
}
}
impl Deref for Score {
type Target = <String as Deref>::Target;
fn deref(&self) -> &Self::Target {
&self.0
} }
} }
#[derive(Clone)] #[derive(Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub(super) struct Instrument(String); pub(super) struct Instrument(String);
impl FromStr for Instrument { impl FromStr for Instrument {
@ -59,7 +26,7 @@ impl FromStr for Instrument {
read_to_string(maybe_a_path) read_to_string(maybe_a_path)
.context("you gave me the path of a real file but reading it is hard!")? .context("you gave me the path of a real file but reading it is hard!")?
} else { } else {
value.to_owned() // hope it's a good one value.to_owned() // hope it's good
})) }))
} }
} }

View file

@ -5,7 +5,6 @@ mod cli;
fn main() -> Result<()> { fn main() -> Result<()> {
let args = cli::Args::try_parse()?; let args = cli::Args::try_parse()?;
#[cfg(debug_assertions)] println!("got: {}", args.instrument());
println!("{:?}", args);
Ok(()) Ok(())
} }