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/interface/input/handle.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'pkgs/by-name/ts/tskm/src/interface/input') diff --git a/pkgs/by-name/ts/tskm/src/interface/input/handle.rs b/pkgs/by-name/ts/tskm/src/interface/input/handle.rs index 9c39cfef..09827fca 100644 --- a/pkgs/by-name/ts/tskm/src/interface/input/handle.rs +++ b/pkgs/by-name/ts/tskm/src/interface/input/handle.rs @@ -9,6 +9,7 @@ // If not, see . use std::{ + collections::HashSet, fs, process, str::FromStr, thread::{self, sleep}, @@ -43,10 +44,23 @@ pub fn handle(command: InputCommand) -> Result<()> { })?; } } - InputCommand::File { file } => { - let file = fs::read_to_string(file)?; - for line in file.lines() { - let input = Input::from_str(line)?; + InputCommand::File { file, tags } => { + let file = fs::read_to_string(&file) + .with_context(|| format!("Failed to read input file '{}'", file.display()))?; + + let mut tag_set = HashSet::with_capacity(tags.len()); + for tag in tags { + tag_set.insert(tag); + } + + for line in file.lines().map(str::trim) { + if line.is_empty() { + continue; + } + + let mut input = Input::from_str(line)?; + input.tags = input.tags.union(&tag_set).cloned().collect(); + input.commit().with_context(|| { format!("Failed to add input ('{input}') to the input storage.") })?; -- cgit 1.4.1