diff --git a/.golangci.yml b/.golangci.yml index 85cbd75b..1532b8c6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -56,7 +56,7 @@ linters: # - errcheck - exhaustive # - gocritic - # - golint + - golint - gci - gomodguard - gosec diff --git a/internal/cli/root.go b/internal/cli/root.go index b3751ae4..b6ecd2a0 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewRootCommand creates the root command. func NewRootCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "hcloud", diff --git a/internal/cmd/all/all.go b/internal/cmd/all/all.go index 87182076..11281b0f 100644 --- a/internal/cmd/all/all.go +++ b/internal/cmd/all/all.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud all' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "all", diff --git a/internal/cmd/all/list.go b/internal/cmd/all/list.go index c45e65bf..0ac0d08a 100644 --- a/internal/cmd/all/list.go +++ b/internal/cmd/all/list.go @@ -41,6 +41,7 @@ var allCmds = []base.ListCmd{ sshkey.ListCmd, } +// ListCmd is the command for 'hcloud all list' var ListCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { diff --git a/internal/cmd/certificate/certificate.go b/internal/cmd/certificate/certificate.go index 121c09d0..7ea751c0 100644 --- a/internal/cmd/certificate/certificate.go +++ b/internal/cmd/certificate/certificate.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud certificate' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "certificate", diff --git a/internal/cmd/certificate/create.go b/internal/cmd/certificate/create.go index 3e40ec95..c22e1d76 100644 --- a/internal/cmd/certificate/create.go +++ b/internal/cmd/certificate/create.go @@ -14,6 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateCmd is the command for 'hcloud certificate create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/certificate/delete.go b/internal/cmd/certificate/delete.go index ce9f8209..94ed9269 100644 --- a/internal/cmd/certificate/delete.go +++ b/internal/cmd/certificate/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud certificate delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "certificate", ResourceNamePlural: "certificates", diff --git a/internal/cmd/certificate/describe.go b/internal/cmd/certificate/describe.go index 6573cbc2..31ec2898 100644 --- a/internal/cmd/certificate/describe.go +++ b/internal/cmd/certificate/describe.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud certificate describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "certificate", ShortDescription: "Describe an certificate", diff --git a/internal/cmd/certificate/labels.go b/internal/cmd/certificate/labels.go index 60d1305d..c992b91b 100644 --- a/internal/cmd/certificate/labels.go +++ b/internal/cmd/certificate/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud certificate add-label' and 'hcloud certificate remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "certificate", ShortDescriptionAdd: "Add a label to an certificate", diff --git a/internal/cmd/certificate/list.go b/internal/cmd/certificate/list.go index 58005e35..1e2f340f 100644 --- a/internal/cmd/certificate/list.go +++ b/internal/cmd/certificate/list.go @@ -16,6 +16,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud certificate list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Certificates", JSONKeyGetByName: "certificates", diff --git a/internal/cmd/certificate/update.go b/internal/cmd/certificate/update.go index 5d347d04..109d7f15 100644 --- a/internal/cmd/certificate/update.go +++ b/internal/cmd/certificate/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud certificate update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "certificate", ShortDescription: "Update a certificate", diff --git a/internal/cmd/completion/completion.go b/internal/cmd/completion/completion.go index e068adaa..54c3ba78 100644 --- a/internal/cmd/completion/completion.go +++ b/internal/cmd/completion/completion.go @@ -32,6 +32,7 @@ import ( // source <(hcloud completion zsh)` // ) +// NewCommand creates the command for 'hcloud completion' func NewCommand(_ state.State) *cobra.Command { cmd := &cobra.Command{ Use: "completion ", diff --git a/internal/cmd/config/add.go b/internal/cmd/config/add.go index 98051899..8d1cc56a 100644 --- a/internal/cmd/config/add.go +++ b/internal/cmd/config/add.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewAddCommand creates the command for 'hcloud config add' func NewAddCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "add ...", diff --git a/internal/cmd/config/config.go b/internal/cmd/config/config.go index 3aac6d82..973c8890 100644 --- a/internal/cmd/config/config.go +++ b/internal/cmd/config/config.go @@ -1,6 +1,7 @@ package config import ( + // embed is used to embed the help text into the binary _ "embed" "github.com/spf13/cobra" @@ -15,6 +16,7 @@ var nonPreferenceOptions string //go:embed helptext/preferences.txt var preferenceOptions string +// NewCommand creates the command for 'hcloud config' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "config", diff --git a/internal/cmd/config/get.go b/internal/cmd/config/get.go index b93ed950..d6f3fde4 100644 --- a/internal/cmd/config/get.go +++ b/internal/cmd/config/get.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewGetCommand creates the command for 'hcloud config get' func NewGetCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "get ", diff --git a/internal/cmd/config/list.go b/internal/cmd/config/list.go index 0298ba2a..5630904e 100644 --- a/internal/cmd/config/list.go +++ b/internal/cmd/config/list.go @@ -14,6 +14,7 @@ import ( var outputColumns = []string{"key", "value"} +// NewListCommand creates the command for 'hcloud config list'. func NewListCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "list", diff --git a/internal/cmd/config/remove.go b/internal/cmd/config/remove.go index fab0a84f..7d026c1e 100644 --- a/internal/cmd/config/remove.go +++ b/internal/cmd/config/remove.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewRemoveCommand creates a new command for 'hcloud config remove' func NewRemoveCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "remove ...", diff --git a/internal/cmd/config/set.go b/internal/cmd/config/set.go index 8f2e8eae..600c5f73 100644 --- a/internal/cmd/config/set.go +++ b/internal/cmd/config/set.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewSetCommand creates a new command for 'hcloud config set' func NewSetCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "set ...", diff --git a/internal/cmd/config/unset.go b/internal/cmd/config/unset.go index f24f54b5..c7f182cb 100644 --- a/internal/cmd/config/unset.go +++ b/internal/cmd/config/unset.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewUnsetCommand creates a new command for 'hcloud config unset' func NewUnsetCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "unset ", diff --git a/internal/cmd/context/active.go b/internal/cmd/context/active.go index 45f34f5e..3b0d877b 100644 --- a/internal/cmd/context/active.go +++ b/internal/cmd/context/active.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewActiveCommand creates the command for 'hcloud context active' func NewActiveCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "active", diff --git a/internal/cmd/context/context.go b/internal/cmd/context/context.go index 964a6a05..76cd8034 100644 --- a/internal/cmd/context/context.go +++ b/internal/cmd/context/context.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud context' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "context", diff --git a/internal/cmd/context/create.go b/internal/cmd/context/create.go index 7f2048cc..aaa3f6ec 100644 --- a/internal/cmd/context/create.go +++ b/internal/cmd/context/create.go @@ -15,6 +15,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewCreateCommand creates the command for 'hcloud context create' func NewCreateCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "create ", diff --git a/internal/cmd/context/delete.go b/internal/cmd/context/delete.go index 4aabf479..b5b74270 100644 --- a/internal/cmd/context/delete.go +++ b/internal/cmd/context/delete.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewDeleteCommand creates the command for 'hcloud context delete' func NewDeleteCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "delete ", diff --git a/internal/cmd/context/list.go b/internal/cmd/context/list.go index 43f3a465..45cba5a8 100644 --- a/internal/cmd/context/list.go +++ b/internal/cmd/context/list.go @@ -14,6 +14,7 @@ type presentation struct { Active string } +// NewListCommand creates the command for 'hcloud context list' func NewListCommand(s state.State) *cobra.Command { cols := newListOutputTable().Columns() cmd := &cobra.Command{ diff --git a/internal/cmd/context/use.go b/internal/cmd/context/use.go index 4a765349..cd2e9458 100644 --- a/internal/cmd/context/use.go +++ b/internal/cmd/context/use.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// NewUseCommand creates the command for 'hcloud context use' func NewUseCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "use ", diff --git a/internal/cmd/datacenter/datacenter.go b/internal/cmd/datacenter/datacenter.go index 3e21df03..84e72450 100644 --- a/internal/cmd/datacenter/datacenter.go +++ b/internal/cmd/datacenter/datacenter.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud datacenter' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "datacenter", diff --git a/internal/cmd/datacenter/describe.go b/internal/cmd/datacenter/describe.go index 132dec36..c094dfbf 100644 --- a/internal/cmd/datacenter/describe.go +++ b/internal/cmd/datacenter/describe.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud datacenter describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "datacenter", ShortDescription: "Describe an datacenter", diff --git a/internal/cmd/datacenter/list.go b/internal/cmd/datacenter/list.go index a01355e7..47b76a3d 100644 --- a/internal/cmd/datacenter/list.go +++ b/internal/cmd/datacenter/list.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud datacenter list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Datacenters", JSONKeyGetByName: "datacenters", diff --git a/internal/cmd/firewall/add_rule.go b/internal/cmd/firewall/add_rule.go index ec9ae088..29176c53 100644 --- a/internal/cmd/firewall/add_rule.go +++ b/internal/cmd/firewall/add_rule.go @@ -14,6 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AddRuleCmd is the command for 'hcloud firewall add-rule' var AddRuleCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/firewall/apply_to_resource.go b/internal/cmd/firewall/apply_to_resource.go index e0c7034e..494d0670 100644 --- a/internal/cmd/firewall/apply_to_resource.go +++ b/internal/cmd/firewall/apply_to_resource.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ApplyToResourceCmd is the command for 'hcloud firewall apply-to-resource' var ApplyToResourceCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/firewall/create.go b/internal/cmd/firewall/create.go index 7bb2c041..6bad79b7 100644 --- a/internal/cmd/firewall/create.go +++ b/internal/cmd/firewall/create.go @@ -17,6 +17,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// CreateCmd is the command for 'hcloud firewall create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/firewall/delete.go b/internal/cmd/firewall/delete.go index adda6827..70320439 100644 --- a/internal/cmd/firewall/delete.go +++ b/internal/cmd/firewall/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud firewall delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "firewall", ResourceNamePlural: "firewalls", diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go index 4c614a9a..e3e3f488 100644 --- a/internal/cmd/firewall/delete_rule.go +++ b/internal/cmd/firewall/delete_rule.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteRuleCmd is the command for 'hcloud firewall delete-rule' var DeleteRuleCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/firewall/describe.go b/internal/cmd/firewall/describe.go index bdcf3ab9..957e3529 100644 --- a/internal/cmd/firewall/describe.go +++ b/internal/cmd/firewall/describe.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud firewall describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "firewall", ShortDescription: "Describe an firewall", diff --git a/internal/cmd/firewall/firewall.go b/internal/cmd/firewall/firewall.go index 393d97a5..2f3b63d4 100644 --- a/internal/cmd/firewall/firewall.go +++ b/internal/cmd/firewall/firewall.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud firewall' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "firewall", diff --git a/internal/cmd/firewall/labels.go b/internal/cmd/firewall/labels.go index 4c1f9883..8a70cd74 100644 --- a/internal/cmd/firewall/labels.go +++ b/internal/cmd/firewall/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud firewall add-label' and 'hcloud firewall remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "firewall", ShortDescriptionAdd: "Add a label to an firewall", diff --git a/internal/cmd/firewall/list.go b/internal/cmd/firewall/list.go index ae7a96e2..b7dd1402 100644 --- a/internal/cmd/firewall/list.go +++ b/internal/cmd/firewall/list.go @@ -14,6 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud firewall list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Firewalls", JSONKeyGetByName: "firewalls", diff --git a/internal/cmd/firewall/remove_from_resource.go b/internal/cmd/firewall/remove_from_resource.go index c728b419..64607828 100644 --- a/internal/cmd/firewall/remove_from_resource.go +++ b/internal/cmd/firewall/remove_from_resource.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// RemoveFromResourceCmd is the command for 'hcloud firewall remove-from-resource' var RemoveFromResourceCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/firewall/replace_rules.go b/internal/cmd/firewall/replace_rules.go index fba2b066..fbb90989 100644 --- a/internal/cmd/firewall/replace_rules.go +++ b/internal/cmd/firewall/replace_rules.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ReplaceRulesCmd is the command for 'hcloud firewall replace-rules' var ReplaceRulesCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/firewall/update.go b/internal/cmd/firewall/update.go index 18cf7fbc..0a341798 100644 --- a/internal/cmd/firewall/update.go +++ b/internal/cmd/firewall/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud firewall update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Firewall", ShortDescription: "Update a firewall", diff --git a/internal/cmd/firewall/validation.go b/internal/cmd/firewall/validation.go index 0ae7b73f..694870ec 100644 --- a/internal/cmd/firewall/validation.go +++ b/internal/cmd/firewall/validation.go @@ -5,6 +5,7 @@ import ( "net" ) +// ValidateFirewallIP checks if the given IP is a valid IP address or CIDR block and returns the net.IPNet func ValidateFirewallIP(ip string) (*net.IPNet, error) { i, n, err := net.ParseCIDR(ip) if err != nil { diff --git a/internal/cmd/firewall/validation_test.go b/internal/cmd/firewall/validation_test.go index d24038a6..c36209cb 100644 --- a/internal/cmd/firewall/validation_test.go +++ b/internal/cmd/firewall/validation_test.go @@ -36,7 +36,7 @@ func TestValidateFirewallIP(t *testing.T) { { name: "Missing CIDR notation (IPv6)", ip: "fe80::", - //nolint:revive + //nolint:revive,golint err: fmt.Errorf("invalid CIDR address: fe80::"), }, { diff --git a/internal/cmd/floatingip/assign.go b/internal/cmd/floatingip/assign.go index 6fe41a54..a0286d29 100644 --- a/internal/cmd/floatingip/assign.go +++ b/internal/cmd/floatingip/assign.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// AssignCmd is the command for 'hcloud floating-ip assign' var AssignCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/floatingip/create.go b/internal/cmd/floatingip/create.go index aee59f02..359d1c74 100644 --- a/internal/cmd/floatingip/create.go +++ b/internal/cmd/floatingip/create.go @@ -14,6 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateCmd is the command for 'hcloud floating-ip create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/floatingip/delete.go b/internal/cmd/floatingip/delete.go index 3ae3ffba..2c655bcd 100644 --- a/internal/cmd/floatingip/delete.go +++ b/internal/cmd/floatingip/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud floating-ip delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "Floating IP", ResourceNamePlural: "Floating IPs", diff --git a/internal/cmd/floatingip/describe.go b/internal/cmd/floatingip/describe.go index 0bfae839..ddb542f2 100644 --- a/internal/cmd/floatingip/describe.go +++ b/internal/cmd/floatingip/describe.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud floating-ip describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "Floating IP", ShortDescription: "Describe an Floating IP", diff --git a/internal/cmd/floatingip/disable_protection.go b/internal/cmd/floatingip/disable_protection.go index 6634eeed..0761a6e2 100644 --- a/internal/cmd/floatingip/disable_protection.go +++ b/internal/cmd/floatingip/disable_protection.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableProtectionCmd is the command for 'hcloud floating-ip disable-protection' var DisableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/floatingip/enable_protection.go b/internal/cmd/floatingip/enable_protection.go index 5211768c..0bf04795 100644 --- a/internal/cmd/floatingip/enable_protection.go +++ b/internal/cmd/floatingip/enable_protection.go @@ -55,6 +55,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } +// EnableProtectionCmd is the command for 'hcloud floating-ip enable-protection' var EnableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/floatingip/floatingip.go b/internal/cmd/floatingip/floatingip.go index 67d6e636..50ec63b6 100644 --- a/internal/cmd/floatingip/floatingip.go +++ b/internal/cmd/floatingip/floatingip.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud floating-ip' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "floating-ip", diff --git a/internal/cmd/floatingip/labels.go b/internal/cmd/floatingip/labels.go index a63a7598..cfbc4e92 100644 --- a/internal/cmd/floatingip/labels.go +++ b/internal/cmd/floatingip/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud floating-ip add-label' and 'hcloud floating-ip remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "Floating IP", ShortDescriptionAdd: "Add a label to an Floating IP", diff --git a/internal/cmd/floatingip/list.go b/internal/cmd/floatingip/list.go index a73ed540..9cfbdd4d 100644 --- a/internal/cmd/floatingip/list.go +++ b/internal/cmd/floatingip/list.go @@ -17,6 +17,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud floating-ip list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Floating IPs", JSONKeyGetByName: "floating_ips", diff --git a/internal/cmd/floatingip/set_rdns.go b/internal/cmd/floatingip/set_rdns.go index b1d387a8..98ca872a 100644 --- a/internal/cmd/floatingip/set_rdns.go +++ b/internal/cmd/floatingip/set_rdns.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// SetRDNSCmd is the command for 'hcloud floating-ip set-rdns' var SetRDNSCmd = base.SetRdnsCmd{ ResourceNameSingular: "Floating IP", ShortDescription: "Change reverse DNS of a Floating IP", diff --git a/internal/cmd/floatingip/unassign.go b/internal/cmd/floatingip/unassign.go index 3621c20b..5ce0c1ed 100644 --- a/internal/cmd/floatingip/unassign.go +++ b/internal/cmd/floatingip/unassign.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// UnassignCmd is the command for 'hcloud floating-ip unassign' var UnassignCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/floatingip/update.go b/internal/cmd/floatingip/update.go index 4a0175a2..3b1a1c09 100644 --- a/internal/cmd/floatingip/update.go +++ b/internal/cmd/floatingip/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud floating-ip update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Floating IP", ShortDescription: "Update a Floating IP", diff --git a/internal/cmd/image/delete.go b/internal/cmd/image/delete.go index 77066e76..15b050f6 100644 --- a/internal/cmd/image/delete.go +++ b/internal/cmd/image/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud image delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "image", ResourceNamePlural: "images", diff --git a/internal/cmd/image/describe.go b/internal/cmd/image/describe.go index 327e22fa..1cc705a2 100644 --- a/internal/cmd/image/describe.go +++ b/internal/cmd/image/describe.go @@ -15,6 +15,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud image describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "image", ShortDescription: "Describe an image", diff --git a/internal/cmd/image/disable_protection.go b/internal/cmd/image/disable_protection.go index 26ae7fc1..fcc18056 100644 --- a/internal/cmd/image/disable_protection.go +++ b/internal/cmd/image/disable_protection.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DisableProtectionCmd is the command for 'hcloud image disable-protection' var DisableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/image/enable_protection.go b/internal/cmd/image/enable_protection.go index ffc76c4d..9648484e 100644 --- a/internal/cmd/image/enable_protection.go +++ b/internal/cmd/image/enable_protection.go @@ -57,6 +57,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } +// EnableProtectionCmd is the command for 'hcloud image enable-protection' var EnableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { diff --git a/internal/cmd/image/image.go b/internal/cmd/image/image.go index 028468de..298d67f0 100644 --- a/internal/cmd/image/image.go +++ b/internal/cmd/image/image.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud image' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "image", diff --git a/internal/cmd/image/labels.go b/internal/cmd/image/labels.go index e1ae3849..b7fd5196 100644 --- a/internal/cmd/image/labels.go +++ b/internal/cmd/image/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud image add-label' and 'hcloud image remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "image", ShortDescriptionAdd: "Add a label to an image", diff --git a/internal/cmd/image/list.go b/internal/cmd/image/list.go index 88fdcf8c..51451e9c 100644 --- a/internal/cmd/image/list.go +++ b/internal/cmd/image/list.go @@ -20,6 +20,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud image list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Images", JSONKeyGetByName: "images", diff --git a/internal/cmd/image/update.go b/internal/cmd/image/update.go index 75e2562f..bf690209 100644 --- a/internal/cmd/image/update.go +++ b/internal/cmd/image/update.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud image update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Image", ShortDescription: "Update an image", diff --git a/internal/cmd/iso/describe.go b/internal/cmd/iso/describe.go index f14b3d84..9a63b438 100644 --- a/internal/cmd/iso/describe.go +++ b/internal/cmd/iso/describe.go @@ -10,7 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -// DescribeCmd defines a command for describing a iso. +// DescribeCmd is the command for 'hcloud iso describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "iso", ShortDescription: "Describe a iso", diff --git a/internal/cmd/iso/iso.go b/internal/cmd/iso/iso.go index ea51f822..f69f35a1 100644 --- a/internal/cmd/iso/iso.go +++ b/internal/cmd/iso/iso.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud iso' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "iso", diff --git a/internal/cmd/iso/list.go b/internal/cmd/iso/list.go index 695da24c..cc43d845 100644 --- a/internal/cmd/iso/list.go +++ b/internal/cmd/iso/list.go @@ -17,6 +17,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud iso list' var ListCmd = base.ListCmd{ ResourceNamePlural: "ISOs", JSONKeyGetByName: "isos", diff --git a/internal/cmd/loadbalancer/add_service.go b/internal/cmd/loadbalancer/add_service.go index bc067ebb..35e95b93 100644 --- a/internal/cmd/loadbalancer/add_service.go +++ b/internal/cmd/loadbalancer/add_service.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AddServiceCmd is the command for 'hcloud load-balancer add-service' var AddServiceCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/add_target.go b/internal/cmd/loadbalancer/add_target.go index 7e42dc8e..31fb2bdb 100644 --- a/internal/cmd/loadbalancer/add_target.go +++ b/internal/cmd/loadbalancer/add_target.go @@ -14,6 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AddTargetCmd is the command for 'hcloud load-balancer add-target' var AddTargetCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/attach_to_network.go b/internal/cmd/loadbalancer/attach_to_network.go index 90803fb2..6b70af8f 100644 --- a/internal/cmd/loadbalancer/attach_to_network.go +++ b/internal/cmd/loadbalancer/attach_to_network.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AttachToNetworkCmd is the command for 'hcloud load-balancer attach-to-network' var AttachToNetworkCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/change_algorithm.go b/internal/cmd/loadbalancer/change_algorithm.go index 194ae585..f0174395 100644 --- a/internal/cmd/loadbalancer/change_algorithm.go +++ b/internal/cmd/loadbalancer/change_algorithm.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ChangeAlgorithmCmd is the command for 'hcloud load-balancer change-algorithm' var ChangeAlgorithmCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/change_type.go b/internal/cmd/loadbalancer/change_type.go index d679940e..74ac8a5d 100644 --- a/internal/cmd/loadbalancer/change_type.go +++ b/internal/cmd/loadbalancer/change_type.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ChangeTypeCmd is the command for 'hcloud load-balancer change-type' var ChangeTypeCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/loadbalancer/create.go b/internal/cmd/loadbalancer/create.go index 0f4c8260..fb8af47f 100644 --- a/internal/cmd/loadbalancer/create.go +++ b/internal/cmd/loadbalancer/create.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateCmd is the command for 'hcloud load-balancer create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/delete.go b/internal/cmd/loadbalancer/delete.go index 83172f54..14d4a267 100644 --- a/internal/cmd/loadbalancer/delete.go +++ b/internal/cmd/loadbalancer/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud load-balancer delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "Load Balancer", ResourceNamePlural: "Load Balancers", diff --git a/internal/cmd/loadbalancer/delete_service.go b/internal/cmd/loadbalancer/delete_service.go index fe38fd72..141e33db 100644 --- a/internal/cmd/loadbalancer/delete_service.go +++ b/internal/cmd/loadbalancer/delete_service.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DeleteServiceCmd is the command for 'hcloud load-balancer delete-service' var DeleteServiceCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/describe.go b/internal/cmd/loadbalancer/describe.go index 92041e6a..9445934e 100644 --- a/internal/cmd/loadbalancer/describe.go +++ b/internal/cmd/loadbalancer/describe.go @@ -11,7 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -// DescribeCmd defines a command for describing a LoadBalancer. +// DescribeCmd is the command for 'hcloud load-balancer describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "Load Balancer", ShortDescription: "Describe a Load Balancer", diff --git a/internal/cmd/loadbalancer/detach_from_network.go b/internal/cmd/loadbalancer/detach_from_network.go index dcb5da3e..b125b1d2 100644 --- a/internal/cmd/loadbalancer/detach_from_network.go +++ b/internal/cmd/loadbalancer/detach_from_network.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DetachFromNetworkCmd is the command for 'hcloud load-balancer detach-from-network' var DetachFromNetworkCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/disable_protection.go b/internal/cmd/loadbalancer/disable_protection.go index 6e7ae911..5aa6e412 100644 --- a/internal/cmd/loadbalancer/disable_protection.go +++ b/internal/cmd/loadbalancer/disable_protection.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableProtectionCmd is the command for 'hcloud load-balancer disable-protection' var DisableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/loadbalancer/disable_public_interface.go b/internal/cmd/loadbalancer/disable_public_interface.go index e869e0ef..5b5862d2 100644 --- a/internal/cmd/loadbalancer/disable_public_interface.go +++ b/internal/cmd/loadbalancer/disable_public_interface.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisablePublicInterfaceCmd is the command for 'hcloud load-balancer disable-public-interface' var DisablePublicInterfaceCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/loadbalancer/enable_protection.go b/internal/cmd/loadbalancer/enable_protection.go index cd4c6e52..fccdf6bb 100644 --- a/internal/cmd/loadbalancer/enable_protection.go +++ b/internal/cmd/loadbalancer/enable_protection.go @@ -55,6 +55,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } +// EnableProtectionCmd is the command for 'hcloud load-balancer enable-protection' var EnableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/loadbalancer/enable_public_interface.go b/internal/cmd/loadbalancer/enable_public_interface.go index b86deebd..b197c48d 100644 --- a/internal/cmd/loadbalancer/enable_public_interface.go +++ b/internal/cmd/loadbalancer/enable_public_interface.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// EnablePublicInterfaceCmd is the command for 'hcloud load-balancer enable-public-interface' var EnablePublicInterfaceCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/loadbalancer/labels.go b/internal/cmd/loadbalancer/labels.go index c7c19d74..044f563e 100644 --- a/internal/cmd/loadbalancer/labels.go +++ b/internal/cmd/loadbalancer/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud load-balancer add-label' and 'hcloud load-balancer remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "Load Balancer", ShortDescriptionAdd: "Add a label to a Load Balancer", diff --git a/internal/cmd/loadbalancer/list.go b/internal/cmd/loadbalancer/list.go index bbe31b96..334d7b15 100644 --- a/internal/cmd/loadbalancer/list.go +++ b/internal/cmd/loadbalancer/list.go @@ -16,6 +16,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud load-balancer list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Load Balancer", JSONKeyGetByName: "load_balancers", @@ -95,6 +96,7 @@ var ListCmd = base.ListCmd{ }, } +// Health returns the health status of a load balancer as a string func Health(l *hcloud.LoadBalancer) string { healthyCount := 0 unhealthyCount := 0 diff --git a/internal/cmd/loadbalancer/load_balancer.go b/internal/cmd/loadbalancer/load_balancer.go index ca3b20d2..31b22ac2 100644 --- a/internal/cmd/loadbalancer/load_balancer.go +++ b/internal/cmd/loadbalancer/load_balancer.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud load-balancer' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "load-balancer", diff --git a/internal/cmd/loadbalancer/metrics.go b/internal/cmd/loadbalancer/metrics.go index 6d184c04..ef69a4e2 100644 --- a/internal/cmd/loadbalancer/metrics.go +++ b/internal/cmd/loadbalancer/metrics.go @@ -28,6 +28,7 @@ var metricTypeStrings = []string{ string(hcloud.LoadBalancerMetricBandwidth), } +// MetricsCmd is the command for 'hcloud load-balancer metrics' var MetricsCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/remove_target.go b/internal/cmd/loadbalancer/remove_target.go index 276c8df8..8c669598 100644 --- a/internal/cmd/loadbalancer/remove_target.go +++ b/internal/cmd/loadbalancer/remove_target.go @@ -14,6 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// RemoveTargetCmd is the command for 'hcloud load-balancer remove-target' var RemoveTargetCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancer/set_rdns.go b/internal/cmd/loadbalancer/set_rdns.go index 5ba4947d..e77fa9c4 100644 --- a/internal/cmd/loadbalancer/set_rdns.go +++ b/internal/cmd/loadbalancer/set_rdns.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// SetRDNSCmd is the command for 'hcloud load-balancer set-rdns' var SetRDNSCmd = base.SetRdnsCmd{ ResourceNameSingular: "Load Balancer", ShortDescription: "Change reverse DNS of a Load Balancer", diff --git a/internal/cmd/loadbalancer/update.go b/internal/cmd/loadbalancer/update.go index 4a7a2372..3186d346 100644 --- a/internal/cmd/loadbalancer/update.go +++ b/internal/cmd/loadbalancer/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud load-balancer update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Load Balancer", ShortDescription: "Update a Load Balancer", diff --git a/internal/cmd/loadbalancer/update_service.go b/internal/cmd/loadbalancer/update_service.go index 254f7430..0953bf8a 100644 --- a/internal/cmd/loadbalancer/update_service.go +++ b/internal/cmd/loadbalancer/update_service.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateServiceCmd is the command for 'hcloud load-balancer update-service' var UpdateServiceCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/loadbalancertype/describe.go b/internal/cmd/loadbalancertype/describe.go index 058facfb..0fcc6b59 100644 --- a/internal/cmd/loadbalancertype/describe.go +++ b/internal/cmd/loadbalancertype/describe.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud load-balancer-type describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "Load Balancer Type", ShortDescription: "Describe a Load Balancer type", diff --git a/internal/cmd/loadbalancertype/list.go b/internal/cmd/loadbalancertype/list.go index 01a9acdc..17dafc87 100644 --- a/internal/cmd/loadbalancertype/list.go +++ b/internal/cmd/loadbalancertype/list.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud load-balancer-type list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Load Balancer Types", JSONKeyGetByName: "load_balancer_types", diff --git a/internal/cmd/loadbalancertype/load_balancer_type.go b/internal/cmd/loadbalancertype/load_balancer_type.go index afc16006..6ddf708a 100644 --- a/internal/cmd/loadbalancertype/load_balancer_type.go +++ b/internal/cmd/loadbalancertype/load_balancer_type.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud load-balancer-type' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "load-balancer-type", diff --git a/internal/cmd/location/describe.go b/internal/cmd/location/describe.go index f6ede55d..e58dab98 100644 --- a/internal/cmd/location/describe.go +++ b/internal/cmd/location/describe.go @@ -9,7 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -// DescribeCmd defines a command for describing a location. +// DescribeCmd is the command for 'hcloud location describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "location", ShortDescription: "Describe a location", diff --git a/internal/cmd/location/list.go b/internal/cmd/location/list.go index eaf16214..15282921 100644 --- a/internal/cmd/location/list.go +++ b/internal/cmd/location/list.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud location list' var ListCmd = base.ListCmd{ ResourceNamePlural: "locations", JSONKeyGetByName: "locations", diff --git a/internal/cmd/location/location.go b/internal/cmd/location/location.go index 80acec9a..95c76e9d 100644 --- a/internal/cmd/location/location.go +++ b/internal/cmd/location/location.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud location' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "location", diff --git a/internal/cmd/network/add_route.go b/internal/cmd/network/add_route.go index c4f7798b..4dbbf765 100644 --- a/internal/cmd/network/add_route.go +++ b/internal/cmd/network/add_route.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AddRouteCmd is the command for 'hcloud network add-route' var AddRouteCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/network/add_subnet.go b/internal/cmd/network/add_subnet.go index b8eb5af3..6511fa2e 100644 --- a/internal/cmd/network/add_subnet.go +++ b/internal/cmd/network/add_subnet.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AddSubnetCmd is the command for 'hcloud network add-subnet' var AddSubnetCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/network/change_ip_range.go b/internal/cmd/network/change_ip_range.go index c9eb1960..9eabe136 100644 --- a/internal/cmd/network/change_ip_range.go +++ b/internal/cmd/network/change_ip_range.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ChangeIPRangeCmd is the command for 'hcloud network change-ip-range' var ChangeIPRangeCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/network/create.go b/internal/cmd/network/create.go index 706f4a68..781ecd73 100644 --- a/internal/cmd/network/create.go +++ b/internal/cmd/network/create.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateCmd is the command for 'hcloud network create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/network/delete.go b/internal/cmd/network/delete.go index 39531a1d..db8dc4d8 100644 --- a/internal/cmd/network/delete.go +++ b/internal/cmd/network/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud network delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "Network", ResourceNamePlural: "Networks", diff --git a/internal/cmd/network/describe.go b/internal/cmd/network/describe.go index 56115de5..01ae901a 100644 --- a/internal/cmd/network/describe.go +++ b/internal/cmd/network/describe.go @@ -11,7 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) -// DescribeCmd defines a command for describing a network. +// DescribeCmd is the command for 'hcloud network describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "network", ShortDescription: "Describe a network", diff --git a/internal/cmd/network/disable_protection.go b/internal/cmd/network/disable_protection.go index 97042046..7abf874b 100644 --- a/internal/cmd/network/disable_protection.go +++ b/internal/cmd/network/disable_protection.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableProtectionCmd is the command for 'hcloud network disable-protection' var DisableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/network/enable_protection.go b/internal/cmd/network/enable_protection.go index 07f4add6..442461e9 100644 --- a/internal/cmd/network/enable_protection.go +++ b/internal/cmd/network/enable_protection.go @@ -55,6 +55,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } +// EnableProtectionCmd is the command for 'hcloud network enable-protection' var EnableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/network/expose_routes_to_vswitch.go b/internal/cmd/network/expose_routes_to_vswitch.go index 959fef16..d4290f8f 100644 --- a/internal/cmd/network/expose_routes_to_vswitch.go +++ b/internal/cmd/network/expose_routes_to_vswitch.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ExposeRoutesToVSwitchCmd is the command for 'hcloud network expose-routes-to-vswitch' var ExposeRoutesToVSwitchCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/network/labels.go b/internal/cmd/network/labels.go index 415d70ae..81527d9e 100644 --- a/internal/cmd/network/labels.go +++ b/internal/cmd/network/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud network add-label' and 'hcloud network remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "Network", ShortDescriptionAdd: "Add a label to a Network", diff --git a/internal/cmd/network/list.go b/internal/cmd/network/list.go index aaaebc98..d9837419 100644 --- a/internal/cmd/network/list.go +++ b/internal/cmd/network/list.go @@ -16,6 +16,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud network list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Networks", JSONKeyGetByName: "networks", diff --git a/internal/cmd/network/network.go b/internal/cmd/network/network.go index 9f396553..84b6e323 100644 --- a/internal/cmd/network/network.go +++ b/internal/cmd/network/network.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud network' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "network", diff --git a/internal/cmd/network/remove_route.go b/internal/cmd/network/remove_route.go index b8611584..1619d52c 100644 --- a/internal/cmd/network/remove_route.go +++ b/internal/cmd/network/remove_route.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// RemoveRouteCmd is the command for 'hcloud network remove-route' var RemoveRouteCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/network/remove_subnet.go b/internal/cmd/network/remove_subnet.go index ec291f05..328d747f 100644 --- a/internal/cmd/network/remove_subnet.go +++ b/internal/cmd/network/remove_subnet.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// RemoveSubnetCmd is the command for 'hcloud network remove-subnet' var RemoveSubnetCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/network/update.go b/internal/cmd/network/update.go index 8cebafe7..6aed1c92 100644 --- a/internal/cmd/network/update.go +++ b/internal/cmd/network/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud network update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Network", ShortDescription: "Update a Network.\n\nTo enable or disable exposing routes to the vSwitch connection you can use the subcommand \"hcloud network expose-routes-to-vswitch\".", diff --git a/internal/cmd/output/output.go b/internal/cmd/output/output.go index f2042dd3..03f06b5f 100644 --- a/internal/cmd/output/output.go +++ b/internal/cmd/output/output.go @@ -19,31 +19,38 @@ import ( const flagName = "output" +// Option is an output option. type Option struct { Name string Values []string } +// OptionNoHeader returns an option to suppress the header. func OptionNoHeader() Option { return Option{Name: "noheader"} } +// OptionJSON returns an option to specify the output format as JSON. func OptionJSON() Option { return Option{Name: "json"} } +// OptionYAML returns an option to specify the output format as YAML. func OptionYAML() Option { return Option{Name: "yaml"} } +// OptionFormat returns an option to specify the output format. func OptionFormat() Option { return Option{Name: "format"} } +// OptionColumns returns an option to specify the output columns. func OptionColumns(columns []string) Option { return Option{Name: "columns", Values: columns} } +// AddFlag adds an output flag to a command. func AddFlag(cmd *cobra.Command, options ...Option) { var ( names []string @@ -109,11 +116,13 @@ func validateOutputFlag(options []Option) func(cmd *cobra.Command, args []string } } +// FlagsForCommand returns the output flags for a command. func FlagsForCommand(cmd *cobra.Command) Opts { opts, _ := cmd.Flags().GetStringArray(flagName) return parseOutputFlags(opts) } +// Opts is a map of output options. type Opts map[string][]string // Set sets the key to value. It replaces any existing @@ -128,6 +137,7 @@ func (o Opts) Add(key, value string) { o[key] = append(o[key], value) } +// IsSet returns true if the output option is set. func (o Opts) IsSet(key string) bool { if values, ok := o[key]; ok && len(values) > 0 { return true @@ -159,6 +169,7 @@ func NewTable() *Table { } } +// FieldFn is a function that formats the value of a field. type FieldFn func(obj interface{}) string type writerFlusher interface { @@ -259,6 +270,7 @@ func (o *Table) WriteHeader(columns []string) { _, _ = fmt.Fprintln(o.w, strings.Join(header, "\t")) } +// Flush flushes the table to the output. func (o *Table) Flush() error { return o.w.Flush() } diff --git a/internal/cmd/placementgroup/create.go b/internal/cmd/placementgroup/create.go index ba74a4e9..45f92b30 100644 --- a/internal/cmd/placementgroup/create.go +++ b/internal/cmd/placementgroup/create.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateCmd is the command for 'hcloud placement-group create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/placementgroup/delete.go b/internal/cmd/placementgroup/delete.go index 87e34de1..e1586ab8 100644 --- a/internal/cmd/placementgroup/delete.go +++ b/internal/cmd/placementgroup/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud placement-group delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "placement group", ResourceNamePlural: "placement groups", diff --git a/internal/cmd/placementgroup/describe.go b/internal/cmd/placementgroup/describe.go index 81abf85c..31e889be 100644 --- a/internal/cmd/placementgroup/describe.go +++ b/internal/cmd/placementgroup/describe.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud placement-group describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "placement group", ShortDescription: "Describe a placement group", diff --git a/internal/cmd/placementgroup/labels.go b/internal/cmd/placementgroup/labels.go index fc6dfe2a..6bf9b9b2 100644 --- a/internal/cmd/placementgroup/labels.go +++ b/internal/cmd/placementgroup/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud placement-group add-label' and 'hcloud placement-group remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "placement group", ShortDescriptionAdd: "Add a label to a placement group", diff --git a/internal/cmd/placementgroup/list.go b/internal/cmd/placementgroup/list.go index 959c339e..49664b2a 100644 --- a/internal/cmd/placementgroup/list.go +++ b/internal/cmd/placementgroup/list.go @@ -16,6 +16,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud placement-group list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Placement Groups", JSONKeyGetByName: "placement_groups", diff --git a/internal/cmd/placementgroup/placementgroup.go b/internal/cmd/placementgroup/placementgroup.go index f54277b1..244bcc47 100644 --- a/internal/cmd/placementgroup/placementgroup.go +++ b/internal/cmd/placementgroup/placementgroup.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud placement-group' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "placement-group", diff --git a/internal/cmd/placementgroup/update.go b/internal/cmd/placementgroup/update.go index fae341d3..53941ba4 100644 --- a/internal/cmd/placementgroup/update.go +++ b/internal/cmd/placementgroup/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud placement-group update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "placement group", ShortDescription: "Update a placement group", diff --git a/internal/cmd/primaryip/assign.go b/internal/cmd/primaryip/assign.go index 72e8c271..a03d76c2 100644 --- a/internal/cmd/primaryip/assign.go +++ b/internal/cmd/primaryip/assign.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AssignCmd is the command for 'hcloud primary-ip assign' var AssignCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/primaryip/create.go b/internal/cmd/primaryip/create.go index 9a7ae40c..8432e697 100644 --- a/internal/cmd/primaryip/create.go +++ b/internal/cmd/primaryip/create.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateCmd is the command for 'hcloud primary-ip create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/primaryip/delete.go b/internal/cmd/primaryip/delete.go index 56adc48e..eb6bdf5b 100644 --- a/internal/cmd/primaryip/delete.go +++ b/internal/cmd/primaryip/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud primary-ip delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "Primary IP", ResourceNamePlural: "Primary IPs", diff --git a/internal/cmd/primaryip/describe.go b/internal/cmd/primaryip/describe.go index 2c8008ea..289b7162 100644 --- a/internal/cmd/primaryip/describe.go +++ b/internal/cmd/primaryip/describe.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud primary-ip describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "Primary IP", ShortDescription: "Describe an Primary IP", diff --git a/internal/cmd/primaryip/disable_protection.go b/internal/cmd/primaryip/disable_protection.go index ebbe4cbe..2508d224 100644 --- a/internal/cmd/primaryip/disable_protection.go +++ b/internal/cmd/primaryip/disable_protection.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableProtectionCmd is the command for 'hcloud primary-ip disable-protection' var DisableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/primaryip/enable_protection.go b/internal/cmd/primaryip/enable_protection.go index f8cc6038..32fa986b 100644 --- a/internal/cmd/primaryip/enable_protection.go +++ b/internal/cmd/primaryip/enable_protection.go @@ -53,6 +53,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } +// EnableProtectionCmd is the command for 'hcloud primary-ip enable-protection' var EnableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/primaryip/labels.go b/internal/cmd/primaryip/labels.go index 5a84f92d..7dceccc1 100644 --- a/internal/cmd/primaryip/labels.go +++ b/internal/cmd/primaryip/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud primary-ip add-label' and 'hcloud primary-ip remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "primary-ip", ShortDescriptionAdd: "Add a label to a Primary IP", diff --git a/internal/cmd/primaryip/list.go b/internal/cmd/primaryip/list.go index a06f23c6..e236448a 100644 --- a/internal/cmd/primaryip/list.go +++ b/internal/cmd/primaryip/list.go @@ -17,6 +17,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud primary-ip list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Primary IPs", JSONKeyGetByName: "primary_ips", diff --git a/internal/cmd/primaryip/primaryip.go b/internal/cmd/primaryip/primaryip.go index e3ea80cf..1f06c587 100644 --- a/internal/cmd/primaryip/primaryip.go +++ b/internal/cmd/primaryip/primaryip.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud primary-ip' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "primary-ip", diff --git a/internal/cmd/primaryip/set_rdns.go b/internal/cmd/primaryip/set_rdns.go index 47c4292d..58b45b42 100644 --- a/internal/cmd/primaryip/set_rdns.go +++ b/internal/cmd/primaryip/set_rdns.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// SetRDNSCmd is the command for 'hcloud primary-ip set-rdns' var SetRDNSCmd = base.SetRdnsCmd{ ResourceNameSingular: "Primary IP", ShortDescription: "Change reverse DNS of a Primary IP", diff --git a/internal/cmd/primaryip/unassign.go b/internal/cmd/primaryip/unassign.go index b1410a24..b086c4d9 100644 --- a/internal/cmd/primaryip/unassign.go +++ b/internal/cmd/primaryip/unassign.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// UnAssignCmd is the command for 'hcloud primary-ip unassign' var UnAssignCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/primaryip/update.go b/internal/cmd/primaryip/update.go index f37116dd..1815a85d 100644 --- a/internal/cmd/primaryip/update.go +++ b/internal/cmd/primaryip/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud primary-ip update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Primary IP", ShortDescription: "Update a Primary IP", diff --git a/internal/cmd/server/add_to_placement_group.go b/internal/cmd/server/add_to_placement_group.go index ea32a532..e5c9395e 100644 --- a/internal/cmd/server/add_to_placement_group.go +++ b/internal/cmd/server/add_to_placement_group.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// AddToPlacementGroupCmd is the command for 'hcloud server add-to-placement-group' var AddToPlacementGroupCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/attach_iso.go b/internal/cmd/server/attach_iso.go index 53caf59c..9f771b04 100644 --- a/internal/cmd/server/attach_iso.go +++ b/internal/cmd/server/attach_iso.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// AttachISOCmd is the command for 'hcloud server attach-iso' var AttachISOCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/attach_to_network.go b/internal/cmd/server/attach_to_network.go index 2d163179..7c880fb0 100644 --- a/internal/cmd/server/attach_to_network.go +++ b/internal/cmd/server/attach_to_network.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AttachToNetworkCmd is the command for 'hcloud server attach-to-network' var AttachToNetworkCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/change_alias_ips.go b/internal/cmd/server/change_alias_ips.go index 8659b682..369c291b 100644 --- a/internal/cmd/server/change_alias_ips.go +++ b/internal/cmd/server/change_alias_ips.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ChangeAliasIPsCmd is the command for 'hcloud server change-alias-ips' var ChangeAliasIPsCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/change_type.go b/internal/cmd/server/change_type.go index 2b37252c..e67ba34e 100644 --- a/internal/cmd/server/change_type.go +++ b/internal/cmd/server/change_type.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ChangeTypeCmd is the command for 'hcloud server change-type' var ChangeTypeCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/create.go b/internal/cmd/server/create.go index dcdf9b6a..ca026087 100644 --- a/internal/cmd/server/create.go +++ b/internal/cmd/server/create.go @@ -34,7 +34,7 @@ type createResultSchema struct { RootPassword string `json:"root_password,omitempty"` } -// CreateCmd defines a command for creating a server. +// CreateCmd is the command for 'hcloud server create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/create_image.go b/internal/cmd/server/create_image.go index 1f8e3f41..49d0c0f1 100644 --- a/internal/cmd/server/create_image.go +++ b/internal/cmd/server/create_image.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateImageCmd is the command for 'hcloud server create-image' var CreateImageCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/delete.go b/internal/cmd/server/delete.go index d16adbb5..681a762d 100644 --- a/internal/cmd/server/delete.go +++ b/internal/cmd/server/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud server delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "Server", ResourceNamePlural: "Servers", diff --git a/internal/cmd/server/describe.go b/internal/cmd/server/describe.go index 8420276c..f484da99 100644 --- a/internal/cmd/server/describe.go +++ b/internal/cmd/server/describe.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud server describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "server", ShortDescription: "Describe a server", diff --git a/internal/cmd/server/detach_from_network.go b/internal/cmd/server/detach_from_network.go index 99f5d207..1414b21d 100644 --- a/internal/cmd/server/detach_from_network.go +++ b/internal/cmd/server/detach_from_network.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DetachFromNetworkCmd is the command for 'hcloud server detach-from-network' var DetachFromNetworkCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/detach_iso.go b/internal/cmd/server/detach_iso.go index dd18ed62..87ce5363 100644 --- a/internal/cmd/server/detach_iso.go +++ b/internal/cmd/server/detach_iso.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DetachISOCmd is the command for 'hcloud server detach-iso' var DetachISOCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/disable_backup.go b/internal/cmd/server/disable_backup.go index 26aded6c..d1cfddf3 100644 --- a/internal/cmd/server/disable_backup.go +++ b/internal/cmd/server/disable_backup.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableBackupCmd is the command for 'hcloud server disable-backup' var DisableBackupCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/disable_protection.go b/internal/cmd/server/disable_protection.go index e8f4c16d..da0f8b5d 100644 --- a/internal/cmd/server/disable_protection.go +++ b/internal/cmd/server/disable_protection.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableProtectionCmd is the command for 'hcloud server disable-protection' var DisableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/disable_rescue.go b/internal/cmd/server/disable_rescue.go index 842f0fd2..34827462 100644 --- a/internal/cmd/server/disable_rescue.go +++ b/internal/cmd/server/disable_rescue.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableRescueCmd is the command for 'hcloud server disable-rescue' var DisableRescueCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/enable_backup.go b/internal/cmd/server/enable_backup.go index 8f51482a..a851d823 100644 --- a/internal/cmd/server/enable_backup.go +++ b/internal/cmd/server/enable_backup.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// EnableBackupCmd is the command for 'hcloud server enable-backup' var EnableBackupCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/enable_protection.go b/internal/cmd/server/enable_protection.go index f9a7c3fe..44028dc5 100644 --- a/internal/cmd/server/enable_protection.go +++ b/internal/cmd/server/enable_protection.go @@ -57,6 +57,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } +// EnableProtectionCmd is the command for 'hcloud server enable-protection' var EnableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/enable_rescue.go b/internal/cmd/server/enable_rescue.go index d347764c..09761e56 100644 --- a/internal/cmd/server/enable_rescue.go +++ b/internal/cmd/server/enable_rescue.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// EnableRescueCmd is the command for 'hcloud server enable-rescue' var EnableRescueCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/ip.go b/internal/cmd/server/ip.go index 65f58abc..fa787e16 100644 --- a/internal/cmd/server/ip.go +++ b/internal/cmd/server/ip.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// IPCmd is the command for 'hcloud server ip' var IPCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/labels.go b/internal/cmd/server/labels.go index ecb5ede0..870500d1 100644 --- a/internal/cmd/server/labels.go +++ b/internal/cmd/server/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud server add-label' and 'hcloud server remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "server", ShortDescriptionAdd: "Add a label to a server", diff --git a/internal/cmd/server/list.go b/internal/cmd/server/list.go index 9ee33baa..28d960d8 100644 --- a/internal/cmd/server/list.go +++ b/internal/cmd/server/list.go @@ -34,6 +34,7 @@ var serverStatusStrings = []string{ string(hcloud.ServerStatusUnknown), } +// ListCmd is the command for 'hcloud server list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Servers", JSONKeyGetByName: "servers", diff --git a/internal/cmd/server/metrics.go b/internal/cmd/server/metrics.go index 979777be..1f818511 100644 --- a/internal/cmd/server/metrics.go +++ b/internal/cmd/server/metrics.go @@ -27,6 +27,7 @@ var metricTypeStrings = []string{ string(hcloud.ServerMetricNetwork), } +// MetricsCmd is the command for 'hcloud server metrics' var MetricsCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/poweroff.go b/internal/cmd/server/poweroff.go index ba61a765..4bf9c223 100644 --- a/internal/cmd/server/poweroff.go +++ b/internal/cmd/server/poweroff.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// PoweroffCmd is the command for 'hcloud server poweroff' var PoweroffCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/poweron.go b/internal/cmd/server/poweron.go index 25fde1e0..bb9eac8b 100644 --- a/internal/cmd/server/poweron.go +++ b/internal/cmd/server/poweron.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// PoweronCmd is the command for 'hcloud server poweron' var PoweronCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/reboot.go b/internal/cmd/server/reboot.go index 9d0509da..0252c787 100644 --- a/internal/cmd/server/reboot.go +++ b/internal/cmd/server/reboot.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// RebootCmd is the command for 'hcloud server reboot' var RebootCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/rebuild.go b/internal/cmd/server/rebuild.go index fbee0513..c3ac42a3 100644 --- a/internal/cmd/server/rebuild.go +++ b/internal/cmd/server/rebuild.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// RebuildCmd is the command for 'hcloud server rebuild' var RebuildCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/remove_from_placement_group.go b/internal/cmd/server/remove_from_placement_group.go index 5527e843..659f2879 100644 --- a/internal/cmd/server/remove_from_placement_group.go +++ b/internal/cmd/server/remove_from_placement_group.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// RemoveFromPlacementGroupCmd is the command for 'hcloud server remove-from-placement-group' var RemoveFromPlacementGroupCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/request_console.go b/internal/cmd/server/request_console.go index 8a2e0ab8..e8b60139 100644 --- a/internal/cmd/server/request_console.go +++ b/internal/cmd/server/request_console.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// RequestConsoleCmd is the command for 'hcloud server request-console' var RequestConsoleCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/reset.go b/internal/cmd/server/reset.go index 1af79ab9..c0c75cac 100644 --- a/internal/cmd/server/reset.go +++ b/internal/cmd/server/reset.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// ResetCmd is the command for 'hcloud server reset' var ResetCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/server/reset_password.go b/internal/cmd/server/reset_password.go index ed0d6185..ac8929ca 100644 --- a/internal/cmd/server/reset_password.go +++ b/internal/cmd/server/reset_password.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// ResetPasswordCmd is the command for 'hcloud server reset-password' var ResetPasswordCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/server.go b/internal/cmd/server/server.go index 48adcf6c..8d5b6027 100644 --- a/internal/cmd/server/server.go +++ b/internal/cmd/server/server.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud server' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "server", diff --git a/internal/cmd/server/set_rdns.go b/internal/cmd/server/set_rdns.go index 6ca0e777..b7c833c3 100644 --- a/internal/cmd/server/set_rdns.go +++ b/internal/cmd/server/set_rdns.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// SetRDNSCmd is the command for 'hcloud server set-rdns' var SetRDNSCmd = base.SetRdnsCmd{ ResourceNameSingular: "Server", ShortDescription: "Change reverse DNS of a Server", diff --git a/internal/cmd/server/shutdown.go b/internal/cmd/server/shutdown.go index 93ce90bc..4dbb1e6f 100644 --- a/internal/cmd/server/shutdown.go +++ b/internal/cmd/server/shutdown.go @@ -16,6 +16,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ShutdownCmd is the command for 'hcloud server shutdown' var ShutdownCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { diff --git a/internal/cmd/server/ssh.go b/internal/cmd/server/ssh.go index c4792e95..628bdb71 100644 --- a/internal/cmd/server/ssh.go +++ b/internal/cmd/server/ssh.go @@ -16,8 +16,10 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// SSHPath is the path to the ssh binary var SSHPath = "ssh" +// SSHCmd is the command for 'hcloud server ssh' var SSHCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/server/update.go b/internal/cmd/server/update.go index d89ee2fb..4bfd534c 100644 --- a/internal/cmd/server/update.go +++ b/internal/cmd/server/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud server update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Server", ShortDescription: "Update a Server", diff --git a/internal/cmd/servertype/describe.go b/internal/cmd/servertype/describe.go index 8418793f..fdfa0886 100644 --- a/internal/cmd/servertype/describe.go +++ b/internal/cmd/servertype/describe.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud server-type describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "serverType", ShortDescription: "Describe a server type", diff --git a/internal/cmd/servertype/list.go b/internal/cmd/servertype/list.go index 291214b3..706aa7bc 100644 --- a/internal/cmd/servertype/list.go +++ b/internal/cmd/servertype/list.go @@ -14,6 +14,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud server-type list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Server Types", JSONKeyGetByName: "server_types", diff --git a/internal/cmd/servertype/server_type.go b/internal/cmd/servertype/server_type.go index 7a35bde8..99d177ea 100644 --- a/internal/cmd/servertype/server_type.go +++ b/internal/cmd/servertype/server_type.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud server-type' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "server-type", diff --git a/internal/cmd/sshkey/create.go b/internal/cmd/sshkey/create.go index ef5d7a2f..f84b13cb 100644 --- a/internal/cmd/sshkey/create.go +++ b/internal/cmd/sshkey/create.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// CreateCmd is the command for 'hcloud ssh-key create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/sshkey/delete.go b/internal/cmd/sshkey/delete.go index 67f2b43d..56ad9b53 100644 --- a/internal/cmd/sshkey/delete.go +++ b/internal/cmd/sshkey/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud ssh-key delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "SSH Key", ResourceNamePlural: "SSH Keys", diff --git a/internal/cmd/sshkey/describe.go b/internal/cmd/sshkey/describe.go index 6b9d8e88..7e4d1550 100644 --- a/internal/cmd/sshkey/describe.go +++ b/internal/cmd/sshkey/describe.go @@ -13,6 +13,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud ssh-key describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "SSH Key", ShortDescription: "Describe a SSH Key", diff --git a/internal/cmd/sshkey/labels.go b/internal/cmd/sshkey/labels.go index 3bfaf396..bf635fc1 100644 --- a/internal/cmd/sshkey/labels.go +++ b/internal/cmd/sshkey/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the command for 'hcloud ssh-key add-label' and 'hcloud ssh-key remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "SSH Key", ShortDescriptionAdd: "Add a label to a SSH Key", diff --git a/internal/cmd/sshkey/list.go b/internal/cmd/sshkey/list.go index 79099629..b8652231 100644 --- a/internal/cmd/sshkey/list.go +++ b/internal/cmd/sshkey/list.go @@ -15,6 +15,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud ssh-key list' var ListCmd = base.ListCmd{ ResourceNamePlural: "SSH keys", JSONKeyGetByName: "ssh_keys", diff --git a/internal/cmd/sshkey/sshkey.go b/internal/cmd/sshkey/sshkey.go index db94e14a..4fd56ac5 100644 --- a/internal/cmd/sshkey/sshkey.go +++ b/internal/cmd/sshkey/sshkey.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud ssh-key' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "ssh-key", diff --git a/internal/cmd/sshkey/update.go b/internal/cmd/sshkey/update.go index 467c4f7b..2089e84b 100644 --- a/internal/cmd/sshkey/update.go +++ b/internal/cmd/sshkey/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud ssh-key update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "SSHKey", ShortDescription: "Update a SSHKey", diff --git a/internal/cmd/util/byte_units.go b/internal/cmd/util/byte_units.go index 3e55d887..84762988 100644 --- a/internal/cmd/util/byte_units.go +++ b/internal/cmd/util/byte_units.go @@ -1,5 +1,6 @@ package util +//nolint:golint const ( Byte = 1 Kibibyte = Byte * 1024 diff --git a/internal/cmd/util/deprecation.go b/internal/cmd/util/deprecation.go index c9b1858c..0a4a87ad 100644 --- a/internal/cmd/util/deprecation.go +++ b/internal/cmd/util/deprecation.go @@ -8,6 +8,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeDeprecation returns a string describing the deprecation status of a resource. func DescribeDeprecation(resource hcloud.Deprecatable) string { if !resource.IsDeprecated() { return "" diff --git a/internal/cmd/util/resource.go b/internal/cmd/util/resource.go index d88e1400..049109c6 100644 --- a/internal/cmd/util/resource.go +++ b/internal/cmd/util/resource.go @@ -1,5 +1,6 @@ package util +// ResourceState is a utility struct to store the state of a resource. type ResourceState struct { IDOrName string Error error diff --git a/internal/cmd/util/util.go b/internal/cmd/util/util.go index e2a91e59..7e1d91f3 100644 --- a/internal/cmd/util/util.go +++ b/internal/cmd/util/util.go @@ -19,6 +19,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// YesNo returns "yes" if b is true, otherwise it returns "no". func YesNo(b bool) string { if b { return "yes" @@ -26,6 +27,7 @@ func YesNo(b bool) string { return "no" } +// NA returns the passed string if it is not empty, otherwise it returns "-". func NA(s string) string { if s == "" { return "-" @@ -33,10 +35,12 @@ func NA(s string) string { return s } +// Datetime returns the passed time as a string in the format "Mon Jan _2 15:04:05 MST 2006". func Datetime(t time.Time) string { return t.Local().Format(time.UnixDate) } +// Age returns the age of the passed time in a human-readable format. func Age(t, currentTime time.Time) string { diff := currentTime.Sub(t) @@ -60,6 +64,7 @@ func Age(t, currentTime time.Time) string { return "just now" } +// GrossPrice returns the gross price as a string with the currency symbol. func GrossPrice(price hcloud.Price) string { currencyDisplay := price.Currency @@ -74,6 +79,8 @@ func GrossPrice(price hcloud.Price) string { return fmt.Sprintf("%s\u00a0%s", currencyDisplay, price.Gross) } +// ChainRunE runs the passed functions in order. If any of the functions returns an error, ChainRunE stops and returns +// the error. func ChainRunE(fns ...func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { for _, fn := range fns { @@ -88,6 +95,7 @@ func ChainRunE(fns ...func(cmd *cobra.Command, args []string) error) func(cmd *c } } +// ExactlyOneSet returns true if exactly one of the passed strings is set. func ExactlyOneSet(s string, ss ...string) bool { set := s != "" for _, s := range ss { @@ -103,6 +111,7 @@ var outputDescription = `Output can be controlled with the -o flag. Use -o nohea table header. Displayed columns and their order can be set with -o columns=%s (see available columns below).` +// ListLongDescription returns a long description for a list command. func ListLongDescription(intro string, columns []string) string { var colExample []string if len(columns) > 2 { @@ -118,6 +127,7 @@ func ListLongDescription(intro string, columns []string) string { ) } +// SplitLabel splits up label into key and value and returns them as a slice with two elements. func SplitLabel(label string) []string { return strings.SplitN(label, "=", 2) } @@ -133,6 +143,7 @@ func SplitLabelVars(label string) (string, string) { return parts[0], parts[1] } +// LabelsToString converts a map of labels to a string in the format key=value, key=value, ... func LabelsToString(labels map[string]string) string { var labelsString []string keys := make([]string, 0, len(labels)) @@ -162,6 +173,7 @@ func PrefixLines(text, prefix string) string { return strings.Join(lines, "\n") } +// DescribeFormat prints the passed object using the passed format string to stdout. func DescribeFormat(object interface{}, format string) error { if !strings.HasSuffix(format, "\n") { format = format + "\n" @@ -173,12 +185,14 @@ func DescribeFormat(object interface{}, format string) error { return t.Execute(os.Stdout, object) } +// DescribeJSON prints the passed object as JSON to stdout. func DescribeJSON(object interface{}) error { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(object) } +// DescribeYAML prints the passed object as YAML to stdout. func DescribeYAML(object interface{}) error { enc := yaml.NewEncoder(os.Stdout) return enc.Encode(object) @@ -229,6 +243,8 @@ func ToKebabCase(s string) string { return strings.ReplaceAll(strings.ToLower(s), " ", "-") } +// IsNil returns true if the passed value is nil, regardless of the type. +// e.g. IsNil(nil) == true, IsNil((*int)(nil)) == true, IsNil(0) == false func IsNil(v any) bool { if v == nil { return true @@ -242,6 +258,7 @@ func IsNil(v any) bool { } } +// FilterNil filters the passed slice and returns a new slice that contains only non-nil values. func FilterNil[T any](values []T) []T { var filtered []T for _, v := range values { @@ -284,6 +301,7 @@ func RemoveDuplicates[S ~[]E, E cmp.Ordered](values S) S { return unique } +// AnyToAnySlice converts the passed value to a slice of interface{}. func AnyToAnySlice(a any) []any { val := reflect.ValueOf(a) if val.Kind() != reflect.Slice { @@ -296,6 +314,7 @@ func AnyToAnySlice(a any) []any { return s } +// AnyToStringSlice converts the passed value to a slice of strings. func AnyToStringSlice(a any) []string { var s []string for _, v := range AnyToAnySlice(a) { @@ -304,6 +323,7 @@ func AnyToStringSlice(a any) []string { return s } +// ToStringSlice converts the passed slice to a slice of strings. func ToStringSlice(a []any) []string { var s []string for _, v := range a { @@ -312,6 +332,7 @@ func ToStringSlice(a []any) []string { return s } +// ToAnySlice converts the passed slice to a slice of interface{}. func ToAnySlice[T any](a []T) []any { var s []any for _, v := range a { diff --git a/internal/cmd/version/version.go b/internal/cmd/version/version.go index 48a1d1f3..eb4809ce 100644 --- a/internal/cmd/version/version.go +++ b/internal/cmd/version/version.go @@ -8,6 +8,7 @@ import ( "github.com/hetznercloud/cli/internal/version" ) +// NewCommand creates the command for 'hcloud version' func NewCommand(_ state.State) *cobra.Command { cmd := &cobra.Command{ Use: "version", diff --git a/internal/cmd/volume/attach.go b/internal/cmd/volume/attach.go index 76b85c6f..14011910 100644 --- a/internal/cmd/volume/attach.go +++ b/internal/cmd/volume/attach.go @@ -12,6 +12,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// AttachCmd is the command for 'hcloud volume attach' var AttachCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/volume/create.go b/internal/cmd/volume/create.go index 5c5775e3..bcf8ac28 100644 --- a/internal/cmd/volume/create.go +++ b/internal/cmd/volume/create.go @@ -15,6 +15,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/exp/actionutil" ) +// CreateCmd is the command for 'hcloud volume create' var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/volume/delete.go b/internal/cmd/volume/delete.go index 41deea2e..7ed1181d 100644 --- a/internal/cmd/volume/delete.go +++ b/internal/cmd/volume/delete.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DeleteCmd is the command for 'hcloud volume delete' var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "Volume", ResourceNamePlural: "Volumes", diff --git a/internal/cmd/volume/describe.go b/internal/cmd/volume/describe.go index 55c9b466..45b72f34 100644 --- a/internal/cmd/volume/describe.go +++ b/internal/cmd/volume/describe.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// DescribeCmd is the command for 'hcloud volume describe' var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "volume", ShortDescription: "Describe an Volume", diff --git a/internal/cmd/volume/detach.go b/internal/cmd/volume/detach.go index 9c48f6ef..ecbb4a95 100644 --- a/internal/cmd/volume/detach.go +++ b/internal/cmd/volume/detach.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DetachCmd is the command for 'hcloud volume detach' var DetachCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/volume/disable_protection.go b/internal/cmd/volume/disable_protection.go index 234c7a50..2578c67b 100644 --- a/internal/cmd/volume/disable_protection.go +++ b/internal/cmd/volume/disable_protection.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// DisableProtectionCmd is the command for 'hcloud volume disable-protection' var DisableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/volume/enable_protection.go b/internal/cmd/volume/enable_protection.go index 69ea052a..45815253 100644 --- a/internal/cmd/volume/enable_protection.go +++ b/internal/cmd/volume/enable_protection.go @@ -55,6 +55,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } +// EnableProtectionCmd is the command for 'hcloud volume enable-protection' var EnableProtectionCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { return &cobra.Command{ diff --git a/internal/cmd/volume/labels.go b/internal/cmd/volume/labels.go index 57a8d972..ee876899 100644 --- a/internal/cmd/volume/labels.go +++ b/internal/cmd/volume/labels.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LabelCmds are the commands for 'hcloud volume add-label' and 'hcloud volume remove-label' var LabelCmds = base.LabelCmds{ ResourceNameSingular: "Volume", ShortDescriptionAdd: "Add a label to a Volume", diff --git a/internal/cmd/volume/list.go b/internal/cmd/volume/list.go index 2e85720b..e0f2e72d 100644 --- a/internal/cmd/volume/list.go +++ b/internal/cmd/volume/list.go @@ -17,6 +17,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) +// ListCmd is the command for 'hcloud volume list' var ListCmd = base.ListCmd{ ResourceNamePlural: "Volumes", JSONKeyGetByName: "volumes", diff --git a/internal/cmd/volume/resize.go b/internal/cmd/volume/resize.go index bf4e2f4d..b52d1de2 100644 --- a/internal/cmd/volume/resize.go +++ b/internal/cmd/volume/resize.go @@ -11,6 +11,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// ResizeCmd is the command for 'hcloud volume resize' var ResizeCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/cmd/volume/update.go b/internal/cmd/volume/update.go index 8b39917e..7a904d8e 100644 --- a/internal/cmd/volume/update.go +++ b/internal/cmd/volume/update.go @@ -10,6 +10,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// UpdateCmd is the command for 'hcloud volume update' var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Volume", ShortDescription: "Update a Volume", diff --git a/internal/cmd/volume/volume.go b/internal/cmd/volume/volume.go index 911c4898..26c76f19 100644 --- a/internal/cmd/volume/volume.go +++ b/internal/cmd/volume/volume.go @@ -7,6 +7,7 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// NewCommand creates the command for 'hcloud volume' func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "volume", diff --git a/internal/hcapi2/action.go b/internal/hcapi2/action.go index 1e7561cc..a01e439a 100644 --- a/internal/hcapi2/action.go +++ b/internal/hcapi2/action.go @@ -9,6 +9,7 @@ type ActionClient interface { hcloud.IActionClient } +// NewActionClient creates a new ActionClient. func NewActionClient(client hcloud.IActionClient) ActionClient { return &actionClient{ IActionClient: client, diff --git a/internal/hcapi2/certificate.go b/internal/hcapi2/certificate.go index 29d41fa5..cf882708 100644 --- a/internal/hcapi2/certificate.go +++ b/internal/hcapi2/certificate.go @@ -15,6 +15,7 @@ type CertificateClient interface { LabelKeys(string) []string } +// NewCertificateClient creates a new CertificateClient. func NewCertificateClient(client hcloud.ICertificateClient) CertificateClient { return &certificateClient{ ICertificateClient: client, diff --git a/internal/hcapi2/datacenter.go b/internal/hcapi2/datacenter.go index a9880460..75f897ea 100644 --- a/internal/hcapi2/datacenter.go +++ b/internal/hcapi2/datacenter.go @@ -14,6 +14,7 @@ type DatacenterClient interface { Names() []string } +// NewDatacenterClient creates a new DataCenterClient. func NewDatacenterClient(client hcloud.IDatacenterClient) DatacenterClient { return &datacenterClient{ IDatacenterClient: client, diff --git a/internal/hcapi2/firewall.go b/internal/hcapi2/firewall.go index d9dd9ae9..45153152 100644 --- a/internal/hcapi2/firewall.go +++ b/internal/hcapi2/firewall.go @@ -7,12 +7,15 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// FirewallClient embeds the Hetzner Cloud Firewall client +// and provides some additional helper functions. type FirewallClient interface { hcloud.IFirewallClient Names() []string LabelKeys(string) []string } +// NewFirewallClient creates a new Firewall client. func NewFirewallClient(client hcloud.IFirewallClient) FirewallClient { return &firewallClient{ IFirewallClient: client, diff --git a/internal/hcapi2/image.go b/internal/hcapi2/image.go index b668e870..809993f0 100644 --- a/internal/hcapi2/image.go +++ b/internal/hcapi2/image.go @@ -15,6 +15,7 @@ type ImageClient interface { LabelKeys(string) []string } +// NewImageClient creates a new ImageClient. func NewImageClient(client hcloud.IImageClient) ImageClient { return &imageClient{ IImageClient: client, diff --git a/internal/hcapi2/iso.go b/internal/hcapi2/iso.go index bed7f282..f1fc5526 100644 --- a/internal/hcapi2/iso.go +++ b/internal/hcapi2/iso.go @@ -14,6 +14,7 @@ type ISOClient interface { Names() []string } +// NewISOClient creates a new ISOClient. func NewISOClient(client hcloud.IISOClient) ISOClient { return &isoClient{ IISOClient: client, diff --git a/internal/hcapi2/load_balancer_type.go b/internal/hcapi2/load_balancer_type.go index 67946e12..559feaee 100644 --- a/internal/hcapi2/load_balancer_type.go +++ b/internal/hcapi2/load_balancer_type.go @@ -8,6 +8,8 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// LoadBalancerTypeClient embeds the Hetzner Cloud LoadBalancerType client and provides some +// additional helper functions. type LoadBalancerTypeClient interface { hcloud.ILoadBalancerTypeClient Names() []string @@ -15,6 +17,7 @@ type LoadBalancerTypeClient interface { LoadBalancerTypeDescription(id int64) string } +// NewLoadBalancerTypeClient creates a new LoadBalancerTypeClient. func NewLoadBalancerTypeClient(client hcloud.ILoadBalancerTypeClient) LoadBalancerTypeClient { return &loadBalancerTypeClient{ ILoadBalancerTypeClient: client, diff --git a/internal/hcapi2/loadbalancer.go b/internal/hcapi2/loadbalancer.go index 2aff0526..36eba081 100644 --- a/internal/hcapi2/loadbalancer.go +++ b/internal/hcapi2/loadbalancer.go @@ -17,6 +17,7 @@ type LoadBalancerClient interface { LabelKeys(string) []string } +// NewLoadBalancerClient creates a new LoadBalancerClient. func NewLoadBalancerClient(client hcloud.ILoadBalancerClient) LoadBalancerClient { return &loadBalancerClient{ ILoadBalancerClient: client, diff --git a/internal/hcapi2/location.go b/internal/hcapi2/location.go index fffebe65..af3e2f48 100644 --- a/internal/hcapi2/location.go +++ b/internal/hcapi2/location.go @@ -15,6 +15,7 @@ type LocationClient interface { NetworkZones() []string } +// NewLocationClient creates a new LocationClient. func NewLocationClient(client hcloud.ILocationClient) LocationClient { return &locationClient{ ILocationClient: client, diff --git a/internal/hcapi2/mock/client.go b/internal/hcapi2/mock/client.go index 765d6ad8..ddb11612 100644 --- a/internal/hcapi2/mock/client.go +++ b/internal/hcapi2/mock/client.go @@ -8,6 +8,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// Client is a mock client. type Client struct { ActionClient *MockActionClient CertificateClient *MockCertificateClient @@ -30,6 +31,7 @@ type Client struct { PricingClient *MockPricingClient } +// NewMockClient creates a new mock client. func NewMockClient(ctrl *gomock.Controller) *Client { return &Client{ ActionClient: NewMockActionClient(ctrl), @@ -54,85 +56,107 @@ func NewMockClient(ctrl *gomock.Controller) *Client { } } +// Action returns a mock of the ActionClient interface. func (c *Client) Action() hcapi2.ActionClient { return c.ActionClient } +// Certificate returns a mock of the CertificateClient interface. func (c *Client) Certificate() hcapi2.CertificateClient { return c.CertificateClient } +// Datacenter returns a mock of the DatacenterClient interface. func (c *Client) Datacenter() hcapi2.DatacenterClient { return c.DatacenterClient } +// Firewall returns a mock of the FirewallClient interface. func (c *Client) Firewall() hcapi2.FirewallClient { return c.FirewallClient } +// FloatingIP returns a mock of the FloatingIPClient interface. func (c *Client) FloatingIP() hcapi2.FloatingIPClient { return c.FloatingIPClient } +// PrimaryIP returns a mock of the PrimaryIPClient interface. func (c *Client) PrimaryIP() hcapi2.PrimaryIPClient { return c.PrimaryIPClient } +// Image returns a mock of the ImageClient interface. func (c *Client) Image() hcapi2.ImageClient { return c.ImageClient } +// ISO returns a mock of the ISOClient interface. func (c *Client) ISO() hcapi2.ISOClient { return c.ISOClient } +// Location returns a mock of the LocationClient interface. func (c *Client) Location() hcapi2.LocationClient { return c.LocationClient } +// LoadBalancer returns a mock of the LoadBalancerClient interface. func (c *Client) LoadBalancer() hcapi2.LoadBalancerClient { return c.LoadBalancerClient } +// LoadBalancerType returns a mock of the LoadBalancerTypeClient interface. func (c *Client) LoadBalancerType() hcapi2.LoadBalancerTypeClient { return c.LoadBalancerTypeClient } +// Network returns a mock of the NetworkClient interface. func (c *Client) Network() hcapi2.NetworkClient { return c.NetworkClient } +// Server returns a mock of the ServerClient interface. func (c *Client) Server() hcapi2.ServerClient { return c.ServerClient } +// ServerType returns a mock of the ServerTypeClient interface. func (c *Client) ServerType() hcapi2.ServerTypeClient { return c.ServerTypeClient } +// SSHKey returns a mock of the SSHKeyClient interface. func (c *Client) SSHKey() hcapi2.SSHKeyClient { return c.SSHKeyClient } +// Volume returns a mock of the VolumeClient interface. func (c *Client) Volume() hcapi2.VolumeClient { return c.VolumeClient } + +// RDNS returns a mock of the RDNSClient interface. func (c *Client) RDNS() hcapi2.RDNSClient { return c.RDNSClient } +// PlacementGroup returns a mock of the PlacementGroupClient interface. func (c *Client) PlacementGroup() hcapi2.PlacementGroupClient { return c.PlacementGroupClient } +// Pricing returns a mock of the PricingClient interface. func (c *Client) Pricing() hcapi2.PricingClient { return c.PricingClient } +// WithOpts is a no-op. func (*Client) WithOpts(_ ...hcloud.ClientOption) { // no-op } +// FromConfig is a no-op. func (*Client) FromConfig(_ config.Config) { // no-op } diff --git a/internal/hcapi2/network.go b/internal/hcapi2/network.go index e9668ad9..b57e17eb 100644 --- a/internal/hcapi2/network.go +++ b/internal/hcapi2/network.go @@ -17,6 +17,7 @@ type NetworkClient interface { LabelKeys(string) []string } +// NewNetworkClient creates a new NetworkClient. func NewNetworkClient(client hcloud.INetworkClient) NetworkClient { return &networkClient{ INetworkClient: client, diff --git a/internal/hcapi2/placement_group.go b/internal/hcapi2/placement_group.go index 12502217..422808ff 100644 --- a/internal/hcapi2/placement_group.go +++ b/internal/hcapi2/placement_group.go @@ -7,12 +7,15 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// PlacementGroupClient embeds the Hetzner Cloud PlacementGroup client and provides some +// additional helper functions. type PlacementGroupClient interface { hcloud.IPlacementGroupClient Names() []string LabelKeys(string) []string } +// NewPlacementGroupClient creates a new PlacementGroupClient. func NewPlacementGroupClient(client hcloud.IPlacementGroupClient) PlacementGroupClient { return &placementGroupClient{ IPlacementGroupClient: client, diff --git a/internal/hcapi2/pricing.go b/internal/hcapi2/pricing.go index 9d7e6475..d97ad209 100644 --- a/internal/hcapi2/pricing.go +++ b/internal/hcapi2/pricing.go @@ -10,6 +10,7 @@ type PricingClient interface { hcloud.IPricingClient } +// NewPricingClient creates a new PricingClient. func NewPricingClient(client hcloud.IPricingClient) PricingClient { return &pricingClient{ IPricingClient: client, diff --git a/internal/hcapi2/rdns.go b/internal/hcapi2/rdns.go index cb948c84..14ee8575 100644 --- a/internal/hcapi2/rdns.go +++ b/internal/hcapi2/rdns.go @@ -2,11 +2,12 @@ package hcapi2 import "github.com/hetznercloud/hcloud-go/v2/hcloud" -// NewRDNSClient embeds the Hetzner Cloud rdns client. +// RDNSClient embeds the Hetzner Cloud RDNS client. type RDNSClient interface { hcloud.IRDNSClient } +// NewRDNSClient creates a new RDNS client. func NewRDNSClient(client hcloud.IRDNSClient) RDNSClient { return &rdnsClient{ IRDNSClient: client, diff --git a/internal/hcapi2/server.go b/internal/hcapi2/server.go index 862e424a..e6cac2f5 100644 --- a/internal/hcapi2/server.go +++ b/internal/hcapi2/server.go @@ -8,6 +8,8 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ServerClient embeds the Hetzner Cloud Server client and provides some +// additional helper functions. type ServerClient interface { hcloud.IServerClient ServerName(id int64) string @@ -15,6 +17,7 @@ type ServerClient interface { LabelKeys(idOrName string) []string } +// NewServerClient creates a new ServerClient. func NewServerClient(client *hcloud.ServerClient) ServerClient { return &serverClient{ IServerClient: client, diff --git a/internal/hcapi2/server_type.go b/internal/hcapi2/server_type.go index 7e1718ba..b1dd37f4 100644 --- a/internal/hcapi2/server_type.go +++ b/internal/hcapi2/server_type.go @@ -8,6 +8,8 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ServerTypeClient embeds the Hetzner Cloud ServerType client and provides some additional +// helper functions. type ServerTypeClient interface { hcloud.IServerTypeClient Names() []string @@ -15,6 +17,7 @@ type ServerTypeClient interface { ServerTypeDescription(id int64) string } +// NewServerTypeClient creates a new ServerType client. func NewServerTypeClient(client hcloud.IServerTypeClient) ServerTypeClient { return &serverTypeClient{ IServerTypeClient: client, diff --git a/internal/hcapi2/sshkey.go b/internal/hcapi2/sshkey.go index e3fd1dc4..f1dcf0a7 100644 --- a/internal/hcapi2/sshkey.go +++ b/internal/hcapi2/sshkey.go @@ -15,6 +15,7 @@ type SSHKeyClient interface { LabelKeys(idOrName string) []string } +// NewSSHKeyClient creates a new SSHKeyClient. func NewSSHKeyClient(client hcloud.ISSHKeyClient) SSHKeyClient { return &sshKeyClient{ ISSHKeyClient: client, diff --git a/internal/hcapi2/volume.go b/internal/hcapi2/volume.go index 50cee43d..c7932e1e 100644 --- a/internal/hcapi2/volume.go +++ b/internal/hcapi2/volume.go @@ -15,6 +15,7 @@ type VolumeClient interface { LabelKeys(idOrName string) []string } +// NewVolumeClient creates a new Volume client. func NewVolumeClient(client hcloud.IVolumeClient) VolumeClient { return &volumeClient{ IVolumeClient: client, diff --git a/internal/state/command_helpers.go b/internal/state/command_helpers.go index e18f5c78..4283fa62 100644 --- a/internal/state/command_helpers.go +++ b/internal/state/command_helpers.go @@ -10,14 +10,17 @@ import ( //go:generate go run github.com/golang/mock/mockgen -package state -destination zz_command_helper_mock.go . ActionWaiter,TokenEnsurer +// ActionWaiter is a helper interface for waiting for actions. type ActionWaiter interface { WaitForActions(context.Context, *cobra.Command, ...*hcloud.Action) error } +// TokenEnsurer is a helper interface for ensuring the token is set. type TokenEnsurer interface { EnsureToken(cmd *cobra.Command, args []string) error } +// WrapCtx wraps a function that takes a context as its first argument to be used as a Cobra command function. func WrapCtx( ctx context.Context, fn func(context.Context, *cobra.Command, []string) error, diff --git a/internal/state/config/config.go b/internal/state/config/config.go index 106068fd..55566c7f 100644 --- a/internal/state/config/config.go +++ b/internal/state/config/config.go @@ -16,6 +16,7 @@ import ( "github.com/hetznercloud/cli/internal/cmd/util" ) +// Config represents the configuration of the CLI type Config interface { // Write writes the config to the given writer. If w is nil, the config is written to the config file. Write(w io.Writer) error @@ -56,6 +57,7 @@ type Config interface { Schema() *Schema } +// Schema represents the structure of the config file type Schema struct { ActiveContext string `toml:"active_context"` Preferences Preferences `toml:"preferences"` @@ -72,6 +74,7 @@ type config struct { schema Schema } +// New creates a new Config instance func New() Config { cfg := &config{} cfg.reset() diff --git a/internal/state/config/config_mock.go b/internal/state/config/config_mock.go index ac72d0e3..1975edb7 100644 --- a/internal/state/config/config_mock.go +++ b/internal/state/config/config_mock.go @@ -8,10 +8,12 @@ import ( // We do not need to generate a gomock for the Config, since you can set config // values during tests with viper.Set() +// MockConfig is a mock implementation of Config type MockConfig struct { Config } +// Write writes the configuration to the given writer func (c *MockConfig) Write(_ io.Writer) error { // MockConfig always writes to stdout for testing purposes return c.Config.Write(os.Stdout) diff --git a/internal/state/config/config_unix.go b/internal/state/config/config_unix.go index d6ce3a19..4f5236ec 100644 --- a/internal/state/config/config_unix.go +++ b/internal/state/config/config_unix.go @@ -7,6 +7,7 @@ import ( "path/filepath" ) +// DefaultConfigPath returns the default path to the config file on unix. func DefaultConfigPath() string { usr, err := user.Current() if err != nil { diff --git a/internal/state/config/context.go b/internal/state/config/context.go index f1b28a4e..57e2ee2a 100644 --- a/internal/state/config/context.go +++ b/internal/state/config/context.go @@ -1,11 +1,13 @@ package config +// Context represents a context in the config. type Context interface { Name() string Token() string Preferences() Preferences } +// NewContext creates a new context with the given name and token. func NewContext(name, token string) Context { return &context{ ContextName: name, @@ -19,6 +21,7 @@ type context struct { ContextPreferences Preferences `toml:"preferences"` } +// Name returns the name of the context. func (ctx *context) Name() string { return ctx.ContextName } @@ -29,6 +32,7 @@ func (ctx *context) Token() string { return ctx.ContextToken } +// Preferences returns the preferences for the context. func (ctx *context) Preferences() Preferences { if ctx.ContextPreferences == nil { ctx.ContextPreferences = make(Preferences) @@ -36,6 +40,7 @@ func (ctx *context) Preferences() Preferences { return ctx.ContextPreferences } +// ContextNames returns the names of all contexts in the config as a string slice. func ContextNames(cfg Config) []string { ctxs := cfg.Contexts() names := make([]string, len(ctxs)) @@ -45,6 +50,7 @@ func ContextNames(cfg Config) []string { return names } +// ContextByName returns the context with the given name or nil if no such context exists. func ContextByName(cfg Config, name string) Context { for _, c := range cfg.Contexts() { if c.Name() == name { @@ -54,6 +60,7 @@ func ContextByName(cfg Config, name string) Context { return nil } +// RemoveContext removes a context from the config. func RemoveContext(cfg Config, context Context) { var filtered []Context for _, c := range cfg.Contexts() { diff --git a/internal/state/config/options.go b/internal/state/config/options.go index a074d959..1d143a76 100644 --- a/internal/state/config/options.go +++ b/internal/state/config/options.go @@ -12,6 +12,8 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// OptionFlag is a bitmask that defines the flags for an option. Flags define an option's behavior and where it can be set. +// Flags can be combined using the bitwise OR operator. type OptionFlag int const ( @@ -30,9 +32,12 @@ const ( // OptionFlagHidden indicates that the option should not be shown in the help output OptionFlagHidden + // DefaultPreferenceFlags is the default set of flags for an option DefaultPreferenceFlags = OptionFlagPreference | OptionFlagConfig | OptionFlagPFlag | OptionFlagEnv ) +// IOption is an interface for configuration options. It is needed since the Option type is generic and can thus +// not be used in a map. type IOption interface { // addToFlagSet adds the option to the provided flag set addToFlagSet(fs *pflag.FlagSet) @@ -70,6 +75,7 @@ type overrides struct { flagName string } +// Options is a map of all available configuration options var Options = make(map[string]IOption) // Note: &^ is the bit clear operator and is used to remove flags from the default flag set @@ -243,6 +249,8 @@ var ( ) ) +// Option is a configuration option that can be set via the config file, environment variable, or command line flag. +// The option can be of any type and is converted to the desired type when retrieved. type Option[T any] struct { Name string Description string diff --git a/internal/state/config/preferences.go b/internal/state/config/preferences.go index c1db4166..486a20fd 100644 --- a/internal/state/config/preferences.go +++ b/internal/state/config/preferences.go @@ -12,6 +12,7 @@ import ( // Preferences are options that can be set in the config file, globally or per context type Preferences map[string]any +// Get returns a preference from the preferences map func (p Preferences) Get(key string) (any, bool) { var m map[string]any = p path := splitPath(key) @@ -29,6 +30,7 @@ func (p Preferences) Get(key string) (any, bool) { return nil, false } +// Set sets a preference in the preferences map func (p Preferences) Set(key string, val any) { var m map[string]any = p path := splitPath(key) @@ -47,6 +49,7 @@ func (p Preferences) Set(key string, val any) { } } +// Unset removes a preference from the preferences map func (p Preferences) Unset(key string) bool { var m map[string]any = p path := splitPath(key) @@ -75,6 +78,7 @@ func (p Preferences) Unset(key string) bool { return false } +// Validate checks if the preferences are valid func (p Preferences) Validate() error { return validate(p, "") } diff --git a/internal/state/helpers.go b/internal/state/helpers.go index f1816566..0b7d6aa4 100644 --- a/internal/state/helpers.go +++ b/internal/state/helpers.go @@ -8,12 +8,14 @@ import ( "github.com/hetznercloud/cli/internal/state/config" ) +// Wrap wraps a function that takes a State as its first argument and returns a cobra.RunE function. func Wrap(s State, f func(State, *cobra.Command, []string) error) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { return f(s, cmd, args) } } +// EnsureToken ensures that a token is set in the config. func (c *state) EnsureToken(_ *cobra.Command, _ []string) error { token, err := config.OptionToken.Get(c.config) if err != nil { diff --git a/internal/state/state.go b/internal/state/state.go index 7d2cc68f..9af7c22c 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -14,6 +14,8 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// State is the global state of the CLI. +// It provides access to the Hetzner Cloud API client, configuration, and utilities. type State interface { context.Context @@ -33,6 +35,7 @@ type state struct { term terminal.Terminal } +// New creates a new state, given a configuration. func New(cfg config.Config) (State, error) { s := &state{ Context: context.Background(), diff --git a/internal/testutil/cmd.go b/internal/testutil/cmd.go index 80ce749c..569f83d4 100644 --- a/internal/testutil/cmd.go +++ b/internal/testutil/cmd.go @@ -11,10 +11,12 @@ import ( "github.com/hetznercloud/cli/internal/state" ) +// TestableCommand is a command that can be tested. type TestableCommand interface { CobraCommand(state.State) *cobra.Command } +// TestCase is a test case for a command. type TestCase struct { Args []string PreRun func(t *testing.T, fx *Fixture) @@ -25,11 +27,15 @@ type TestCase struct { ExpErr string } +// DataType is the type of output that is expected from a command. type DataType string const ( + // DataTypeText is the default data type and does a simple string comparison. DataTypeText DataType = "text" + // DataTypeJSON expects the output to be valid JSON and compares it using JSONEq. DataTypeJSON DataType = "json" + // DataTypeYAML expects the output to be valid YAML and compares it using YAMLEq. DataTypeYAML DataType = "yaml" ) @@ -48,6 +54,7 @@ func (dt DataType) test(t *testing.T, expected string, actual string, _ ...any) } } +// TestCommand tests a command with the given test cases. func TestCommand(t *testing.T, cmd TestableCommand, cases map[string]TestCase) { for name, testCase := range cases { testCase := testCase diff --git a/internal/testutil/terminal/terminal.go b/internal/testutil/terminal/terminal.go index 6b8e2c2d..d5e8abb2 100644 --- a/internal/testutil/terminal/terminal.go +++ b/internal/testutil/terminal/terminal.go @@ -8,17 +8,21 @@ import ( //go:generate go run github.com/golang/mock/mockgen -package terminal -destination zz_terminal_mock.go . Terminal +// Terminal is an interface for terminal operations that can be mocked. type Terminal interface { StdoutIsTerminal() bool ReadPassword(fd int) ([]byte, error) } +// DefaultTerminal is the default implementation of Terminal. type DefaultTerminal struct{} +// StdoutIsTerminal returns true if stdout is a terminal. func (DefaultTerminal) StdoutIsTerminal() bool { return ui.StdoutIsTerminal() } +// ReadPassword reads a password from the terminal. func (DefaultTerminal) ReadPassword(fd int) ([]byte, error) { return term.ReadPassword(fd) } diff --git a/internal/ui/actions.go b/internal/ui/actions.go index caf72424..75b6c939 100644 --- a/internal/ui/actions.go +++ b/internal/ui/actions.go @@ -9,6 +9,7 @@ import ( "github.com/hetznercloud/hcloud-go/v2/hcloud" ) +// ActionMessage returns a string representation of the given action. func ActionMessage(action *hcloud.Action) string { return fmt.Sprintf("Waiting for %s", color.New(color.Bold).Sprint(action.Command)) } @@ -23,6 +24,7 @@ func FakeActionMessage(value string) string { return color.New(color.Bold).Sprint("") + value } +// ActionResourcesMessage returns a string representation of the given action resources. func ActionResourcesMessage(resources ...*hcloud.ActionResource) string { if len(resources) == 0 { return "" diff --git a/internal/ui/progress.go b/internal/ui/progress.go index 5071d873..a8912cd3 100644 --- a/internal/ui/progress.go +++ b/internal/ui/progress.go @@ -4,12 +4,14 @@ import ( "io" ) +// ProgressGroup is an interface for showing multiple progresses in the terminal. type ProgressGroup interface { Add(message string, resources string) Progress Start() error Stop() error } +// NewProgressGroup creates a new ProgressGroup with a given output writer. func NewProgressGroup(output io.Writer) ProgressGroup { if StdoutIsTerminal() && TerminalWidth() > 80 { return newTerminalProgressGroup(output) @@ -17,6 +19,7 @@ func NewProgressGroup(output io.Writer) ProgressGroup { return newScriptProgressGroup(output) } +// Progress is an interface for showing progress in the terminal. type Progress interface { Start() SetCurrent(value int) @@ -24,6 +27,7 @@ type Progress interface { SetError() } +// NewProgress creates a new Progress with a given output writer, message and resources. func NewProgress(output io.Writer, message string, resources string) Progress { if StdoutIsTerminal() && TerminalWidth() > 80 { return newTerminalProgress(output, message, resources)