Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/hcloud
/dist
/bats
/completions
/manpages
/cmd/hcloud/hcloud
hcloud_cli.p12
coverage.txt
70 changes: 58 additions & 12 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: 2
before:
hooks:
- go mod tidy
- ./scripts/completions.sh
- go run scripts/manpages.go

builds:
- <<: &build_defaults
Expand All @@ -17,13 +19,26 @@ builds:
env:
- CGO_ENABLED=0

id: hcloud-build
goos: [freebsd, windows, linux]
id: hcloud-build-linux-main
goos: [linux]
goarch: [amd64, arm64]

- <<: *build_defaults
id: hcloud-build-linux-other
goos: [ linux ]
goarch: [ arm, "386" ]
goarm: [ "6", "7" ]

- <<: *build_defaults
id: hcloud-build-freebsd
goos: [ freebsd ]
goarch: [amd64, arm, arm64, "386"]
goarm: ["6", "7"]
ignore:
- goos: windows
goarch: arm

- <<: *build_defaults
id: hcloud-build-windows
goos: [ windows ]
goarch: [ amd64, arm64, "386" ]

- <<: *build_defaults
id: hcloud-build-darwin
Expand All @@ -37,9 +52,46 @@ builds:
- cmd: bash -c 'quill sign-and-notarize "{{ .Path }}" --dry-run={{ .IsSnapshot }} --ad-hoc={{ .IsSnapshot }} || touch sign-and-notarize.error'
output: true

nfpms:
- id: default
file_name_template: "{{ .ConventionalFileName }}"
package_name: hcloud-cli
ids: [hcloud-build-linux-main]
provides: [hcloud]
vendor: Hetzner Cloud GmbH
homepage: https://github.com/hetznercloud/cli
maintainer: Hetzner Cloud GmbH <support-cloud@hetzner.com>
formats:
- deb
- rpm
description: A command-line interface for Hetzner Cloud
license: MIT

contents:
- src: ./completions/hcloud.bash
dst: /usr/share/bash-completion/completions/hcloud
file_info:
mode: 0644
- src: ./completions/hcloud.fish
dst: /usr/share/fish/vendor_completions.d/hcloud.fish
file_info:
mode: 0644
- src: ./completions/hcloud.zsh
dst: /usr/share/zsh/vendor-completions/_hcloud
file_info:
mode: 0644
- src: ./LICENSE
dst: /usr/share/doc/hcloud/license
file_info:
mode: 0644
- src: ./manpages/*
dst: /usr/share/man/man1/
file_info:
mode: 0644

kos:
- id: container-images
build: hcloud-build
build: hcloud-build-linux-main
main: ./cmd/hcloud/
repositories:
- hetznercloud/cli
Expand Down Expand Up @@ -71,9 +123,6 @@ signs:
- artifacts: all
signature: ${artifact}.sig
id: hcloud-sign
ids:
- hcloud-build
- hcloud-build-darwin
args:
- --batch
- --local-user=github-bot@hetzner-cloud.de
Expand All @@ -84,9 +133,6 @@ signs:

archives:
- id: hcloud-archive
ids:
- hcloud-build
- hcloud-build-darwin
name_template: "{{ .Binary }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

format_overrides:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.25.7
require (
github.com/BurntSushi/toml v1.6.0
github.com/cheggaaa/pb/v3 v3.1.7
github.com/cpuguy83/go-md2man/v2 v2.0.7
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.18.0
github.com/fatih/structs v1.1.0
Expand All @@ -33,7 +34,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bool64/shared v0.1.6 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cheggaaa/pb/v3 v3.1.7 h1:2FsIW307kt7A/rz/ZI2lvPO+v3wKazzE4K/0LtTWsOI=
github.com/cheggaaa/pb/v3 v3.1.7/go.mod h1:/Ji89zfVPeC/u5j8ukD0MBPHt2bzTYp74lQ7KlgFWTQ=
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down
7 changes: 7 additions & 0 deletions scripts/completions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e
rm -rf completions
mkdir completions
for sh in bash zsh fish; do
go run ./cmd/hcloud completion "$sh" >"completions/hcloud.$sh"
done
41 changes: 41 additions & 0 deletions scripts/manpages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"context"
"fmt"
"log"
"os"
// We import md2man here so we can keep it up to date in go.mod
_ "github.com/cpuguy83/go-md2man/v2/md2man"
Copy link
Member

Choose a reason for hiding this comment

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

We can already manually bump the version, even if the dependency is marked as indirect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But renovate will only pick up direct dependencies, right? Also it would be nice to have it documented so that it doesn't randomly break in the future and nobody knows/notices.


"github.com/spf13/cobra/doc"

"github.com/hetznercloud/cli/internal/cli"
"github.com/hetznercloud/cli/internal/state"
"github.com/hetznercloud/cli/internal/state/config"
"github.com/hetznercloud/cli/internal/version"
)

const directory = "./manpages"
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about running this and completions.sh as part of go generate and dump the generated files in dist/{manpages,completions}?

Related to the above, is there a reason to put these two files and internal/scripts/generate_docs.go in separate places? They feel pretty related.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it could use some clean up, I'll do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two things:

  • Goreleaser requires dist/ to be empty, even after the before hooks. So we probably can't (easily) put our generated files there
  • Why do we want to go generate the manpages and completions? We don't want to commit them into the repository and they are only needed for a release anyway. Only generating manpages and completions is pretty fast, but running a full go generate before each release would be slow.


func main() {
//nolint:gosec
if err := os.MkdirAll(directory, 0755); err != nil {
log.Fatal(err)
}

ctx := context.Background()
ctx = context.WithValue(ctx, state.ContextKeyMarkdownTables{}, true)
s, _ := state.New(ctx, config.New())
rootCommand := cli.NewRootCommand(s)

err := doc.GenManTree(rootCommand, &doc.GenManHeader{
Source: version.Version,
Manual: "CLI for Hetzner API",
}, directory)

if err != nil {
log.Fatal(err)
}
fmt.Println("Man pages generated successfully")
}
Loading