diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index e92a872c..be01316e 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -143,7 +143,8 @@ pub struct CommandsConfig { /// If empty, commands will be parsed with shell-words and run natievly pub shell: Vec, /// Default query command for responses - pub query_default: Option, + #[serde(default)] + pub default_query: MimeMap, } impl Default for CommandsConfig { @@ -159,7 +160,7 @@ impl Default for CommandsConfig { Self { shell: default_shell.iter().map(|s| s.to_string()).collect(), - query_default: None, + default_query: MimeMap::default(), } } } diff --git a/crates/tui/src/view/component/queryable_body.rs b/crates/tui/src/view/component/queryable_body.rs index d1948dc5..b27e0ef9 100644 --- a/crates/tui/src/view/component/queryable_body.rs +++ b/crates/tui/src/view/component/queryable_body.rs @@ -43,7 +43,7 @@ pub struct QueryableBody { /// Default query to use when none is present. We have to store this so we /// can apply it when an empty query is loaded from persistence. Generally /// this will come from the config but it's parameterized for testing - query_default: Option, + default_query: Option, /// Track status of the current query command query_state: QueryState, /// Where the user enters their body query @@ -81,7 +81,7 @@ impl QueryableBody { emitter_id: EmitterId::new(), response, query_focused: false, - query_default: default_query, + default_query, last_executed_command: None, query_state: QueryState::None, query_text_box: query_text_box.into(), @@ -279,7 +279,7 @@ impl PersistedContainer for QueryableBody { // for this recipe). It's possible the user really wants an empty box // and this is annoying, but I think it'll be more good than bad. if text_box.text().is_empty() { - if let Some(query) = self.query_default.clone() { + if let Some(query) = self.default_query.clone() { self.query_text_box.data_mut().set_text(query); } } @@ -558,7 +558,7 @@ mod tests { /// Test that the user's configured query default is applied on a fresh load #[rstest] #[tokio::test] - async fn test_query_default_initial( + async fn test_default_query_initial( harness: TestHarness, terminal: TestTerminal, response: Arc, @@ -586,7 +586,7 @@ mod tests { /// persisted value, but it's an empty string #[rstest] #[tokio::test] - async fn test_query_default_persisted( + async fn test_default_query_persisted( harness: TestHarness, terminal: TestTerminal, response: Arc, diff --git a/crates/tui/src/view/component/response_view.rs b/crates/tui/src/view/component/response_view.rs index f583f105..07aa7abb 100644 --- a/crates/tui/src/view/component/response_view.rs +++ b/crates/tui/src/view/component/response_view.rs @@ -38,12 +38,14 @@ pub struct ResponseBodyView { impl ResponseBodyView { pub fn new(recipe_id: RecipeId, response: Arc) -> Self { + // Select default query based on content type + let config = &TuiContext::get().config.commands; + let default_query = response + .mime() + .and_then(|mime| config.default_query.get(&mime).cloned()); let body = PersistedLazy::new( ResponseQueryPersistedKey(recipe_id), - QueryableBody::new( - Arc::clone(&response), - TuiContext::get().config.commands.query_default.clone(), - ), + QueryableBody::new(Arc::clone(&response), default_query), ) .into(); Self { diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 77013e54..a19befde 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -21,6 +21,7 @@ - [slumber collections](./cli/collections.md) - [slumber generate](./cli/generate.md) +- [slumber history](./cli/history.md) - [slumber import](./cli/import.md) - [slumber new](./cli/new.md) - [slumber request](./cli/request.md) diff --git a/docs/src/api/configuration/index.md b/docs/src/api/configuration/index.md index 84bf84ac..01dca04d 100644 --- a/docs/src/api/configuration/index.md +++ b/docs/src/api/configuration/index.md @@ -42,9 +42,9 @@ The following fields are available in `config.yml`: Shell used to execute commands within the TUI. Use `[]` for no shell (commands will be parsed and executed directly). [More info](../../user_guide/tui/filter_query.md) -### `commands.query_default` +### `commands.default_query` -**Type:** `string` +**Type:** `string` or `mapping[Mime, string]` (see [MIME Maps](./mime.md)) **Default:** `""` diff --git a/docs/src/cli/history.md b/docs/src/cli/history.md new file mode 100644 index 00000000..db5a3401 --- /dev/null +++ b/docs/src/cli/history.md @@ -0,0 +1,12 @@ +# `slumber history` + +View your Slumber request history. + +## Examples + +```sh +slumber history list login # List all requests for the "login" recipe +slumber history list login -p dev # List all requests for "login" under the "dev" profile +slumber history get login # Get the most recent request/response for "login" +slumber history get 548ba3e7-3b96-4695-9856-236626ea0495 # Get a particular request/response by ID (IDs can be retrieved from the `list` subcommand) +``` diff --git a/docs/src/user_guide/tui/filter_query.md b/docs/src/user_guide/tui/filter_query.md index 71d8d994..ec86585e 100644 --- a/docs/src/user_guide/tui/filter_query.md +++ b/docs/src/user_guide/tui/filter_query.md @@ -14,6 +14,16 @@ _Example of using pipes in a query command_ Keep in mind that your queries are being executed as shell commands on your system. You should avoid running any commands that interact with the file system, such as using `>` or `<` to pipe to/from files. TODO add more about side-effect commands once implemented +## Default command + +You can set the default command to query with via the [`commands.default_query`](../../api/configuration/index.md#commandsdefault_query) config field. This accepts either a single string to set it for all content types, or a [MIME map](../../api/configuration/mime.md) to set different defaults based on the response content type. For example, to default to `jq` for all JSON responses: + +```yaml +commands: + default_query: + json: jq +``` + ## Which shell does Slumber use? By default, Slumber executes your command via `sh -c` on Unix and `cmd /S /C` on Windows. You can customize this via the [`commands.shell` configuration field](../../api/configuration/index.md#commandsshell). For example, to use `fish` instead of `sh`: