zones.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package cmd
  2. import (
  3. "github.com/spf13/cobra"
  4. )
  5. var zonesCmd = &cobra.Command{
  6. Use: "zones",
  7. Short: "List the zones the account can see",
  8. Long: `List every DNS zone the account has access to, with the name server that
  9. serves it.
  10. This is also the quickest way to check that credentials, context and network
  11. path are all working: it is read-only and touches nothing.
  12. The name server shown is the value the gateway requires when changing
  13. records, so this is what the write commands rely on.`,
  14. Example: ` # every zone
  15. schlundtech-dns zones
  16. # one zone per line, for scripting
  17. schlundtech-dns zones --output json`,
  18. Args: cobra.NoArgs,
  19. RunE: func(cmd *cobra.Command, _ []string) error {
  20. f, err := parseFormat(flagOutput)
  21. if err != nil {
  22. return err
  23. }
  24. c, err := client()
  25. if err != nil {
  26. return err
  27. }
  28. zones, err := c.Zones(cmd.Context())
  29. if err != nil {
  30. return err
  31. }
  32. rows := make([][]string, 0, len(zones))
  33. for _, z := range zones {
  34. rows = append(rows, []string{z.Name, z.SystemNS})
  35. }
  36. return writeOutput(cmd.OutOrStdout(), f, []string{"ZONE", "NAMESERVER"}, rows, zones)
  37. },
  38. }
  39. func init() {
  40. rootCmd.AddCommand(zonesCmd)
  41. }