aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ts/tskm/src/interface
diff options
context:
space:
mode:
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.")
})?;