From 65be7ad74176505ffb23a2a7ac8e5c1dda08e841 Mon Sep 17 00:00:00 2001 From: maksimowiczm Date: Wed, 1 May 2024 17:27:12 +0200 Subject: [PATCH] Add stdin option to command chains --- CHANGELOG.md | 1 + .../api/request_collection/chain_source.md | 1 + docs/src/user_guide/chains.md | 3 +- docs/src/user_guide/filter_query.md | 3 +- src/collection/models.rs | 5 +- src/template.rs | 37 ++++++-- src/template/render.rs | 91 ++++++++++++++----- 7 files changed, 108 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31dc81d0..2ebebaa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - Add action to save response body to file ([#183](https://github.com/LucasPickering/slumber/issues/183)) - Add `theme` field to the config, to configure colors ([#193](https://github.com/LucasPickering/slumber/issues/193)) - [See docs](https://slumber.lucaspickering.me/book/api/configuration/theme.html) for more info +- Add `stdin` option to command chains ([#190](https://github.com/LucasPickering/slumber/issues/190)) ### Changed diff --git a/docs/src/api/request_collection/chain_source.md b/docs/src/api/request_collection/chain_source.md index 0e0730e9..2e5ebe16 100644 --- a/docs/src/api/request_collection/chain_source.md +++ b/docs/src/api/request_collection/chain_source.md @@ -107,6 +107,7 @@ Execute a command and use its stdout as the rendered value. | Field | Type | Description | Default | | --------- | ------------ | ----------------------------------------------------------- | -------- | | `command` | `Template[]` | Command to execute, in the format `[program, ...arguments]` | Required | +| `stdin` | `Template` | Standard input which will be piped into the command | None | ### File diff --git a/docs/src/user_guide/chains.md b/docs/src/user_guide/chains.md index 563d2113..2806996f 100644 --- a/docs/src/user_guide/chains.md +++ b/docs/src/user_guide/chains.md @@ -99,7 +99,8 @@ chains: recipe: login auth_token: source: !command - command: [sh, -c, "echo '{{chains.auth_token_raw}}' | cut -d':' -f2"] + command: [ "cut", "-d':'", "-f2" ] + stdin: "{{chains.auth_token_raw}}" requests: login: !request diff --git a/docs/src/user_guide/filter_query.md b/docs/src/user_guide/filter_query.md index 09cd6ac5..b823e225 100644 --- a/docs/src/user_guide/filter_query.md +++ b/docs/src/user_guide/filter_query.md @@ -77,7 +77,8 @@ chains: recipe: login auth_token: source: !command - command: [sh, -c, "echo '{{chains.auth_token_raw}}' | jq .token"] + command: [ "jq", ".token" ] + stdin: "{{chains.auth_token_raw}} requests: login: !request diff --git a/src/collection/models.rs b/src/collection/models.rs index 66f82e5b..6dbdcefb 100644 --- a/src/collection/models.rs +++ b/src/collection/models.rs @@ -244,7 +244,10 @@ pub enum ChainSource { section: ChainRequestSection, }, /// Run an external command to get a result - Command { command: Vec