Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Regolith Linux committed Feb 10, 2024
1 parent a7973df commit 76b0249
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
32 changes: 22 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,34 @@ fn main() {
.unwrap()
.block_on(async move {
let mut config: Config = match args.config.as_str() {
STDIN_FILE_DESIGNATOR => { // read from stdin
STDIN_FILE_DESIGNATOR => {
// read from stdin
let mut config_str = String::new();

let size = std::io::stdin().read_to_string(&mut config_str)
.or_error(|| format!("Configuration file could not be read from stdin"))?;

if size == 0 {
return Err(i3status_rs::errors::Error { kind: ErrorKind::Config, message: None, cause: None, block: None });
let size = std::io::stdin()
.read_to_string(&mut config_str)
.or_error(|| {
"Configuration file could not be read from stdin".to_string()
})?;

if size == 0 {
return Err(i3status_rs::errors::Error {
kind: ErrorKind::Config,
message: None,
cause: None,
block: None,
});
}

util::deserialize_toml(&config_str, None)?
},
_ => { // read from file path
}
_ => {
// read from file path
let config_path = util::find_file(&args.config, None, Some("toml"))
.or_error(|| format!("Configuration file '{}' not found", args.config))?;
let config_str = util::read_file(&config_path).await.or_error(|| format!("Configuration file '{}' not found", args.config))?;
.or_error(|| format!("Configuration file '{}' not found", args.config))?;
let config_str = util::read_file(&config_path)
.await
.or_error(|| format!("Configuration file '{}' not found", args.config))?;
util::deserialize_toml(&config_str, Some(&config_path))?
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
let contents = std::fs::read_to_string(path)
.or_error(|| format!("Failed to read file: {}", path.display()))?;

self::deserialize_toml(&contents, Some(&path))
self::deserialize_toml(&contents, Some(path))
}

pub fn deserialize_toml<T>(contents: &String, file_path: Option<&Path>) -> Result<T>
Expand All @@ -104,10 +104,10 @@ where
{
let source = match file_path {
Some(msg) => msg.display().to_string(),
_ => String::from("(from stdin)")
_ => String::from("(from stdin)"),
};

toml::from_str(&contents).map_err(|err| {
toml::from_str(contents).map_err(|err| {
#[allow(deprecated)]
let location_msg = err
.span()
Expand Down

0 comments on commit 76b0249

Please sign in to comment.