root.go 1.7 KB

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