Exemplo n.º 1
0
func AppList(configStore *config.Store, env string) error {

	envs := []string{env}

	if env == "" {
		var err error
		envs, err = configStore.ListEnvs()
		if err != nil {
			return err
		}
	}

	columns := []string{"NAME | ENV | VERSION | IMAGE ID | CONFIG | POOLS "}

	for _, env := range envs {

		appList, err := configStore.ListApps(env)
		if err != nil {
			return err
		}

		pools, err := configStore.ListPools(env)
		if err != nil {
			return err
		}

		for _, app := range appList {
			name := app.Name()
			versionDeployed := app.Version()
			versionID := app.VersionID()
			if len(versionID) > 12 {
				versionID = versionID[:12]
			}

			assignments := []string{}
			for _, pool := range pools {
				aa, err := configStore.ListAssignments(env, pool)
				if err != nil {
					return err
				}
				if utils.StringInSlice(app.Name(), aa) {
					assignments = append(assignments, pool)
				}
			}

			columns = append(columns, strings.Join([]string{
				name,
				env,
				versionDeployed,
				versionID,
				strconv.FormatInt(app.ID(), 10),
				strings.Join(assignments, ","),
			}, " | "))
		}
	}
	output := columnize.SimpleFormat(columns)
	fmt.Println(output)
	return nil
}
Exemplo n.º 2
0
// TODO: shouldn't the command cmd be printing the output, and not the package?
// The app, config, host, and runtime sections all do this too. (otherwise we
// should just combine the two packages). And why do we print the output here,
// but print the error in main???
func ListPools(configStore *config.Store, env string) error {
	var envs []string
	var err error

	if env != "" {
		envs = []string{env}
	} else {
		envs, err = configStore.ListEnvs()
		if err != nil {
			return err
		}

	}

	columns := []string{"ENV | POOL | APPS "}

	for _, env := range envs {

		pools, err := configStore.ListPools(env)
		if err != nil {
			return fmt.Errorf("ERROR: cannot list pools: %s", err)
		}

		if len(pools) == 0 {
			columns = append(columns, strings.Join([]string{
				env,
				"",
				""}, " | "))
			continue
		}

		for _, pool := range pools {

			assigments, err := configStore.ListAssignments(env, pool)
			if err != nil {
				fmt.Printf("ERROR: cannot list pool assignments for %s/%s: %s", env, pool, err)
			}

			columns = append(columns, strings.Join([]string{
				env,
				pool,
				strings.Join(assigments, ",")}, " | "))

		}
	}
	fmt.Println(columnize.SimpleFormat(columns))
	return nil
}