Skip to content

Commit 6069f3c

Browse files
committed
fix: guide v1 api configure users to v2
1 parent 8642e26 commit 6069f3c

25 files changed

Lines changed: 3456 additions & 3 deletions

internal/cli/api.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ func (c *CLI) addAPICommand(root *cobra.Command) {
7575
connectCmd.Flags().Bool("replace", false, "Replace existing profiles with discovered OpenAPI/x-cli-config defaults")
7676
connectCmd.Flags().Bool("yes", false, "Accept safe api connect prompts without asking")
7777
apiCmd.AddCommand(connectCmd)
78+
apiCmd.AddCommand(&cobra.Command{
79+
Use: "configure <name> [url]",
80+
Short: "Explain the v1 api configure replacement",
81+
Hidden: true,
82+
DisableFlagParsing: true,
83+
RunE: func(cmd *cobra.Command, args []string) error {
84+
return newUsageError(c.apiConfigureMigrationError(args))
85+
},
86+
})
7887
apiCmd.AddCommand(&cobra.Command{
7988
Use: "inspect <name>",
8089
Short: "Print the config for a registered API as JSON",
@@ -94,6 +103,28 @@ func (c *CLI) addAPICommand(root *cobra.Command) {
94103
root.AddCommand(apiCmd)
95104
}
96105

106+
func (c *CLI) apiConfigureMigrationError(args []string) error {
107+
commandName := c.commandNameOrDefault()
108+
replacement := fmt.Sprintf(" %s api connect <name> <url>", commandName)
109+
if len(args) == 1 && !strings.HasPrefix(args[0], "-") {
110+
replacement = fmt.Sprintf(" %s api connect %s <url>", commandName, args[0])
111+
} else if len(args) >= 2 && !strings.HasPrefix(args[0], "-") && !strings.HasPrefix(args[1], "-") {
112+
replacement = fmt.Sprintf(" %s api connect %s %s", commandName, args[0], args[1])
113+
}
114+
return fmt.Errorf(`api configure was a Restish v1 command and is not available in v2.
115+
116+
Use api connect to register an API explicitly:
117+
118+
%s
119+
120+
In many cases replacing "configure" with "connect" is enough. If the v1
121+
command prompted for auth, profiles, or other defaults, connect first and then
122+
adjust the API with "restish api set".
123+
124+
Upgrade guide: https://rest.sh/docs/getting-started/upgrade-from-v1/
125+
Archived v1 docs: https://rest.sh/v1/`, replacement)
126+
}
127+
97128
// runAPIAuthLogout deletes the token cache entry for the named API+profile.
98129
func (c *CLI) runAPIAuthLogout(cmd *cobra.Command, args []string) error {
99130
authProfile, _ := cmd.Flags().GetString("auth-profile")

internal/cli/api_manage_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2641,7 +2641,6 @@ func TestAPIConnectAdversarialSpecShapesFailGracefully(t *testing.T) {
26412641
func TestAPIConnectRejectsRemovedCommandNames(t *testing.T) {
26422642
for _, args := range [][]string{
26432643
{"restish", "api", "add", "myapi", "https://api.example.com"},
2644-
{"restish", "api", "configure", "myapi", "https://api.example.com"},
26452644
{"restish", "api", "delete", "myapi"},
26462645
} {
26472646
c, _, _ := newTestCLI(t)
@@ -2653,6 +2652,20 @@ func TestAPIConnectRejectsRemovedCommandNames(t *testing.T) {
26532652
}
26542653
}
26552654

2655+
func TestAPIConfigureShowsV1MigrationMessage(t *testing.T) {
2656+
c, _, _ := newTestCLI(t)
2657+
err := c.Run([]string{"restish", "api", "configure", "myapi", "https://api.example.com"})
2658+
if err == nil {
2659+
t.Fatal("api configure should fail with a v1 migration message")
2660+
}
2661+
requireContains(t, err.Error(),
2662+
"api configure was a Restish v1 command",
2663+
"restish api connect myapi https://api.example.com",
2664+
"https://rest.sh/docs/getting-started/upgrade-from-v1/",
2665+
"https://rest.sh/v1/",
2666+
)
2667+
}
2668+
26562669
func TestAPIRemovePreservesJSONCComments(t *testing.T) {
26572670
cfgFile := writeAPIConfig(t, `{
26582671
"apis": {

site/content/en/docs/getting-started/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ locally.
3535

3636
## Existing v1 Users
3737

38-
If you already have Restish v1 config or plugins, read [Upgrade From v1](./upgrade-from-v1/) before editing config. The migration docs are kept out of the new-user happy path, but they are still important for existing setups.
38+
If you already have Restish v1 config or plugins, read [Upgrade From v1](./upgrade-from-v1/) before editing config. The migration docs are kept out of the new-user happy path, but they are still important for existing setups. The archived v1 docs remain available at [rest.sh/v1/](https://rest.sh/v1/).
3939

4040
## Related Pages
4141

site/content/en/docs/getting-started/install.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ Use `bash` or `fish` instead of `zsh` when that is your shell.
8989

9090
Restish v2 can migrate default-location v1 config on first run. Read
9191
[Upgrade From v1](../upgrade-from-v1/) before editing config or replacing
92-
plugins.
92+
plugins. The archived v1 documentation remains available at
93+
[rest.sh/v1/](https://rest.sh/v1/) for teams that need to compare old commands during a
94+
migration.
9395

9496
## Next Step
9597

@@ -104,3 +106,4 @@ next to see the major workflows before connecting your own APIs.
104106
- [Shell Setup](../shell-setup/)
105107
- [Development Setup](/docs/contributing/development-setup/)
106108
- [Upgrade From v1](../upgrade-from-v1/)
109+
- [Archived v1 Docs](https://rest.sh/v1/)

site/content/en/docs/getting-started/upgrade-from-v1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ aliases:
99

1010
This page is the shortest path for existing Restish v1 users who want to know
1111
what changed, what is preserved automatically, and what needs a manual update.
12+
The archived v1 documentation remains available at [rest.sh/v1/](https://rest.sh/v1/) for
13+
old links, internal runbooks, and side-by-side migration checks.
1214

1315
## What To Expect
1416

@@ -115,6 +117,7 @@ Use this as the fast lookup table when muscle memory collides with v2.
115117
| ------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------- |
116118
| `apis.json` | `restish.json` | API config now lives under top-level `apis` |
117119
| `config.json` | `restish.json` | v2 uses one config file |
120+
| `restish api configure <name> <url>` | `restish api connect <name> <url>` | v2 prints a migration hint for `api configure` |
118121
| `restish api edit` | `restish config edit` | Config editing moved under `config` |
119122
| old interactive API setup | `restish api connect <name> <url>` | v2 expects the base URL explicitly |
120123
| n/a | `restish api connect <name> <url> 'path:value'` | fast one-shot registration with shorthand expressions |
@@ -185,3 +188,4 @@ restish config edit
185188
- [Tour of Restish](../tour/)
186189
- [Config](/docs/reference/config/)
187190
- [Install And Use Plugins](/docs/plugins/install-and-use/)
191+
- [Archived v1 Docs](https://rest.sh/v1/)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
<script src='{{ "js/prism-restish.js" | relURL }}'></script>
22
<script src='{{ "js/restish-playground.js" | relURL }}'></script>
3+
<script>
4+
(function () {
5+
if (window.location.pathname === "/" && window.location.hash.indexOf("#/") === 0) {
6+
window.location.replace("/v1/" + window.location.hash);
7+
}
8+
}());
9+
</script>

site/static/v1/.markdownlint.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
default: true
2+
3+
# no-hard-tabs
4+
MD010: false
5+
6+
# line-length
7+
MD013: false
8+
9+
# commands-show-output
10+
MD014: false
11+
12+
# no-inline-html
13+
MD033: false

site/static/v1/.nojekyll

Whitespace-only changes.

site/static/v1/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
![Restish Logo](https://user-images.githubusercontent.com/106826/82109918-ec5b2300-96ee-11ea-9af0-8515329d5965.png)
2+
3+
<div style="text-align: center;">
4+
5+
[![Works With Restish](https://img.shields.io/badge/Works%20With-Restish-ff5f87)](https://rest.sh/) [![User Guide](https://img.shields.io/badge/Docs-Guide-5fafd7)](https://rest.sh/v1/#/guide) [![CI](https://github.com/rest-sh/restish/workflows/CI/badge.svg?branch=main)](https://github.com/rest-sh/restish/actions?query=workflow%3ACI+branch%3Amain++) [![codecov](https://codecov.io/gh/rest-sh/restish/branch/main/graph/badge.svg)](https://codecov.io/gh/rest-sh/restish) [![Docs](https://img.shields.io/badge/godoc-reference-5fafd7)](https://pkg.go.dev/github.com/rest-sh/restish?tab=subdirectories) [![Go Report Card](https://goreportcard.com/badge/github.com/rest-sh/restish)](https://goreportcard.com/report/github.com/rest-sh/restish) [![GitHub Likes](https://img.shields.io/github/stars/rest-sh/restish?style=social)](https://github.com/rest-sh/restish)
6+
7+
</div>
8+
9+
[Restish](https://rest.sh/) is a CLI for interacting with [REST](https://apisyouwonthate.com/blog/rest-and-hypermedia-in-2019)-ish HTTP APIs with some nice features built-in, like always having the latest API resources, fields, and operations available when they go live on the API without needing to install or update anything.
10+
11+
## Why use this?
12+
13+
Every API deserves a CLI for quick access and for power users to script against the service. Building CLIs from scratch is a pain. Restish provides one tool your users can install that just works for multiple APIs and is always up to date, because the interface is defined by the server. See how it [compares](./comparison.md) to cURL and HTTPie.
14+
15+
## Getting started
16+
17+
Start with the [guide](./guide.md) to learn how to install and configure Restish as well as getting an overview of all of its features.
18+
19+
## Features
20+
21+
- HTTP/2 ([RFC 7540](https://tools.ietf.org/html/rfc7540)) with TLS by _default_ with fallback to HTTP/1.1
22+
- Generic HEAD/GET/POST/PUT/PATCH/DELETE verbs like `curl` or [HTTPie](https://httpie.org/)
23+
- Generated commands for CLI operations, e.g. `restish my-api list-users`
24+
- Automatically discovers API descriptions
25+
- [RFC 8631](https://tools.ietf.org/html/rfc8631) `service-desc` link relation
26+
- [RFC 5988](https://tools.ietf.org/html/rfc5988#section-6.2.2) `describedby` link relation
27+
- Supported formats
28+
- OpenAPI [3.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) / [3.1](https://spec.openapis.org/oas/v3.1.0.html) and [JSON Schema](https://json-schema.org/)
29+
- Automatic configuration of API auth if advertised by the API
30+
- Shell command completion for Bash, Fish, Zsh, Powershell
31+
- Automatic pagination of resource collections via [RFC 5988](https://tools.ietf.org/html/rfc5988) `prev` and `next` hypermedia links
32+
- API endpoint-based auth built-in with support for profiles:
33+
- HTTP Basic
34+
- API key via header or query param
35+
- OAuth2 client credentials flow (machine-to-machine, [RFC 6749](https://tools.ietf.org/html/rfc6749))
36+
- OAuth2 authorization code (with PKCE [RFC 7636](https://tools.ietf.org/html/rfc7636)) flow
37+
- Content negotiation, decoding & unmarshalling built-in:
38+
- JSON ([RFC 8259](https://tools.ietf.org/html/rfc8259), <https://www.json.org/>)
39+
- YAML (<https://yaml.org/>)
40+
- CBOR ([RFC 7049](https://tools.ietf.org/html/rfc7049), <http://cbor.io/>)
41+
- MessagePack (<https://msgpack.org/>)
42+
- Amazon Ion (<http://amzn.github.io/ion-docs/>)
43+
- Gzip ([RFC 1952](https://tools.ietf.org/html/rfc1952)), Deflate ([RFC 1951](https://datatracker.ietf.org/doc/html/rfc1951)), and Brotli ([RFC 7932](https://tools.ietf.org/html/rfc7932)) content encoding
44+
- Automatic retries with support for [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) and `X-Retry-In` headers when APIs are rate-limited.
45+
- Standardized [hypermedia](https://smartbear.com/learn/api-design/what-is-hypermedia/) parsing into queryable/followable response links:
46+
- HTTP Link relation headers ([RFC 5988](https://tools.ietf.org/html/rfc5988#section-6.2.2))
47+
- [HAL](http://stateless.co/hal_specification.html)
48+
- [Siren](https://github.com/kevinswiber/siren)
49+
- [Terrifically Simple JSON](https://github.com/mpnally/Terrifically-Simple-JSON)
50+
- [JSON:API](https://jsonapi.org/)
51+
- Local caching that respects [RFC 7234](https://tools.ietf.org/html/rfc7234) `Cache-Control` and `Expires` headers
52+
- Client-side bulk resource management (like git for API resources)
53+
- CLI [shorthand](https://github.com/danielgtaylor/openapi-cli-generator/tree/master/shorthand#cli-shorthand-syntax) for structured data input (e.g. for JSON)
54+
- [Shorthand query](https://github.com/danielgtaylor/shorthand#querying) response filtering & projection
55+
- Colorized prettified readable output
56+
- Fast native zero-dependency binary
57+
58+
## Articles
59+
60+
- [A CLI for REST APIs](https://dev.to/danielgtaylor/a-cli-for-rest-apis-part-1-104b)
61+
- [Mapping OpenAPI to the CLI](https://dev.to/danielgtaylor/mapping-openapi-to-the-cli-37pb)

site/static/v1/_sidebar.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- [Home](./ "Restish")
2+
- [Guide](guide.md "Restish User Guide")
3+
- [Comparison](comparison.md "Comparison")
4+
- [Configuration](configuration.md "Configuring Restish")
5+
- [OpenAPI](openapi.md "OpenAPI 3 & Restish")
6+
- [Input](input.md "Restish Input")
7+
- [CLI Shorthand](shorthand.md "CLI Shorthand")
8+
- [Output](output.md "Restish Output")
9+
- [Retries & Timeouts](retries.md "Retries & Timeouts")
10+
- [Hypermedia](hypermedia.md "Hypermedia Linking in Restish")
11+
- [Bulk Management](bulk.md "Bulk Resource Management")

0 commit comments

Comments
 (0)