Skip to content

Commit

Permalink
Replace yaml with toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Lloyd committed Jan 25, 2024
1 parent b77ecb1 commit 197d388
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
61 changes: 47 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ regex = "1.10.3"
tabled = { version = "0.14.0", features = ["color"] }
time = "0.3.31"
clap_complete = "4.4.9"
serde_yaml = "0.9.30"
duration-str = "0.7.1"
toml = "0.8.8"

[dev-dependencies]
assert_cmd = "2.0.13"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ If the `RUDRIC_SESSION` token is set in the environment:

# Configuration

Rudric can be configured with a yaml file. By default, this file is stored in `XDG_CONFIG/rudric/config.yaml` (`$HOME/.config/rudric/config.yaml` on Linux and Mac). All config options are optional. An example config file might look like this:
Rudric can be configured with a toml file. By default, this file is stored in `XDG_CONFIG/rudric/config.toml` (`$HOME/.config/rudric/config.toml` on Linux and Mac). All config options are optional. An example config file might look like this:

```yaml
```toml
# Options are: bash, zsh, fish, nu
default_shell: fish
default_shell = "fish"

# Specify the default length of time that a session token is valid for
session_lifetime: 6h
session_lifetime = "6h"

# Specify the name of the file to use in the CWD for setting environment variables (default ".renv")
renv_filename: .env
renv_filename = ".env"
```

# direnv
Expand Down
17 changes: 9 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::{fs, path::Path};

use anyhow::Result;
use duration_str::deserialize_option_duration_time;
Expand All @@ -16,15 +16,16 @@ pub struct Config {

impl Config {
pub fn load(config_dir: &Path) -> Result<Self> {
let config_file_path = config_dir.join("config.yaml");
let config_file = match std::fs::File::open(config_file_path) {
let config_file_path = config_dir.join("config.toml");

let config_string = match fs::read_to_string(config_file_path) {
Ok(c) => c,
Err(_) => {
return Ok(Self::default());
}
};

Ok(serde_yaml::from_reader(config_file)?)
Ok(toml::from_str(&config_string)?)
}
}

Expand All @@ -41,9 +42,9 @@ mod session_tests {
let test_dir = "testdata/test_config1";
std::fs::create_dir_all(test_dir)?;

let config_path = test_dir.to_string() + "/config.yaml";
let config_path = test_dir.to_string() + "/config.toml";
let mut file = File::create(config_path)?;
file.write_all(b"default_shell: fish\nsession_lifetime: 6h")?;
file.write_all(b"default_shell = \"fish\"\nsession_lifetime = \"6h\"")?;

let config = Config::load(Path::new(test_dir))?;

Expand All @@ -60,9 +61,9 @@ mod session_tests {
let test_dir = "testdata/test_config2";
std::fs::create_dir_all(test_dir)?;

let config_path = test_dir.to_string() + "/config.yaml";
let config_path = test_dir.to_string() + "/config.toml";
let mut file = File::create(config_path)?;
file.write_all(b"default_shell: fish")?;
file.write_all(b"default_shell = \"fish\"")?;

let config = Config::load(Path::new(test_dir))?;

Expand Down

0 comments on commit 197d388

Please sign in to comment.