Specify default capture file
This commit is contained in:
parent
039b7b73ee
commit
0b4f614af6
7 changed files with 70 additions and 6 deletions
33
src/files.rs
33
src/files.rs
|
|
@ -85,6 +85,7 @@ pub struct Files {
|
|||
/// Codespan-reporting file database.
|
||||
cs_files: SimpleFiles<String, String>,
|
||||
timezone: Option<Tz>,
|
||||
capture: Option<usize>,
|
||||
logs: HashMap<NaiveDate, Source>,
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +133,7 @@ impl Files {
|
|||
files: vec![],
|
||||
cs_files: SimpleFiles::new(),
|
||||
timezone: None,
|
||||
capture: None,
|
||||
logs: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -155,6 +157,7 @@ impl Files {
|
|||
|
||||
self.load_file(&mut loaded, path)?;
|
||||
self.determine_timezone()?;
|
||||
self.determine_capture()?;
|
||||
self.collect_logs()?;
|
||||
|
||||
Ok(())
|
||||
|
|
@ -257,6 +260,32 @@ impl Files {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn determine_capture(&mut self) -> Result<()> {
|
||||
assert_eq!(self.capture, None);
|
||||
|
||||
let mut found: Option<Source> = None;
|
||||
|
||||
for command in self.commands() {
|
||||
if let Command::Capture = &command.value.value {
|
||||
if let Some(found) = &found {
|
||||
let found_cmd = self.command(*found);
|
||||
return Err(Error::MultipleCapture {
|
||||
file1: found.file(),
|
||||
span1: found_cmd.value.span,
|
||||
file2: command.source.file(),
|
||||
span2: command.value.span,
|
||||
});
|
||||
} else {
|
||||
found = Some(command.source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.capture = found.map(|s| s.file);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect_logs(&mut self) -> Result<()> {
|
||||
for command in Self::commands_of_files(&self.files) {
|
||||
if let Command::Log(log) = &command.value.value {
|
||||
|
|
@ -369,6 +398,10 @@ impl Files {
|
|||
.max_by_key(|(d, _)| *d)
|
||||
}
|
||||
|
||||
pub fn capture(&self) -> Option<FileSource> {
|
||||
self.capture.map(FileSource)
|
||||
}
|
||||
|
||||
pub fn now(&self) -> DateTime<&Tz> {
|
||||
if let Some(tz) = &self.timezone {
|
||||
Utc::now().with_timezone(&tz)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue