func initApp()

in cmd/root.go [177:213]


func initApp(cmd *cobra.Command, client *http.Client, v *viper.Viper) error {
	for _, cmdName := range excludedApplicationCommands {
		if cmd.Name() == cmdName {
			return nil
		}
	}

	if client == nil {
		return errors.New("cmd: root http client cannot be nil")
	}

	var c = ecctl.Config{
		Client:       client,
		OutputDevice: output.NewDevice(defaultOutput),
		ErrorDevice:  defaultError,
		UserAgent:    strings.Join([]string{"ecctl", versionInfo.Version}, "/"),
	}
	if err := v.Unmarshal(&c); err != nil {
		return err
	}

	// Set the default region to `ece-region` when the endpoint is not the ESS endpoint.
	if c.Region == "" && c.Host != api.ESSEndpoint {
		c.Region = cmdutil.DefaultECERegion
	}

	err := api.ReturnErrOnly(ecctl.Instance(c))
	// When no config file has been read and initApp returns an error, tell
	// the user how to initialize the application.
	if err != nil && v.ConfigFileUsed() == "" {
		return multierror.NewPrefixed(
			`missing ecctl config file, please use the "ecctl init" command to initialize ecctl`, err,
		)
	}

	return err
}