func buildRootCmd()

in packages/cli/cmd/application/main.go [89:136]


func buildRootCmd() *cobra.Command {
	vars := mainVars{}
	formatVars := formatVars{}
	cmd := &cobra.Command{
		Use:   "agc",
		Short: shortDescription,
		Example: `
  Displays the help menu for the specified sub-command.
  /code $ agc account --help`,
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			setLoggingLevel()
			setFormatter(formatVars)
			checkCliVersion()
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			if vars.docPath != "" {
				err := BuildCommandDocsForHugo(cmd, vars.docPath)
				if err != nil {
					return clierror.New("agc", args, err)
				}
			}
			return nil
		},
		SilenceUsage:  true,
		SilenceErrors: false,
	}

	// Sets version for --version flag. Version command gives more detailed
	// version information.
	cmd.Version = version.Version
	cmd.SetVersionTemplate("agc version: {{.Version}}\n")

	cmd.AddCommand(cli.BuildAccountCommand())
	cmd.AddCommand(cli.BuildProjectCommand())
	cmd.AddCommand(cli.BuildContextCommand())
	cmd.AddCommand(cli.BuildLogsCommand())
	cmd.AddCommand(cli.BuildWorkflowCommand())
	cmd.AddCommand(cli.BuildConfigureCommand())

	cmd.SetUsageTemplate(template.RootUsage)

	cmd.PersistentFlags().BoolVarP(&logging.Verbose, cli.VerboseFlag, cli.VerboseFlagShort, false, cli.VerboseFlagDescription)
	cmd.PersistentFlags().StringVar(&formatVars.format, cli.FormatFlag, "", cli.FormatFlagDescription)
	cmd.Flags().StringVar(&vars.docPath, "docs", "", "generate markdown documenting the CLI to the specified path")
	cmd.Flag("docs").Hidden = true

	return cmd
}