From 4ec3968a3c970dd1ea16aa420bc119d92669b10c Mon Sep 17 00:00:00 2001 From: Lucas Pickering Date: Fri, 3 Jan 2025 21:31:15 -0500 Subject: [PATCH 1/3] Add docs for history subcommand --- docs/src/SUMMARY.md | 1 + docs/src/cli/history.md | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 docs/src/cli/history.md 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/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) +``` From 26c19fd0f10223ec6e0a9ef572212f172005fcb5 Mon Sep 17 00:00:00 2001 From: Lucas Pickering Date: Fri, 3 Jan 2025 21:39:07 -0500 Subject: [PATCH 2/3] Rename query_default -> default_query --- crates/config/src/lib.rs | 4 ++-- crates/tui/src/view/component/queryable_body.rs | 10 +++++----- crates/tui/src/view/component/response_view.rs | 2 +- docs/src/api/configuration/index.md | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index e92a872c..2becca50 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -143,7 +143,7 @@ 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, + pub default_query: Option, } impl Default for CommandsConfig { @@ -159,7 +159,7 @@ impl Default for CommandsConfig { Self { shell: default_shell.iter().map(|s| s.to_string()).collect(), - query_default: None, + default_query: None, } } } 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..84459d81 100644 --- a/crates/tui/src/view/component/response_view.rs +++ b/crates/tui/src/view/component/response_view.rs @@ -42,7 +42,7 @@ impl ResponseBodyView { ResponseQueryPersistedKey(recipe_id), QueryableBody::new( Arc::clone(&response), - TuiContext::get().config.commands.query_default.clone(), + TuiContext::get().config.commands.default_query.clone(), ), ) .into(); diff --git a/docs/src/api/configuration/index.md b/docs/src/api/configuration/index.md index 84bf84ac..de3010a3 100644 --- a/docs/src/api/configuration/index.md +++ b/docs/src/api/configuration/index.md @@ -42,7 +42,7 @@ 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` From 3a50298a56db3233c895ae76fc871b0126825fdc Mon Sep 17 00:00:00 2001 From: Lucas Pickering Date: Fri, 3 Jan 2025 21:47:32 -0500 Subject: [PATCH 3/3] Support MIME map for commands.default_query --- crates/config/src/lib.rs | 5 +++-- crates/tui/src/view/component/response_view.rs | 10 ++++++---- docs/src/api/configuration/index.md | 2 +- docs/src/user_guide/tui/filter_query.md | 10 ++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 2becca50..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 default_query: 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(), - default_query: None, + default_query: MimeMap::default(), } } } diff --git a/crates/tui/src/view/component/response_view.rs b/crates/tui/src/view/component/response_view.rs index 84459d81..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.default_query.clone(), - ), + QueryableBody::new(Arc::clone(&response), default_query), ) .into(); Self { diff --git a/docs/src/api/configuration/index.md b/docs/src/api/configuration/index.md index de3010a3..01dca04d 100644 --- a/docs/src/api/configuration/index.md +++ b/docs/src/api/configuration/index.md @@ -44,7 +44,7 @@ Shell used to execute commands within the TUI. Use `[]` for no shell (commands w ### `commands.default_query` -**Type:** `string` +**Type:** `string` or `mapping[Mime, string]` (see [MIME Maps](./mime.md)) **Default:** `""` 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`: