Beispiel #1
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
}
Beispiel #2
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()
}
Beispiel #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 {
		if len(os.Getenv(EnvDepconMode)) > 0 && os.Getenv(EnvDepconMode) == ModeMarathon {
			configFile = marathonConfigFromEnv()
			executeWithExistingConfig()
		} else {
			if len(os.Args) >= 4 && os.Args[1] == "config" && os.Args[2] == "env" && os.Args[3] == "add-marathon" {
				configFile, _ = cliconfig.Load("")
				rootCmd.AddCommand(configCmd)
				rootCmd.Execute()
				return
			}
			logger.Logger().Error("%s file not found.  Generating initial configuration", file.Filename())
			configFile = cliconfig.CreateNewConfigFromUserInput()
		}
	}
}