root.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package cmd
  2. import (
  3. "os"
  4. "github.com/gravitl/netmaker/cli/cmd/acl"
  5. "github.com/gravitl/netmaker/cli/cmd/commons"
  6. "github.com/gravitl/netmaker/cli/cmd/context"
  7. "github.com/gravitl/netmaker/cli/cmd/dns"
  8. "github.com/gravitl/netmaker/cli/cmd/enrollment_key"
  9. "github.com/gravitl/netmaker/cli/cmd/ext_client"
  10. "github.com/gravitl/netmaker/cli/cmd/host"
  11. "github.com/gravitl/netmaker/cli/cmd/metrics"
  12. "github.com/gravitl/netmaker/cli/cmd/network"
  13. "github.com/gravitl/netmaker/cli/cmd/network_user"
  14. "github.com/gravitl/netmaker/cli/cmd/node"
  15. "github.com/gravitl/netmaker/cli/cmd/server"
  16. "github.com/gravitl/netmaker/cli/cmd/user"
  17. "github.com/gravitl/netmaker/cli/cmd/usergroup"
  18. "github.com/spf13/cobra"
  19. )
  20. // rootCmd represents the base command when called without any subcommands
  21. var rootCmd = &cobra.Command{
  22. Use: "nmctl",
  23. Short: "CLI for interacting with Netmaker Server",
  24. Long: `CLI for interacting with Netmaker Server`,
  25. }
  26. // GetRoot returns the root of all subcommands
  27. func GetRoot() *cobra.Command {
  28. return rootCmd
  29. }
  30. // Execute adds all child commands to the root command and sets flags appropriately.
  31. // This is called by main.main(). It only needs to happen once to the rootCmd.
  32. func Execute() {
  33. err := rootCmd.Execute()
  34. if err != nil {
  35. os.Exit(1)
  36. }
  37. }
  38. func init() {
  39. rootCmd.PersistentFlags().StringVarP(&commons.OutputFormat, "output", "o", "", "List output in specific format (Enum:- json)")
  40. // Bind subcommands here
  41. rootCmd.AddCommand(network.GetRoot())
  42. rootCmd.AddCommand(context.GetRoot())
  43. rootCmd.AddCommand(acl.GetRoot())
  44. rootCmd.AddCommand(node.GetRoot())
  45. rootCmd.AddCommand(dns.GetRoot())
  46. rootCmd.AddCommand(server.GetRoot())
  47. rootCmd.AddCommand(ext_client.GetRoot())
  48. rootCmd.AddCommand(user.GetRoot())
  49. rootCmd.AddCommand(usergroup.GetRoot())
  50. rootCmd.AddCommand(metrics.GetRoot())
  51. rootCmd.AddCommand(network_user.GetRoot())
  52. rootCmd.AddCommand(host.GetRoot())
  53. rootCmd.AddCommand(enrollment_key.GetRoot())
  54. }