Iterate over commands in all files
This commit is contained in:
parent
6f49c32e79
commit
bac673ea65
1 changed files with 24 additions and 1 deletions
25
src/files.rs
25
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<PathBuf, LoadedFile>,
|
||||
|
|
@ -124,6 +136,17 @@ impl Files {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn commands(&self) -> Vec<SourcedCommand<'_>> {
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue