Esempio n. 1
0
func runAppList(cmd *cobra.Command, args []string) int {
	if len(args) != 1 {
		cmd.Usage()
		return 1
	}

	apps, err := rkt.AppsForPod(args[0], getDataDir(), "")
	if err != nil {
		stderr.PrintE("error listing apps", err)
		return 1
	}

	tabBuffer := new(bytes.Buffer)
	tabOut := getTabOutWithWriter(tabBuffer)

	if !flagNoLegend {
		fmt.Fprintf(tabOut, "NAME\tSTATE\n")
	}

	for _, app := range apps {
		fmt.Fprintf(tabOut, "%s\t%s\n", app.Name, app.State)
	}

	tabOut.Flush()
	stdout.Print(tabBuffer)
	return 0
}
Esempio n. 2
0
func runAppStatus(cmd *cobra.Command, args []string) (exit int) {
	if len(args) != 1 || flagAppName == "" {
		cmd.Usage()
		return 1
	}

	apps, err := rkt.AppsForPod(args[0], getDataDir(), flagAppName)
	if err != nil {
		stderr.PrintE("error getting app status", err)
		return 1
	}

	if len(apps) == 0 {
		stderr.Error(fmt.Errorf("cannot find app %q in the pod", flagAppName))
		return 1
	}

	// Must have only 1 app.
	if len(apps) != 1 {
		stderr.Error(fmt.Errorf("find more than one app with the name %q", flagAppName))
		return 1
	}

	// TODO(yifan): Print yamls.
	switch flagFormat {
	case outputFormatJSON:
		result, err := json.Marshal(apps[0])
		if err != nil {
			stderr.PrintE("error marshaling the app status", err)
			return 1
		}
		stdout.Print(string(result))
	case outputFormatPrettyJSON:
		result, err := json.MarshalIndent(apps[0], "", "\t")
		if err != nil {
			stderr.PrintE("error marshaling the app status", err)
			return 1
		}
		stdout.Print(string(result))
	default:
		printApp(apps[0])
	}

	return 0
}