Skip to content

Commit

Permalink
Start implementing configs part (Serialize/Deserialize files)
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <[email protected]>
  • Loading branch information
FedericoBruzzone committed Mar 11, 2024
1 parent 40386a4 commit 396dd72
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 130 deletions.
58 changes: 50 additions & 8 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ default-run = "tgt"
[dependencies]
config = "0.14.0"
crossterm = {version = "0.27.0", features = ["event-stream"]}
dirs = "5.0.1"
futures = "0.3.30"
lazy_static = "1.4.0"
ratatui = "0.26.1"
serde = "1.0.197"
signal-hook = "0.3.17"
tdlib = "0.10.0"
tokio = {version = "1.36.0", features = ["full"]}
toml = "0.8.10"
tracing = "0.1.40"
tracing-error = "0.2.0"
tracing-subscriber = {version = "0.3.18", features = ["env-filter"]}
xdg = "2.5.2"

[profile.dev]
incremental = true
Expand Down
3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ project_name := "tgt"
_default:
just --list --justfile {{justfile()}}

# All
all: fmt clippy test build

# Build the project using cargo
build:
cargo build
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export RUST_BACKTRACE := 1
build:
cargo build

all: fmt clippy test build

# Example: make run ARGS="--bin <bin_name>"
run:
cargo run $(ARGS)
Expand Down
3 changes: 3 additions & 0 deletions config/logger.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
log_folder = ".data"
log_file = "tgt.log"
log_level = "info" # error | warn | info | debug | trace | off
7 changes: 1 addition & 6 deletions docs/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
`tgt` reads configurations from the following directories using environment variables (in order of precedence):

- `$TGT_CONFIG_HOME`
- `$XDG_CONFIG_HOME/tgt` (only on Linux and macOS)
- `$HOME/.config/tgt`
- `$HOME/.config/tgt` (for Linux and macOS) and `C:\Users\<name>\AppData\Roaming\tgt` (for Windows)

`tgt`'s behavior is:

If there exists a config file, use that config. (No default or inherited values from a default config)
If there is no config file, a default config will be used (found under config/)
16 changes: 8 additions & 8 deletions src/app_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use {crate::enums::action::Action, tokio::sync::mpsc::error::SendError};
use {crate::enums::action::Action, config::ConfigError, tokio::sync::mpsc::error::SendError};

#[derive(Debug)]
/// An error type for the application.
Expand All @@ -7,8 +7,8 @@ use {crate::enums::action::Action, tokio::sync::mpsc::error::SendError};
/// This type is used as the error type for the `Result` type returned by the `main` function.
pub enum AppError {
Io(std::io::Error),
TomlDeError(toml::de::Error),
Send(SendError<Action>),
Config(ConfigError),
}
/// Convert an `std::io::Error` into an `AppError`.
impl From<std::io::Error> for AppError {
Expand All @@ -22,19 +22,19 @@ impl From<SendError<Action>> for AppError {
Self::Send(error)
}
}
/// Convert a `toml::de::Error` into an `AppError`.
impl From<toml::de::Error> for AppError {
fn from(error: toml::de::Error) -> Self {
Self::TomlDeError(error)
/// Convert a `config::ConfigError` into an `AppError`.
impl From<ConfigError> for AppError {
fn from(error: ConfigError) -> Self {
Self::Config(error)
}
}
/// Implement the `Display` trait for `AppError`.
impl std::fmt::Display for AppError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Io(error) => write!(f, "IO error: {}", error),
Self::TomlDeError(error) => write!(f, "TOML deserialization error: {}", error),
Self::Send(error) => write!(f, "Send error: {}", error),
Self::Config(error) => write!(f, "Config error: {}", error),
}
}
}
Expand All @@ -43,8 +43,8 @@ impl std::error::Error for AppError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(error) => Some(error),
Self::TomlDeError(error) => Some(error),
Self::Send(error) => Some(error),
Self::Config(error) => Some(error),
}
}
}
101 changes: 0 additions & 101 deletions src/config/config_dir_hierarchy.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/config/mod.rs

This file was deleted.

Loading

0 comments on commit 396dd72

Please sign in to comment.