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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
version: "2"

linters:
enable:
- revive
- misspell
- unconvert
exclusions:
rules:
- linters: [errcheck]
source: "fmt\\.Fprint"
- linters: [errcheck]
source: "\\.Body\\.Close\\(\\)"
# api.APIError is intentional: renaming to api.Error would be confusing
# next to the error interface. The package is internal so external callers
# are not a concern.
- linters: [revive]
path: "internal/api/apierror.go"
text: "stutters"

# Formatters are checked by `golangci-lint run` and applied by
# `golangci-lint fmt`. Enabling gofmt here makes CI fail on formatting drift,
# which the default linter set does not catch.
formatters:
enable:
- gofmt
exclusions:
generated: lax
6 changes: 3 additions & 3 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ var authLoginCmd = &cobra.Command{
Short: "Configure credentials interactively",
Example: ` namecom auth login
namecom auth login --profile staging`,
RunE: runAuthLogin,
RunE: runAuthLogin,
}

var authStatusCmd = &cobra.Command{
Use: "status",
Short: "Verify credentials by calling the API hello endpoint",
Example: ` namecom auth status
namecom auth status --profile staging`,
RunE: runAuthStatus,
RunE: runAuthStatus,
}

var authLogoutCmd = &cobra.Command{
Use: "logout",
Short: "Remove credentials for the active profile",
Example: ` namecom auth logout
namecom auth logout --profile staging`,
RunE: runAuthLogout,
RunE: runAuthLogout,
}

