diff options
author | Nick Gerace <nickagerace@gmail.com> | 2022-03-10 09:41:09 -0700 |
---|---|---|
committer | Nick Gerace <nickagerace@gmail.com> | 2022-03-10 11:47:40 -0500 |
commit | 706329e246d0561cd1c199bcfb0b94d4eb17352e (patch) | |
tree | 1b141e77152e6edbef278dfe192631828899a850 | |
parent | 46d9b240e774432e6261d311f3ae313d2ab2d6c2 (diff) | |
download | gfold-706329e246d0561cd1c199bcfb0b94d4eb17352e.zip |
Change config file lookup path and file type
- Change config file lookup path from "<prefix>/gfold/gfold.json" to
"<prefix>/gfold.toml"
- Change config file type from JSON to TOML
Signed-off-by: Nick Gerace <nickagerace@gmail.com>
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | Cargo.lock | 70 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | README.md | 8 | ||||
-rwxr-xr-x | scripts/uninstall.sh | 4 | ||||
-rw-r--r-- | src/cli.rs | 4 | ||||
-rw-r--r-- | src/config.rs | 29 |
7 files changed, 49 insertions, 70 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ebc8bc..ab4dc53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed +- Config file location from `<prefix>/gfold/gfold.json` to `<prefix>/gfold.toml` +- Config file type from JSON to TOML - Major performance improvements due to moving from sequential target generation to nested, parallel iterators for target generation ### Removed @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" +checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" [[package]] name = "argh" @@ -62,9 +62,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" dependencies = [ "jobserver", ] @@ -168,9 +168,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" +checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" dependencies = [ "cfg-if", "libc", @@ -189,16 +189,16 @@ dependencies = [ "log", "rayon", "serde", - "serde_json", "termcolor", "thiserror", + "toml", ] [[package]] name = "git2" -version = "0.13.25" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6" +checksum = "6e7d3b96ec1fcaa8431cf04a4f1ef5caafe58d5cf7bcc31f09c1626adddb0ffe" dependencies = [ "bitflags", "libc", @@ -243,12 +243,6 @@ dependencies = [ ] [[package]] -name = "itoa" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" - -[[package]] name = "jobserver" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -265,15 +259,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.117" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" [[package]] name = "libgit2-sys" -version = "0.12.26+1.3.0" +version = "0.13.1+1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494" +checksum = "43e598aa7a4faedf1ea1b4608f582b06f0f40211eec551b7ef36019ae3f62def" dependencies = [ "cc", "libc", @@ -283,9 +277,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de5435b8549c16d423ed0c03dbaafe57cf6c3344744f1242520d59c9d8ecec66" +checksum = "6f35facd4a5673cb5a48822be2be1d4236c1c99cb4113cab7061ac720d5bf859" dependencies = [ "cc", "libc", @@ -384,9 +378,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c" dependencies = [ "bitflags", ] @@ -402,12 +396,6 @@ dependencies = [ ] [[package]] -name = "ryu" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" - -[[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -434,17 +422,6 @@ dependencies = [ ] [[package]] -name = "serde_json" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] name = "syn" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -457,9 +434,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] @@ -500,6 +477,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] name = "unicode-bidi" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -21,9 +21,9 @@ git2 = { version = "0", default_features = false } log = "0" rayon = "1" serde = { version = "1", features = ["derive"] } -serde_json = "1" termcolor = "1" thiserror = "1" +toml = "0" # Source: https://github.com/env-logger-rs/env_logger/blob/v0.9.0/Cargo.toml#L47 # Removed features: ["regex", "termcolor"] @@ -82,13 +82,13 @@ gfold ../../this/is/a/relative/path Upon execution, `gfold` will look for a config file at the following path on macOS, Linux and similar operating systems: ```bash -$HOME/.config/gfold/gfold.json +$HOME/.config/gfold.toml ``` On Windows, the config file is located at the following path: ```powershell -{FOLDERID_Profile}\.config\gfold\gfold.json +{FOLDERID_Profile}\.config\gfold.toml ``` Creating and using the config file is entirely optional, and you can ignore your config file at any time using the `-i` flag. @@ -96,7 +96,7 @@ Creating and using the config file is entirely optional, and you can ignore your Here is an example creation workflow for a config file: ```bash -gfold --classic ~/ --print > $HOME/.config/gfold/gfold.json +gfold --classic ~/ --print > $HOME/.config/gfold.toml ``` This config file will default to the classic display mode and set the default path to `$HOME`, rather than the current working directory. @@ -114,7 +114,7 @@ You can back up a config file and track its history with `git`. On macOS, Linux, and most systems, you can link the file back to a `git` repository. ```bash -ln -s path/to/repository/gfold.json $HOME/.config/gfold/gfold.json +ln -s path/to/repository/gfold.toml $HOME/.config/gfold.toml ``` Now, you can update the config file within your repository and include the linking as part of your environment setup workflow. diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index f14a12d..25ca4df 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -25,8 +25,8 @@ function perform-uninstall { done log "uninstallation and cleanup has completed successfully" - if [ -f $HOME/.config/gfold/gfold.json ]; then - log "you may want to delete or backup the config file: $HOME/.config/gfold/gfold.json" + if [ -f $HOME/.config/gfold.toml ]; then + log "you may want to delete or backup the config file: $HOME/.config/gfold.toml" fi } @@ -15,8 +15,8 @@ While CLI options are prioritized, default options will fallback to the config file if it exists. Here is the config file lookup locations for some common operating systems: - macOS/Linux $HOME/.config/gfold/gfold.json - Windows {{FOLDERID_Profile}}\\.config\\gfold\\gfold.json")] + macOS/Linux $HOME/.config/gfold.toml + Windows {{FOLDERID_Profile}}\\.config\\gfold.toml")] struct Args { #[argh( positional, diff --git a/src/config.rs b/src/config.rs index 1f51cfd..c0a7334 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,10 +1,9 @@ use crate::error::Error; -use anyhow::{Context, Result}; -use log::warn; +use anyhow::Result; + use serde::{Deserialize, Serialize}; + use std::env; -use std::fs::File; -use std::io::BufReader; use std::path::PathBuf; // "Config" is the actual type consumed through the codebase. It is boostrapped via its public @@ -52,19 +51,11 @@ impl Config { // "EntryConfig" default before conversion. pub fn try_config() -> Result<Self> { let home = dirs::home_dir().ok_or(Error::HomeDirNotFound)?; - let entry_config = match File::open(home.join(".config").join("gfold").join("gfold.json")) { - Ok(o) => match o.metadata()?.len() { - len if len > 0 => { - let reader = BufReader::new(o); - serde_json::from_reader(reader) - .context("config file's contents are likely invalid JSON")? - } - _ => EntryConfig::default(), - }, - Err(e) => { - warn!("{}", e); - EntryConfig::default() - } + let path = home.join(".config").join("gfold.toml"); + let contents = std::fs::read_to_string(path)?; + let entry_config = match contents.is_empty() { + true => EntryConfig::default(), + false => toml::from_str(&contents)?, }; Self::from_entry_config(&entry_config) } @@ -75,9 +66,9 @@ impl Config { Self::from_entry_config(&EntryConfig::default()) } - // This method prints the full config (merged with config file, as needed) as valid JSON. + // This method prints the full config (merged with config file, as needed) as valid, pretty TOML. pub fn print(self) -> Result<()> { - println!("{}", serde_json::to_string_pretty(&self)?); + print!("{}", toml::to_string_pretty(&self)?); Ok(()) } |