From ceb0ff290707905af56106401b3f2a326971c505 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 14 Feb 2025 16:31:19 +0100 Subject: fix(yt/cli): Make most of the arguments to `yt select ` optional In most cases `yt select watch ` is enough, but the previous cli specification required you to insert: `[TITLE] [DATE] [PUBLISHER] [DURATION] [URL]`. These are not used (except the `url` command), and thus the cli usage can be greatly improved by allowing the to be empty. --- yt/src/cli.rs | 10 +++++----- yt/src/select/cmds/mod.rs | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/yt/src/cli.rs b/yt/src/cli.rs index b110772..e95b93f 100644 --- a/yt/src/cli.rs +++ b/yt/src/cli.rs @@ -218,15 +218,15 @@ pub struct SharedSelectionCommandArgs { /// The short extractor hash pub hash: LazyExtractorHash, - pub title: String, + pub title: Option, - pub date: OptionalNaiveDate, + pub date: Option, - pub publisher: OptionalPublisher, + pub publisher: Option, - pub duration: Duration, + pub duration: Option, - pub url: Url, + pub url: Option, } #[derive(Clone, Debug, Copy)] pub struct OptionalNaiveDate { diff --git a/yt/src/select/cmds/mod.rs b/yt/src/select/cmds/mod.rs index f576241..105569b 100644 --- a/yt/src/select/cmds/mod.rs +++ b/yt/src/select/cmds/mod.rs @@ -18,7 +18,7 @@ use crate::{ }, }; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; mod add; @@ -50,9 +50,13 @@ pub async fn handle_select_cmd( } SelectCommand::Url { shared } => { + let Some(url) = shared.url else { + bail!("You need to provide a url to `select url ..`") + }; + let mut firefox = std::process::Command::new("firefox"); firefox.args(["-P", "timesinks.youtube"]); - firefox.arg(shared.url.as_str()); + firefox.arg(url.as_str()); let _handle = firefox.spawn().context("Failed to run firefox")?; } SelectCommand::File { .. } => unreachable!("This should have been filtered out"), -- cgit 1.4.1