예제 #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()
}
예제 #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()
	}
}
예제 #3
0
파일: depcon.go 프로젝트: f1yegor/depcon
// 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()
	}
}
예제 #4
0
파일: depcon.go 프로젝트: f1yegor/depcon
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
}
예제 #5
0
파일: depcon.go 프로젝트: f1yegor/depcon
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()
}
예제 #6
0
파일: format.go 프로젝트: f1yegor/depcon
func printColumn(formatter cli.Formatter) {
	err := formatter.ToColumns(os.Stdout)
	if err != nil {
		logger.Logger().Error("Error: %s", err.Error())
	}
}
예제 #7
0
파일: format.go 프로젝트: f1yegor/depcon
func PrintError(err error) {
	logger.Logger().Error("%v", err.Error())
	os.Exit(1)
}