aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ts/tskm/src/interface
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-02 12:42:07 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-02 12:42:49 +0200
commit9545aa2e0305ba970380f358eb043cdf13b85ac7 (patch)
tree9d723121172b9cf41aa654a4fd3fe162778e14fd /pkgs/by-name/ts/tskm/src/interface
parentpkgs/tskm/input/handle: Use types to contain parsing and dry code (diff)
downloadnixos-config-9545aa2e0305ba970380f358eb043cdf13b85ac7.zip
pkgs/tskm/cli::input::file: Support adding default tags to file import
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/interface')
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/input/handle.rs22
1 files changed, 18 insertions, 4 deletions
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 <https://www.gnu.org/licenses/gpl-3.0.txt>.
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.")
})?;