Esempio n. 1
0
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()
}
Esempio n. 2
0
// 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()
	}
}
Esempio n. 3
0
// 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()
	}
}
Esempio n. 4
0
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
}
Esempio n. 5
0
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()
}
Esempio n. 6
0
func printColumn(formatter cli.Formatter) {
	err := formatter.ToColumns(os.Stdout)
	if err != nil {
		logger.Logger().Error("Error: %s", err.Error())
	}
}
Esempio n. 7
0
func PrintError(err error) {
	logger.Logger().Error("%v", err.Error())
	os.Exit(1)
}