Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Commit

Permalink
Verbose error for missed files
Browse files Browse the repository at this point in the history
  • Loading branch information
fido-node committed Dec 29, 2023
1 parent 7c1e5d8 commit ec3167b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 28 deletions.
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ lazy_static = "1.4.0"
mockall = "0.11.4"
handlebars = "4.5.0"
systemstat = "0.2.3"
dirs = "5.0.1"

[build-dependencies]
prost-build = "0.12"
Empty file added resources/rusty-belt.plist
Empty file.
35 changes: 25 additions & 10 deletions src/bin/rusty_belt_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ use rusty_belt::io::server::Server;
use rusty_belt::state::rehydrator::Rehydrator;
use rusty_belt::state::State;
use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;
use std::sync::Arc;

#[tokio::main]
async fn main() {
async fn main() -> Result<(), Box<dyn Error>> {
let args = ServerArgs::parse();

let config_folder = get_config_path();
let config_folder = get_config_path().ok_or_else(|| "Can't find path for config")?;

let mut config_file = PathBuf::from(config_folder.clone());
let mut config_file = config_folder.clone();
config_file.push("config.yaml");

let mut log_config_file = PathBuf::from(config_folder.clone());
Expand All @@ -31,13 +32,26 @@ async fn main() {
config_file
};

log4rs::init_file(
args.log_config_path
.map(|cp| PathBuf::from(cp))
.unwrap_or(log_config_file),
Default::default(),
)
.unwrap();
path_to_config.try_exists().map_err(|_| {
format!(
"Can't find app config file. Expect it here: \n {}",
path_to_config.as_path().display()
)
})?;

let path_to_log = args
.log_config_path
.map(|cp| PathBuf::from(cp))
.unwrap_or(log_config_file);

path_to_log.try_exists().map_err(|_| {
format!(
"Can't find log config file. Expect it here: \n {}",
path_to_log.as_path().display()
)
})?;

log4rs::init_file(path_to_log, Default::default()).unwrap();

let config: AppConfig = parse_config(&path_to_config);
let models: HashMap<String, Vec<Box<dyn Model>>> = config
Expand Down Expand Up @@ -65,4 +79,5 @@ async fn main() {

let server = Server::new(arc_state.clone(), addr);
server.run().await;
Ok(())
}
31 changes: 22 additions & 9 deletions src/bin/tmux_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use std::error::Error;
async fn main() -> Result<(), Box<dyn Error>> {
let args = CliArgs::parse();

let config_folder = get_config_path();
let config_folder = get_config_path().ok_or_else(|| "Can't find path for config")?;

let mut config_file = PathBuf::from(config_folder.clone());
let mut config_file = config_folder.clone();
config_file.push("config.yaml");

let mut log_config_file = PathBuf::from(config_folder.clone());
Expand All @@ -31,13 +31,26 @@ async fn main() -> Result<(), Box<dyn Error>> {
config_file
};

log4rs::init_file(
args.log_config_path
.map(|cp| PathBuf::from(cp))
.unwrap_or(log_config_file),
Default::default(),
)
.unwrap();
path_to_config.try_exists().map_err(|_| {
format!(
"Can't find app config file. Expect it here: \n {}",
path_to_config.as_path().display()
)
})?;

let path_to_log = args
.log_config_path
.map(|cp| PathBuf::from(cp))
.unwrap_or(log_config_file);

path_to_log.try_exists().map_err(|_| {
format!(
"Can't find log config file. Expect it here: \n {}",
path_to_log.as_path().display()
)
})?;

log4rs::init_file(path_to_log, Default::default()).unwrap();

let config: AppConfig = parse_config(&path_to_config);
let segment_conf = config
Expand Down
23 changes: 14 additions & 9 deletions src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
pub fn get_config_path() -> String {
let xdg_home = std::env::var("XDG_CONFIG_HOME").map(|mut s| {
s.push_str("/rusty-belt");
use std::path::PathBuf;

use dirs;

pub fn get_config_path() -> Option<PathBuf> {
dirs::config_dir().map(|mut s| {
s.push("rusty-belt");
s
});
let home = std::env::var("HOME").map(|mut s| {
s.push_str("/.config/rusty-belt");
})
}

pub fn get_data_path() -> Option<PathBuf> {
dirs::data_dir().map(|mut s| {
s.push("rusty-belt");
s
});
let path = xdg_home.or(home).unwrap();
path
})
}

0 comments on commit ec3167b

Please sign in to comment.