forked from WGUNDERWOOD/tex-fmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into pr-refactor-logic
- Loading branch information
Showing
8 changed files
with
71 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
#+title: tex-fmt | ||
* Release process | ||
** Update version number in Cargo.toml | ||
** Push to GitHub and check tests pass | ||
** Create a git tag | ||
*** git tag vX.X.X | ||
*** git push --tags | ||
** Publish to crates.io with cargo publish | ||
** Publish GitHub release with notes | ||
*** GitHub binaries published automatically with actions | ||
** Publish in nixpkgs when bot makes pull request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! Utilities for reading files | ||
use crate::logging::*; | ||
use crate::regexes::*; | ||
use log::Level::{Error, Trace}; | ||
use std::fs; | ||
use std::io::Read; | ||
|
||
/// Add a missing extension and read the file | ||
pub fn read(file: &str, logs: &mut Vec<Log>) -> Option<(String, String)> { | ||
// check if file has an accepted extension | ||
let has_ext = EXTENSIONS.iter().any(|e| file.ends_with(e)); | ||
// if no valid extension, try adding .tex | ||
let mut new_file = file.to_owned(); | ||
if !has_ext { | ||
new_file.push_str(".tex"); | ||
}; | ||
if let Ok(text) = fs::read_to_string(&new_file) { | ||
return Some((new_file, text)); | ||
} | ||
if has_ext { | ||
record_file_log(logs, Error, file, "Could not open file."); | ||
} else { | ||
record_file_log(logs, Error, file, "File type invalid."); | ||
} | ||
None | ||
} | ||
|
||
/// Attempt to read from STDIN, return filename `<STDIN>` and text | ||
pub fn read_stdin(logs: &mut Vec<Log>) -> Option<(String, String)> { | ||
let mut text = String::new(); | ||
match std::io::stdin().read_to_string(&mut text) { | ||
Ok(bytes) => { | ||
record_file_log( | ||
logs, | ||
Trace, | ||
"<STDIN>", | ||
&format!("Read {bytes} bytes."), | ||
); | ||
Some((String::from("<STDIN>"), text)) | ||
} | ||
Err(e) => { | ||
record_file_log( | ||
logs, | ||
Error, | ||
"<STDIN>", | ||
&format!("Could not read from STDIN: {e}"), | ||
); | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters