Skip to content

feat: add api command#1457

Open
phm07 wants to merge 7 commits into
mainfrom
api-command
Open

feat: add api command#1457
phm07 wants to merge 7 commits into
mainfrom
api-command

Conversation

@phm07

@phm07 phm07 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

This PR adds a command that allows users to directly interact with the API.

Closes #1448

@phm07 phm07 self-assigned this Jul 17, 2026
@phm07
phm07 requested a review from a team as a code owner July 17, 2026 09:24
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 17.46032% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.81%. Comparing base (6f2fcae) to head (d2e8e8b).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
internal/cmd/api/api.go 18.51% 44 Missing ⚠️
internal/hcapi2/client.go 0.00% 4 Missing ⚠️
internal/hcapi2/mock/client.go 0.00% 4 Missing ⚠️
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     
Flag Coverage Δ
e2e 51.32% <18.64%> (-0.04%) ⬇️
unit 67.69% <17.46%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread internal/cmd/api/api.go
var ApiCmd = base.Cmd{
BaseCobraCommand: func(client hcapi2.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "api [options] <path>",

@lukasmetzner lukasmetzner Jul 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/cmd/api/api.go Outdated
@phm07

phm07 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

We also need to think about how to handle switching between the api.hetzner.cloud and api.hetzner.com endpoints.

@nachtjasmin

Copy link
Copy Markdown
Contributor

A minor user experience nitpick: Right now, the command requires me to prefix all paths with the forward slash /. It'd be nice if this could be added automatically to allow calls like hcloud api fancy_product/123 instead of hcloud api /fancy_product/123. ^^

Comment thread internal/cmd/api/api.go Outdated
if err := json.Indent(&formatted, respBody, "", " "); err != nil {
return err
}
cmd.Print(formatted.String())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/cmd/api/api.go
Comment thread internal/cmd/api/api.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support generic hcloud api subcommand

4 participants