Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize config path with SLUMBER_CONFIG_PATH #372

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions crates/slumber_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down
27 changes: 24 additions & 3 deletions crates/slumber_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
);
}
}
4 changes: 2 additions & 2 deletions crates/slumber_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions docs/src/api/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Loading