diff options
Diffstat (limited to 'yt/src/cli.rs')
-rw-r--r-- | yt/src/cli.rs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/yt/src/cli.rs b/yt/src/cli.rs index 78d8de9..fe85a89 100644 --- a/yt/src/cli.rs +++ b/yt/src/cli.rs @@ -8,7 +8,7 @@ // You should have received a copy of the License along with this program. // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. -use std::path::PathBuf; +use std::{path::PathBuf, str::FromStr}; use anyhow::Context; use bytes::Bytes; @@ -216,14 +216,42 @@ pub struct SharedSelectionCommandArgs { pub title: String, - pub date: NaiveDate, + pub date: OptionalNaiveDate, - pub publisher: String, + pub publisher: OptionalPublisher, pub duration: Duration, pub url: Url, } +#[derive(Clone, Debug, Copy)] +pub struct OptionalNaiveDate { + pub date: Option<NaiveDate>, +} +impl FromStr for OptionalNaiveDate { + type Err = anyhow::Error; + fn from_str(v: &str) -> Result<Self,Self::Err> { + if v == "[No release date]" { + Ok(Self {date: None}) + } else { + Ok(Self {date: Some(NaiveDate::from_str(v)?)}) + } + } +} +#[derive(Clone, Debug)] +pub struct OptionalPublisher { + pub publisher: Option<String>, +} +impl FromStr for OptionalPublisher { + type Err = anyhow::Error; + fn from_str(v: &str) -> Result<Self,Self::Err> { + if v == "[No author]" { + Ok(Self {publisher: None}) + } else { + Ok(Self {publisher: Some(v.to_owned())}) + } + } +} #[derive(Subcommand, Clone, Debug)] // NOTE: Keep this in sync with the [`constants::HELP_STR`] constant. <2024-08-20> |