Skip to content

Commit

Permalink
feat: edit command now uses shorthand query
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Nov 9, 2022
1 parent 829559e commit d3644d7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 182 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Features include:
- [JSON:API](https://jsonapi.org/)
- Local caching that respects [RFC 7234](https://tools.ietf.org/html/rfc7234) `Cache-Control` and `Expires` headers
- CLI [shorthand](https://github.com/danielgtaylor/openapi-cli-generator/tree/master/shorthand#cli-shorthand-syntax) for structured data input (e.g. for JSON)
- [JMESPath Plus](https://github.com/danielgtaylor/go-jmespath-plus) response filtering & projection
- [Shorthand query](https://github.com/danielgtaylor/shorthand#querying) response filtering & projection
- Colorized prettified readable output
- Fast native zero-dependency binary

Expand Down
10 changes: 8 additions & 2 deletions cli/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os/exec"
"strings"

jmespath "github.com/danielgtaylor/go-jmespath-plus"
"github.com/danielgtaylor/shorthand/v2"
"github.com/google/shlex"
"github.com/hexops/gotextdiff"
Expand Down Expand Up @@ -71,7 +70,14 @@ export EDITOR="vim"`)
if filter == "" {
filter = "body"
}
filtered, err := jmespath.Search(filter, data)

var logger func(format string, a ...interface{})
if enableVerbose {
logger = LogDebug
}
filtered, _, err := shorthand.GetPath(filter, data, shorthand.GetOptions{
DebugLogger: logger,
})
panicOnErr(err)
data = filtered

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
- [JSON:API](https://jsonapi.org/)
- Local caching that respects [RFC 7234](https://tools.ietf.org/html/rfc7234) `Cache-Control` and `Expires` headers
- CLI [shorthand](https://github.com/danielgtaylor/openapi-cli-generator/tree/master/shorthand#cli-shorthand-syntax) for structured data input (e.g. for JSON)
- [JMESPath Plus](https://github.com/danielgtaylor/go-jmespath-plus) response filtering & projection
- [Shorthand query](https://github.com/danielgtaylor/shorthand#querying) response filtering & projection
- Colorized prettified readable output
- Fast native zero-dependency binary

Expand Down
30 changes: 15 additions & 15 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ Global configuration affects all commands and can be set in one of three ways, g

The global options in addition to `--help` and `--version` are:

| Argument | Env Var | Example | Description |
| --------------------------- | ------------------- | ------------------- | -------------------------------------------------------------------------------- |
| `-f`, `--rsh-filter` | `RSH_FILTER` | `body.users[].id` | [JMESPath Plus](https://github.com/danielgtaylor/go-jmespath-plus#readme) filter |
| `-H`, `--rsh-header` | `RSH_HEADER` | `Version:2020-05` | Set a header name/value |
| `--rsh-insecure` | `RSH_INSECURE` | | Disable TLS certificate checks |
| `--rsh-client-cert` | `RSH_CLIENT_CERT` | `/etc/ssl/cert.pem` | Path to a PEM encoded client certificate |
| `--rsh-client-key` | `RSH_CLIENT_KEY` | `/etc/ssl/key.pem` | Path to a PEM encoded private key |
| `--rsh-ca-cert` | `RSH_CA_CERT` | `/etc/ssl/ca.pem` | Path to a PEM encoded CA certificate |
| `--rsh-no-paginate` | `RSH_NO_PAGINATE` | | Disable automatic `next` link pagination |
| `-o`, `--rsh-output-format` | `RSH_OUTPUT_FORMAT` | `json` | [Output format](/output.md), defaults to `auto` |
| `-p`, `--rsh-profile` | `RSH_PROFILE` | `testing` | Auth profile name, defaults to `default` |
| `-q`, `--rsh-query` | `RSH_QUERY` | `search=foo` | Set a query parameter |
| `-r`, `--rsh-raw` | `RSH_RAW` | | Raw output for shell processing |
| `-s`, `--rsh-server` | `RSH_SERVER` | `https://foo.com` | Override API server base URL |
| `-v`, `--rsh-verbose` | `RSH_VERBOSE` | | Enable verbose output |
| Argument | Env Var | Example | Description |
| --------------------------- | ------------------- | ------------------- | ------------------------------------------------------------------------------------------ |
| `-f`, `--rsh-filter` | `RSH_FILTER` | `body.users[].id` | Filter response via [Shorthand query](https://github.com/danielgtaylor/shorthand#querying) |
| `-H`, `--rsh-header` | `RSH_HEADER` | `Version:2020-05` | Set a header name/value |
| `--rsh-insecure` | `RSH_INSECURE` | | Disable TLS certificate checks |
| `--rsh-client-cert` | `RSH_CLIENT_CERT` | `/etc/ssl/cert.pem` | Path to a PEM encoded client certificate |
| `--rsh-client-key` | `RSH_CLIENT_KEY` | `/etc/ssl/key.pem` | Path to a PEM encoded private key |
| `--rsh-ca-cert` | `RSH_CA_CERT` | `/etc/ssl/ca.pem` | Path to a PEM encoded CA certificate |
| `--rsh-no-paginate` | `RSH_NO_PAGINATE` | | Disable automatic `next` link pagination |
| `-o`, `--rsh-output-format` | `RSH_OUTPUT_FORMAT` | `json` | [Output format](/output.md), defaults to `auto` |
| `-p`, `--rsh-profile` | `RSH_PROFILE` | `testing` | Auth profile name, defaults to `default` |
| `-q`, `--rsh-query` | `RSH_QUERY` | `search=foo` | Set a query parameter |
| `-r`, `--rsh-raw` | `RSH_RAW` | | Raw output for shell processing |
| `-s`, `--rsh-server` | `RSH_SERVER` | `https://foo.com` | Override API server base URL |
| `-v`, `--rsh-verbose` | `RSH_VERBOSE` | | Enable verbose output |

Configuration file keys are the same as long-form arguments without the `--` prefix.

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/andybalholm/brotli v1.0.4
github.com/charmbracelet/glamour v0.5.1-0.20221024082230-3c5ceaed91cc
github.com/danielgtaylor/casing v0.0.0-20210126043903-4e55e6373ac3
github.com/danielgtaylor/go-jmespath-plus v0.0.0-20200228063638-e0b6f132acba
github.com/danielgtaylor/shorthand/v2 v2.0.0-beta2
github.com/eliukblau/pixterm v1.3.1
github.com/fxamacker/cbor/v2 v2.4.0
Expand All @@ -31,6 +30,7 @@ require (
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.1
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9
golang.org/x/exp v0.0.0-20221108223516-5d533826c662
golang.org/x/oauth2 v0.1.0
golang.org/x/term v0.1.0
golang.org/x/text v0.4.0
Expand All @@ -45,6 +45,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand Down Expand Up @@ -78,10 +79,10 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/twpayne/httpcache v1.0.0 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/exp v0.0.0-20221108223516-5d533826c662 // indirect
golang.org/x/image v0.1.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
Expand Down

0 comments on commit d3644d7

Please sign in to comment.