diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 02d3a0f6..566b7aaa 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -45,6 +45,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 + lfs: true - uses: dtolnay/rust-toolchain@stable - uses: swatinem/rust-cache@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index fbe9c45e..eada147f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] - ReleaseDate +### Added + +- Use `SLUMBER_CONFIG_PATH` to customize configuration (_not_ collection) file path [#370](https://github.com/LucasPickering/slumber/issues/370) + +### Fixed + +- Updated the Configuration docs to remove the non-existent `slumber show dir` command (thanks @SVendittelli) + ## [2.0.0] - 2024-09-06 2.0 is headlined by a highly requested feature: one-off edits to recipes! If you need to tweak a query parameter or edit a body, but don't want to modify your collection file, you can now highlight the value in question and hit `e` to modify it. The override will be retained until you modify the collection file or exit Slumber, at which point it will revert to its original value. @@ -43,7 +51,7 @@ Here's the full list of changes: ### Fixed -- Fix Basic auth being label as Bearer auth in Recipe Authentication pane +- Fix basic auth being label as bearer auth in Recipe Authentication pane - Use correct binding for `search` action in the placeholder of the response filter textbox - Previously it was hardcoded to display the default of `/` - Fix response body filter not applying on new responses diff --git a/Cargo.lock b/Cargo.lock index 12f271bb..671897d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2218,6 +2218,8 @@ dependencies = [ "anyhow", "crossterm", "derive_more", + "dirs", + "env-lock", "indexmap", "itertools 0.13.0", "ratatui", diff --git a/Cargo.toml b/Cargo.toml index d3d499d1..9a2bc1e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,8 @@ bytes = {version = "1.6.1", default-features = false} chrono = {version = "0.4.31", default-features = false} crossterm = {version = "0.28.0", default-features = false, features = ["events"]} derive_more = {version = "1.0.0", default-features = false} +dirs = "5.0.1" +env-lock = "0.1.0" futures = "0.3.28" indexmap = {version = "2.0.0", default-features = false} itertools = "0.13.0" diff --git a/README.md b/README.md index 851e3536..dbc0b811 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ - [Docs](https://slumber.lucaspickering.me/book/) - [Changelog](https://slumber.lucaspickering.me/changelog/) -![Slumber example](./static/demo.gif) +![Slumber example](/static/demo.gif) Slumber is a TUI (terminal user interface) HTTP client. Define, execute, and share configurable HTTP requests. Slumber is built on some basic principles: diff --git a/crates/slumber_config/Cargo.toml b/crates/slumber_config/Cargo.toml index e1447e45..6b15478b 100644 --- a/crates/slumber_config/Cargo.toml +++ b/crates/slumber_config/Cargo.toml @@ -22,6 +22,8 @@ slumber_core = {workspace = true} tracing = {workspace = true} [dev-dependencies] +dirs = {workspace = true} +env-lock = {workspace = true} rstest = {workspace = true} serde_test = {workspace = true} slumber_core = {workspace = true, features = ["test"]} diff --git a/crates/slumber_config/src/lib.rs b/crates/slumber_config/src/lib.rs index ed4c90f1..149b7cc6 100644 --- a/crates/slumber_config/src/lib.rs +++ b/crates/slumber_config/src/lib.rs @@ -20,11 +20,12 @@ use indexmap::IndexMap; use serde::{Deserialize, Serialize}; use slumber_core::{ http::HttpEngineConfig, - util::{parse_yaml, DataDirectory, ResultTraced}, + util::{expand_home, parse_yaml, DataDirectory, ResultTraced}, }; -use std::{fs::File, path::PathBuf}; +use std::{env, fs::File, path::PathBuf}; use tracing::info; +const PATH_ENV_VAR: &str = "SLUMBER_CONFIG_PATH"; const FILE: &str = "config.yml"; /// App-level configuration, which is global across all sessions and @@ -52,7 +53,9 @@ pub struct Config { impl Config { /// Path to the configuration file pub fn path() -> PathBuf { - DataDirectory::get().file(FILE) + env::var(PATH_ENV_VAR) + .map(|path| expand_home(PathBuf::from(path)).into_owned()) + .unwrap_or_else(|_| DataDirectory::get().file(FILE)) } /// Load configuration from the file, if present. If not, just return a @@ -96,3 +99,21 @@ impl Default for Config { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_custom_config_path() { + let _guard = env_lock::lock_env([( + PATH_ENV_VAR, + Some("~/dotfiles/slumber.yml"), + )]); + // Note: tilde is NOT expanded here; we expect the shell to do that + assert_eq!( + Config::path(), + dirs::home_dir().unwrap().join("dotfiles/slumber.yml") + ); + } +} diff --git a/crates/slumber_core/Cargo.toml b/crates/slumber_core/Cargo.toml index b0b74f7e..2a428d8d 100644 --- a/crates/slumber_core/Cargo.toml +++ b/crates/slumber_core/Cargo.toml @@ -16,7 +16,7 @@ async-trait = "0.1.81" bytes = {workspace = true, features = ["serde"]} chrono = {workspace = true, features = ["clock", "serde", "std"]} derive_more = {workspace = true, features = ["debug", "deref", "deref_mut", "display", "from", "from_str"]} -dirs = "5.0.1" +dirs = {workspace = true} futures = {workspace = true} indexmap = {workspace = true, features = ["serde"]} itertools = {workspace = true} @@ -41,7 +41,7 @@ uuid = {workspace = true, features = ["serde", "v4"]} winnow = "0.6.16" [dev-dependencies] -env-lock = "0.1.0" +env-lock = {workspace = true} pretty_assertions = {workspace = true} proptest = "1.5.0" proptest-derive = "0.5.0" diff --git a/docs/src/api/configuration/index.md b/docs/src/api/configuration/index.md index 403484c0..8e5ba7b2 100644 --- a/docs/src/api/configuration/index.md +++ b/docs/src/api/configuration/index.md @@ -4,21 +4,20 @@ Configuration provides _application_-level settings, as opposed to collection-le ## Location & Creation -Configuration is stored in the Slumber root directory, under the file `config.yml`. To find the root directory, you can run: +By default, configuration is stored in the Slumber root directory, under the file `config.yml`. To find the config file, you can run: ```sh -slumber show dir +slumber show paths ``` -To quickly create and edit the file: +If the root directory doesn't exist yet, you can create it yourself or have Slumber create it by simply starting the TUI. + +You can change the location of the config file by setting the environment variable `SLUMBER_CONFIG_PATH`. For example: ```sh -# Replace vim with your favorite text editor -vim $(slumber show dir)/config.yml +SLUMBER_CONFIG_PATH=~/dotfiles/slumber.yml slumber ``` -If the root directory doesn't exist yet, you can create it yourself or have Slumber create it by simply starting the TUI. - ## Fields | Field | Type | Description | Default |