func executeWithExistingConfig() { envName := findEnvNameFromArgs() if envName == "" { if _, single := configFile.DetermineIfServiceIsRooted(); single { envName = configFile.GetEnvironments()[0] } else { if configFile.DefaultEnv != "" { envName = configFile.DefaultEnv } else { rootCmd.Execute() logger.Logger().Error("Multiple environments are defined in config. You must execute with -e envname.") printValidEnvironments() return } } } if _, err := configFile.GetEnvironment(envName); err != nil { logger.Logger().Error("'%s' environment could not be found in config (%s)\n\n", envName, configFile.Filename()) printValidEnvironments() os.Exit(1) } else { viper.Set(ViperEnv, envName) if configFile.RootService { marathon.AddJailedMarathonToCmd(rootCmd, configFile) } else { marathon.AddMarathonToCmd(rootCmd, configFile) } } rootCmd.AddCommand(configCmd) rootCmd.Execute() }
// Main Entry point called by main - responsible for detecting if this is a first run without a config // to force initial setup func Execute() { file, found := cliconfig.HasExistingConfig() if found { configFile = file executeWithExistingConfig() } else { logger.Logger().Error("%s file not found. Generating initial configuration", file.Filename()) configFile = cliconfig.CreateNewConfigFromUserInput() } }
// Main Entry point called by main - responsible for detecting if this is a first run without a config // to force initial setup func Execute() { rootCmd.Long = fmt.Sprintf(DepConHelp, Version, BuildDate) file, found := cliconfig.HasExistingConfig() if found { configFile = file executeWithExistingConfig() } else { logger.Logger().Error("%s file not found. Generating initial configuration", file.Filename()) configFile = cliconfig.CreateNewConfigFromUserInput() } }
func determineEnvironment() string { envName := findEnvNameFromArgs() if envName == "" { if _, single := configFile.DetermineIfServiceIsRooted(); single { envName = configFile.GetEnvironments()[0] } else { if configFile.DefaultEnv != "" { envName = configFile.DefaultEnv } else { rootCmd.Execute() logger.Logger().Error("Multiple environments are defined in config. You must execute with -e envname.") printValidEnvironments() return "" } } } return envName }
func executeWithExistingConfig() { envName := determineEnvironment() if envName == "" { os.Exit(1) } if _, err := configFile.GetEnvironment(envName); err != nil { logger.Logger().Error("'%s' environment could not be found in config (%s)\n\n", envName, configFile.Filename()) printValidEnvironments() os.Exit(1) } else { viper.Set(ViperEnv, envName) if configFile.RootService { marathon.AddJailedMarathonToCmd(rootCmd, configFile) } else { marathon.AddMarathonToCmd(rootCmd, configFile) } } compose.AddComposeToCmd(rootCmd, nil) rootCmd.AddCommand(configCmd) rootCmd.Execute() }
func printColumn(formatter cli.Formatter) { err := formatter.ToColumns(os.Stdout) if err != nil { logger.Logger().Error("Error: %s", err.Error()) } }
func PrintError(err error) { logger.Logger().Error("%v", err.Error()) os.Exit(1) }