feat: add api command#1457
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1457 +/- ##
==========================================
- Coverage 72.89% 72.81% -0.08%
==========================================
Files 300 301 +1
Lines 11127 11143 +16
==========================================
+ Hits 8111 8114 +3
- Misses 2118 2135 +17
+ Partials 898 894 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| var ApiCmd = base.Cmd{ | ||
| BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "api [options] <path>", |
There was a problem hiding this comment.
Not sure if this is relevant for the first iteration, but what about setting Content-Type and defaulting to json?
edit: we already set this in hcloud-go, so we would not need to default here.
|
We also need to think about how to handle switching between the |
|
A minor user experience nitpick: Right now, the command requires me to prefix all paths with the forward slash |
| if err := json.Indent(&formatted, respBody, "", " "); err != nil { | ||
| return err | ||
| } | ||
| cmd.Print(formatted.String()) |
There was a problem hiding this comment.
This prints the formatted string without a final newline. In some shells this causes the prompt to be printed on the same line as the closing }. zsh shows a % after the closing } by default.
It looks like jq prints a final newline after formatted output. I would suggest we do the same, but maybe I am overlooking some drawbacks.
This PR adds a command that allows users to directly interact with the API.
Closes #1448