From 9545aa2e0305ba970380f358eb043cdf13b85ac7 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Mon, 2 Jun 2025 12:42:07 +0200 Subject: pkgs/tskm/cli::input::file: Support adding default tags to file import --- pkgs/by-name/ts/tskm/src/cli.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'pkgs/by-name/ts/tskm/src/cli.rs') diff --git a/pkgs/by-name/ts/tskm/src/cli.rs b/pkgs/by-name/ts/tskm/src/cli.rs index a1dd2d8e..ac8f8ee9 100644 --- a/pkgs/by-name/ts/tskm/src/cli.rs +++ b/pkgs/by-name/ts/tskm/src/cli.rs @@ -16,7 +16,10 @@ use clap_complete::{ArgValueCompleter, CompletionCandidate}; use url::Url; use crate::{ - interface::{input::Input, project::ProjectName}, + interface::{ + input::{Input, Tag}, + project::ProjectName, + }, state, task, }; @@ -153,7 +156,14 @@ pub enum InputCommand { /// Add all URLs in the file as inputs to be categorized. /// /// This expects each line to contain one URL. - File { file: PathBuf }, + File { + /// The file to read from. + file: PathBuf, + + /// Additional tags to apply to every read URL in the file. + #[arg(add = ArgValueCompleter::new(complete_tag))] + tags: Vec, + }, /// Like 'review', but for the inputs that have previously been added. /// It takes a project in which to open the URLs. @@ -272,3 +282,27 @@ fn complete_input_url(current: &OsStr) -> Vec { output } +fn complete_tag(current: &OsStr) -> Vec { + let mut output = vec![]; + + let Some(current) = current.to_str() else { + return output; + }; + + if !current.starts_with('+') { + output.push(CompletionCandidate::new(format!("+{current}"))); + } + + output +} + +#[cfg(test)] +mod test { + use clap::CommandFactory; + + use super::CliArgs; + #[test] + fn verify_cli() { + CliArgs::command().debug_assert(); + } +} -- cgit 1.4.1