var loginProfile string
Expand Down
3 changes: 2 additions & 1 deletion cmd/cmdutil/cmdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (

type contextKey int

// Context keys for values stored by cmd/root.go's PersistentPreRunE.
const (
KeyOutput contextKey = iota
KeyOutput contextKey = iota
KeyClient
KeyConfig
KeyOverrides
Expand Down
6 changes: 3 additions & 3 deletions cmd/cmdutil/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func TestValidDNSAnswer(t *testing.T) {
{"A", "@", "1.2.3.4", false},
{"A", "@", "256.0.0.1", true},
{"A", "@", "not-an-ip", true},
{"A", "@", "::1", true}, // IPv6 for A record
{"A", "@", "::1", true}, // IPv6 for A record
{"AAAA", "@", "::1", false},
{"AAAA", "@", "1.2.3.4", true}, // IPv4 for AAAA record
{"AAAA", "@", "1.2.3.4", true}, // IPv4 for AAAA record
{"AAAA", "@", "not-an-ip", true},
{"CNAME", "www", "target.example.com.", false},
{"CNAME", "@", "target.example.com.", true}, // apex CNAME
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestDNSAnswerWarnings(t *testing.T) {
{"CNAME", "target.example.com", 0, false, "trailing dot"},
{"CNAME", "target.example.com.", 0, false, ""},
{"MX", "mail.example.com", 0, false, "priority"},
{"MX", "mail.example.com", 0, true, ""}, // priority explicitly set
{"MX", "mail.example.com", 0, true, ""}, // priority explicitly set
{"MX", "mail.example.com", 10, false, ""}, // non-zero priority
{"TXT", "v=spf1 ~all", 0, false, ""},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
updateTTL int64
updatePriority int64

exportZone bool
exportZone bool
importFile string
importDryRun bool
)
Expand Down
8 changes: 4 additions & 4 deletions cmd/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func cmdForCreate(t *testing.T, srv *httptest.Server) *cobra.Command {
t.Fatalf("api.New: %v", err)
}
out := &output.Config{
Format: output.FormatTable,
Color: output.ColorNever,
Writer: &bytes.Buffer{},
Format: output.FormatTable,
Color: output.ColorNever,
Writer: &bytes.Buffer{},
EWriter: &bytes.Buffer{},
}
cmd := &cobra.Command{}
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestDNSCreate_DomainNormalized(t *testing.T) {

func recordServer(t *testing.T, records []gen.Record, nextPage int32) *httptest.Server {
t.Helper()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(gen.ListRecordsResponseSchema{
Records: records,
Expand Down
24 changes: 12 additions & 12 deletions cmd/dnssec/dnssec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@ var (
)

var listCmd = &cobra.Command{
Use: "list <domain>",
Short: "List DNSSEC keys for a domain",
Example: ` namecom dnssec list example.com`,
Use: "list <domain>",
Short: "List DNSSEC keys for a domain",
Example: ` namecom dnssec list example.com`,
Args: cmdutil.ExactArgs(1),
RunE: runList,
ValidArgsFunction: cmdutil.CompleteDomains,
}

var getCmd = &cobra.Command{
Use: "get <domain> <digest>",
Short: "Get a specific DNSSEC key",
Example: ` namecom dnssec get example.com abc123def456`,
Use: "get <domain> <digest>",
Short: "Get a specific DNSSEC key",
Example: ` namecom dnssec get example.com abc123def456`,
Args: cmdutil.ExactArgs(2),
RunE: runGet,
ValidArgsFunction: cmdutil.CompleteDomains,
}

var createCmd = &cobra.Command{
Use: "create <domain>",
Short: "Add a DNSSEC key",
Example: ` namecom dnssec create example.com --algorithm 8 --digest-type 2 --key-tag 12345 --digest abc123`,
Use: "create <domain>",
Short: "Add a DNSSEC key",
Example: ` namecom dnssec create example.com --algorithm 8 --digest-type 2 --key-tag 12345 --digest abc123`,
Args: cmdutil.ExactArgs(1),
RunE: runCreate,
ValidArgsFunction: cmdutil.CompleteDomains,
}

var deleteCmd = &cobra.Command{
Use: "delete <domain> <digest>",
Short: "Remove a DNSSEC key",
Example: ` namecom dnssec delete example.com abc123def456`,
Use: "delete <domain> <digest>",
Short: "Remove a DNSSEC key",
Example: ` namecom dnssec delete example.com abc123def456`,
Args: cmdutil.ExactArgs(2),
RunE: runDelete,
ValidArgsFunction: cmdutil.CompleteDomains,
Expand Down
1 change: 0 additions & 1 deletion cmd/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func confirm(out *output.Config, yes bool, msg string) (bool, error) {
return cmdutil.Confirm(out, yes, msg)
}


// derefBool dereferences a *bool, returning false for nil.
func derefBool(b *bool) bool {
if b == nil {
Expand Down
12 changes: 6 additions & 6 deletions cmd/domain/list_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ func runList(cmd *cobra.Command, _ []string) error {
rows = append(rows, []string{
d.DomainName,
out.ExpiryDate(d.ExpireDate),
out.BoolBadge(bool(d.AutorenewEnabled)),
out.BoolBadge(bool(d.Locked)),
out.BoolBadge(bool(d.PrivacyEnabled)),
out.BoolBadge(d.AutorenewEnabled),
out.BoolBadge(d.Locked),
out.BoolBadge(d.PrivacyEnabled),
})
}
out.Table(headers, rows)
Expand Down Expand Up @@ -263,9 +263,9 @@ func runGet(cmd *cobra.Command, args []string) error {
{"Domain", d.DomainName},
{"Created", out.Dim(formatTime(d.CreateDate))},
{"Expires", out.ExpiryDate(d.ExpireDate)},
{"Auto-Renew", out.BoolBadge(bool(d.AutorenewEnabled))},
{"Locked", out.BoolBadge(bool(d.Locked))},
{"Privacy", out.BoolBadge(bool(d.PrivacyEnabled))},
{"Auto-Renew", out.BoolBadge(d.AutorenewEnabled)},
{"Locked", out.BoolBadge(d.Locked)},
{"Privacy", out.BoolBadge(d.PrivacyEnabled)},
{"Nameservers", out.Dim(formatNS(d.Nameservers))},
}
out.KVTable(rows)
Expand Down
8 changes: 4 additions & 4 deletions cmd/domain/list_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"context"
"encoding/json"
"net/http"
"strconv"
"net/http/httptest"
"strconv"
"testing"

"github.com/patramsey/namecom-cli/cmd/cmdutil"
Expand All @@ -25,9 +25,9 @@ func TestFilterToWildcard(t *testing.T) {
}{
{"acme", "*acme*"},
{"acme.io", "*acme.io*"},
{"*acme", "*acme"}, // already has wildcard — leave alone
{"acme*", "acme*"}, // already has wildcard — leave alone
{"*acme*", "*acme*"}, // already has wildcard — leave alone
{"*acme", "*acme"}, // already has wildcard — leave alone
{"acme*", "acme*"}, // already has wildcard — leave alone
{"*acme*", "*acme*"}, // already has wildcard — leave alone
}
for _, tt := range tests {
if got := filterToWildcard(tt.input); got != tt.want {
Expand Down
14 changes: 7 additions & 7 deletions cmd/domain/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ var autorenewCmd = &cobra.Command{
Short: "Enable or disable automatic renewal",
Example: ` namecom domain autorenew on example.com
namecom domain autorenew off example.com`,
Args: cmdutil.ExactArgs(2),
RunE: runAutorenew,
Args: cmdutil.ExactArgs(2),
RunE: runAutorenew,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return []string{"on", "off"}, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -131,8 +131,8 @@ var privacyCmd = &cobra.Command{
Short: "Enable or disable WHOIS privacy",
Example: ` namecom domain privacy on example.com
namecom domain privacy off example.com`,
Args: cmdutil.ExactArgs(2),
RunE: runPrivacy,
Args: cmdutil.ExactArgs(2),
RunE: runPrivacy,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return []string{"on", "off"}, cobra.ShellCompDirectiveNoFileComp
Expand Down Expand Up @@ -459,9 +459,9 @@ func runUpdate(cmd *cobra.Command, args []string) error {
return err
}

autorenew := bool(current.AutorenewEnabled)
privacy := bool(current.PrivacyEnabled)
locked := bool(current.Locked)
autorenew := current.AutorenewEnabled
privacy := current.PrivacyEnabled
locked := current.Locked
body := gen.UpdateDomainJSONRequestBody{
AutorenewEnabled: &autorenew,
PrivacyEnabled: &privacy,
Expand Down
18 changes: 9 additions & 9 deletions cmd/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ var listCmd = &cobra.Command{
}

var getCmd = &cobra.Command{
Use: "get <domain> <mailbox>",
Short: "Get an email forwarding entry",
Example: ` namecom email get example.com info`,
Use: "get <domain> <mailbox>",
Short: "Get an email forwarding entry",
Example: ` namecom email get example.com info`,
Args: cmdutil.ExactArgs(2),
RunE: runGet,
ValidArgsFunction: cmdutil.CompleteDomains,
Expand All @@ -57,18 +57,18 @@ var createCmd = &cobra.Command{
}

var updateCmd = &cobra.Command{
Use: "update <domain> <mailbox>",
Short: "Update an email forwarding entry",
Example: ` namecom email update example.com info --to newemail@gmail.com`,
Use: "update <domain> <mailbox>",
Short: "Update an email forwarding entry",
Example: ` namecom email update example.com info --to newemail@gmail.com`,
Args: cmdutil.ExactArgs(2),
RunE: runUpdate,
ValidArgsFunction: cmdutil.CompleteDomains,
}

var deleteCmd = &cobra.Command{
Use: "delete <domain> <mailbox>",
Short: "Delete an email forwarding entry",
Example: ` namecom email delete example.com info`,
Use: "delete <domain> <mailbox>",
Short: "Delete an email forwarding entry",
Example: ` namecom email delete example.com info`,
Args: cmdutil.ExactArgs(2),
RunE: runDelete,
ValidArgsFunction: cmdutil.CompleteDomains,
Expand Down
20 changes: 10 additions & 10 deletions cmd/order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ var listCmd = &cobra.Command{
}

var getCmd = &cobra.Command{
Use: "get <id>",
Short: "Get an order by ID",
Use: "get <id>",
Short: "Get an order by ID",
Example: ` namecom order get 12345`,
Args: cmdutil.ExactArgs(1),
RunE: runGet,
Args: cmdutil.ExactArgs(1),
RunE: runGet,
}

var refundCmd = &cobra.Command{
Use: "refund",
Short: "Process a refund for order items",
Use: "refund",
Short: "Process a refund for order items",
Example: ` namecom order refund --order-id 12345 --item-ids 67890 --yes`,
Args: cobra.NoArgs,
RunE: runRefund,
Args: cobra.NoArgs,
RunE: runRefund,
}

func init() {
Expand All @@ -79,7 +79,7 @@ func init() {
Cmd.AddCommand(listCmd, getCmd, refundCmd)
}

func runList(cmd *cobra.Command, args []string) error {
func runList(cmd *cobra.Command, _ []string) error {
out := cmdutil.Out(cmd)
client := cmdutil.APIClient(cmd)

Expand Down Expand Up @@ -217,7 +217,7 @@ func runGet(cmd *cobra.Command, args []string) error {
return nil
}

func runRefund(cmd *cobra.Command, args []string) error {
func runRefund(cmd *cobra.Command, _ []string) error {
out := cmdutil.Out(cmd)
client := cmdutil.APIClient(cmd)
yes := cmdutil.IsYes(cmd)
Expand Down
6 changes: 3 additions & 3 deletions cmd/order/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"context"
"encoding/json"
"net/http"
"strconv"
"net/http/httptest"
"strconv"
"testing"

"github.com/patramsey/namecom-cli/cmd/cmdutil"
Expand Down Expand Up @@ -155,8 +155,8 @@ func TestOrderList_StatusFilterPassedToAPI(t *testing.T) {

func TestOrderList_FilterAutoPages(t *testing.T) {
srv, requests := orderServer(t, [][]int32{
{101}, // page 1 — NextPage=2
{102}, // page 2 — no NextPage
{101}, // page 1 — NextPage=2
{102}, // page 2 — no NextPage
})
var stdout, stderr bytes.Buffer
cmd := cmdForOrderList(t, srv, &stdout, &stderr)
Expand Down
Loading
Loading