func()

in astro/cli/astro/cmd/cmd.go [111:150]


func (cli *AstroCLI) Run(args []string) (exitCode int) {
	cli.commands.root.SetArgs(args)
	cli.commands.root.SetOutput(cli.stderr)

	userProvidedConfigPath, err := configPathFromArgs(args)
	if err != nil {
		fmt.Fprintln(cli.stderr, err.Error())
		return 1
	}

	configFilePath := firstExistingFilePath(
		append([]string{userProvidedConfigPath}, configFileSearchPaths...)...,
	)

	if configFilePath != "" {
		config, err := astro.NewConfigFromFile(configFilePath)
		if err != nil {
			fmt.Fprintln(cli.stderr, err.Error())
			return 1
		}

		cli.config = config
	}

	cli.configureDynamicUserFlags()

	if err := cli.commands.root.Execute(); err != nil {
		fmt.Fprintln(cli.stderr, err.Error())
		exitCode = 1 // exit with error

		// If we get an unknown flag, it could be because the user expected
		// config to be loaded but it wasn't. Display a message to the user to
		// let them know.
		if cli.config == nil && strings.Contains(err.Error(), "unknown flag") {
			fmt.Fprintln(cli.stderr, "NOTE: No astro config was loaded.")
		}
	}

	return exitCode
}