From bac673ea65c9f2f69d863e06fda98064ac7af2ca Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 22 Nov 2021 15:22:06 +0000 Subject: [PATCH] Iterate over commands in all files --- src/files.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/files.rs b/src/files.rs index addce9d..400a64d 100644 --- a/src/files.rs +++ b/src/files.rs @@ -5,7 +5,7 @@ use std::{fs, io, result}; use chrono::{DateTime, Utc}; use tzfile::Tz; -use self::commands::File; +use self::commands::{Command, File}; pub mod commands; mod format; @@ -23,6 +23,18 @@ impl LoadedFile { } } +#[derive(Debug)] +pub struct Source<'a> { + file: &'a Path, + index: usize, +} + +#[derive(Debug)] +pub struct SourcedCommand<'a> { + pub source: Source<'a>, + pub command: &'a Command, +} + #[derive(Debug)] pub struct Files { files: HashMap, @@ -124,6 +136,17 @@ impl Files { } } + pub fn commands(&self) -> Vec> { + let mut result = vec![]; + for (path, file) in &self.files { + for (index, command) in file.file.commands.iter().enumerate() { + let source = Source { file: path, index }; + result.push(SourcedCommand { source, command }); + } + } + result + } + pub fn now(&self) -> DateTime<&Tz> { Utc::now().with_timezone(&&self.timezone) }