From c944db2ab71ddd3ee2f38e46b6d7f3944d8ed470 Mon Sep 17 00:00:00 2001 From: p6nj Date: Mon, 2 Sep 2024 22:04:05 -0400 Subject: [PATCH] cli files dispatch --- src/cli.rs | 56 +++++-------------------------------------- src/cli/instrument.rs | 21 ++++++++++++++++ src/cli/score.rs | 21 ++++++++++++++++ 3 files changed, 48 insertions(+), 50 deletions(-) create mode 100644 src/cli/instrument.rs create mode 100644 src/cli/score.rs diff --git a/src/cli.rs b/src/cli.rs index ea8bb94..bc5587c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,14 +1,18 @@ -use std::{fs::read_to_string, ops::Deref, path::Path, str::FromStr}; +use std::str::FromStr; cfg_if! { if #[cfg(feature = "save")] { use std::path::PathBuf; } } -use anyhow::{Context, Error}; use cfg_if::cfg_if; use clap::Parser; +mod instrument; +mod score; +pub use instrument::Instrument; +pub use score::Score; + #[derive(Parser)] #[cfg_attr(debug_assertions, derive(Debug))] pub(super) struct Args { @@ -22,51 +26,3 @@ pub(super) struct Args { silent: bool, score: Score, } - -#[derive(Clone)] -#[cfg_attr(debug_assertions, derive(Debug))] -pub(super) struct Score(String); - -impl FromStr for Score { - type Err = Error; - fn from_str(value: &str) -> Result { - 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 = ::Target; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -#[derive(Clone)] -#[cfg_attr(debug_assertions, derive(Debug))] -pub(super) struct Instrument(String); - -impl FromStr for Instrument { - type Err = Error; - fn from_str(value: &str) -> Result { - let maybe_a_path = Path::new(&value); - Ok(Instrument(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 Instrument { - type Target = ::Target; - fn deref(&self) -> &Self::Target { - &self.0 - } -} diff --git a/src/cli/instrument.rs b/src/cli/instrument.rs new file mode 100644 index 0000000..c9bfe64 --- /dev/null +++ b/src/cli/instrument.rs @@ -0,0 +1,21 @@ +use std::{fs::read_to_string, path::Path, str::FromStr}; + +use anyhow::{Context, Error}; +use derived_deref::Deref; + +#[derive(Clone, Deref)] +#[cfg_attr(debug_assertions, derive(Debug))] +pub struct Instrument(String); + +impl FromStr for Instrument { + type Err = Error; + fn from_str(value: &str) -> Result { + let maybe_a_path = Path::new(&value); + Ok(Instrument(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 + })) + } +} diff --git a/src/cli/score.rs b/src/cli/score.rs new file mode 100644 index 0000000..a1fac87 --- /dev/null +++ b/src/cli/score.rs @@ -0,0 +1,21 @@ +use std::{fs::read_to_string, path::Path, str::FromStr}; + +use anyhow::{Context, Error}; +use derived_deref::Deref; + +#[derive(Clone, Deref)] +#[cfg_attr(debug_assertions, derive(Debug))] +pub struct Score(String); + +impl FromStr for Score { + type Err = Error; + fn from_str(value: &str) -> Result { + 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 + })) + } +}