func newtCmd()

in newt/newt.go [60:144]


func newtCmd() *cobra.Command {
	newtHelpText := cli.FormatHelp(`Newt allows you to create your own embedded 
		application based on the Mynewt operating system.  Newt provides both 
		build and package management in a single tool, which allows you to 
		compose an embedded application, and set of projects, and then build
		the necessary artifacts from those projects.  For more information 
		on the Mynewt operating system, please visit 
		https://mynewt.apache.org/.`)
	newtHelpText += "\n\n" + cli.FormatHelp(`Please use the newt help command, 
		and specify the name of the command you want help for, for help on 
		how to use a specific command`)
	newtHelpEx := "  newt\n"
	newtHelpEx += "  newt help [<command-name>]\n"
	newtHelpEx += "    For help on <command-name>.  If not specified, " +
		"print this message."

	logLevelStr := ""
	newtCmd := &cobra.Command{
		Use:     "newt",
		Short:   "Newt is a tool to help you compose and build your own OS",
		Long:    newtHelpText,
		Example: newtHelpEx,
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			verbosity := util.VERBOSITY_DEFAULT
			if newtSilent {
				verbosity = util.VERBOSITY_SILENT
			} else if newtQuiet {
				verbosity = util.VERBOSITY_QUIET
			} else if newtVerbose {
				verbosity = util.VERBOSITY_VERBOSE
			}

			var err error
			NewtLogLevel, err = log.ParseLevel(logLevelStr)
			if err != nil {
				cli.NewtUsage(nil, util.NewNewtError(err.Error()))
			}

			err = util.Init(NewtLogLevel, newtLogFile, verbosity)
			if err != nil {
				cli.NewtUsage(nil, err)
			}

			newtutil.NewtNumJobs = newtNumJobs
		},
		Run: func(cmd *cobra.Command, args []string) {
			cmd.Help()
		},
	}

	newtCmd.PersistentFlags().BoolVarP(&newtVerbose, "verbose", "v", false,
		"Enable verbose output when executing commands")
	newtCmd.PersistentFlags().BoolVarP(&newtQuiet, "quiet", "q", false,
		"Be quiet; only display error output")
	newtCmd.PersistentFlags().BoolVarP(&newtSilent, "silent", "s", false,
		"Be silent; don't output anything")
	newtCmd.PersistentFlags().StringVarP(&logLevelStr, "loglevel", "l",
		"WARN", "Log level")
	newtCmd.PersistentFlags().StringVarP(&newtLogFile, "outfile", "o",
		"", "Filename to tee output to")
	newtCmd.PersistentFlags().IntVarP(&newtNumJobs, "jobs", "j",
		newtDfltNumJobs(), "Number of concurrent build jobs")
	newtCmd.PersistentFlags().BoolVarP(&newtHelp, "help", "h",
		false, "Help for newt commands")
	newtCmd.PersistentFlags().BoolVarP(&util.EscapeShellCmds, "escape", "",
		util.EscapeShellCmds, "Apply Windows escapes to shell commands")
	newtCmd.PersistentFlags().IntVarP(&util.ShallowCloneDepth, "shallow", "",
		util.ShallowCloneDepth, "Use shallow clone for git repositories up to specified number of commits")

	versHelpText := cli.FormatHelp(`Display the Newt version number`)
	versHelpEx := "  newt version"
	versCmd := &cobra.Command{
		Use:     "version",
		Short:   "Display the Newt version number",
		Long:    versHelpText,
		Example: versHelpEx,
		Run: func(cmd *cobra.Command, args []string) {
			newtutil.PrintNewtVersion()
		},
	}

	newtCmd.AddCommand(versCmd)

	return newtCmd
}