Esempio n. 1
0
func (cmd *Wildcard) WildcardCommandApps(cliConnection plugin.CliConnection, args string) {
	introduction(cliConnection, args)
	output := getMatchedApps(cliConnection, args)
	mytable := table.NewTable([]string{("name"), ("requested state"), ("instances"), ("memory"), ("disk"), ("urls")})
	for _, app := range output {
		var urls []string
		for _, route := range app.Routes {
			if route.Host == "" {
				urls = append(urls, route.Domain.Name)
			}
			urls = append(urls, fmt.Sprintf("%s.%s", route.Host, route.Domain.Name))
		}
		runningInstances := strconv.Itoa(app.RunningInstances)
		if app.RunningInstances < 0 {
			runningInstances = "?"
		}
		mytable.Add(
			app.Name,
			app.State,
			runningInstances+"/"+strconv.Itoa(app.TotalInstances),
			formatters.ByteSize(app.Memory*formatters.MEGABYTE),
			formatters.ByteSize(app.DiskQuota*formatters.MEGABYTE),
			strings.Join(urls, ", "),
		)
	}
	mytable.Print()
	if len(output) == 0 {
		fmt.Println(table.WarningColor("No apps found matching"), table.WarningColor(args))
	}
}
Esempio n. 2
0
func (cmd *Wildcard) WildcardCommand(cliConnection plugin.CliConnection, args []string) {
	force := false
	if args[0] == "-f" {
		force = true
		args = append(args[:0], args[1:]...)
	}
	command := args[0]
	pattern := args[1]
	apps := getMatchedApps(cliConnection, pattern)
	if !force && len(apps) > 0 {
		cmd.WildcardCommandApps(cliConnection, pattern)
		fmt.Println("")
		fmt.Printf("Would you like to %s (%s)nteractively, (%s)ll, or (%s)ancel ?%s", command, table.PromptColor("i"), table.PromptColor("a"), table.PromptColor("c"), table.PromptColor(">"))
		var mode string
		fmt.Scanf("%s", &mode)
		if strings.EqualFold(mode, "a") || strings.EqualFold(mode, "all") {
			force = true
		} else if strings.EqualFold(mode, "i") || strings.EqualFold(mode, "interactively") {
			force = false
		} else {
			fmt.Println(table.WarningColor("Cancelled"))
			return
		}
	} else {
		introduction(cliConnection, pattern)
	}
	for _, app := range apps {
		coloredCommand := table.EntityNameColor(command)
		coloredAppName := table.EntityNameColor(app.Name)
		if !force {
			var confirmation string
			fmt.Printf("Really %s app %s?%s ", table.PromptColor(command), table.PromptColor(app.Name), table.PromptColor(">"))
			fmt.Scanf("%s", &confirmation)
			if !strings.EqualFold(confirmation, "y") && !strings.EqualFold(confirmation, "yes") {
				continue
			}
		}
		fmt.Println("Running command", coloredCommand, "on app", coloredAppName)
		args[1] = app.Name
		fmt.Println(args)
		_, err := cliConnection.CliCommand(args...)
		if err != nil {
			fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
		}
	}
	if len(apps) == 0 {
		fmt.Println(table.WarningColor("No apps found matching"), table.WarningColor(pattern))
	} else {
		fmt.Println(table.SuccessColor("OK"))
	}
}
Esempio n. 3
0
func (cmd *Wildcard) WildcardCommandDelete(cliConnection plugin.CliConnection, args string, force *bool, routes *bool) {
	output := getMatchedApps(cliConnection, args)
	exit := false
	if !*force && len(output) > 0 {
		cmd.WildcardCommandApps(cliConnection, args)
		fmt.Println("")
		fmt.Printf("Would you like to delete the apps (%s)nteractively, (%s)ll, or (%s)ancel this command?%s", table.PromptColor("i"), table.PromptColor("a"), table.PromptColor("c"), table.PromptColor(">"))
		var mode string
		fmt.Scanf("%s", &mode)
		if strings.EqualFold(mode, "a") || strings.EqualFold(mode, "all") {
			*force = true
		} else if strings.EqualFold(mode, "i") || strings.EqualFold(mode, "interactively") {
		} else {
			fmt.Println(table.WarningColor("Delete cancelled"))
			exit = true
		}
	} else {
		introduction(cliConnection, args)
	}
	if !exit {
		for _, app := range output {
			coloredAppName := table.EntityNameColor(app.Name)
			if *force && *routes {
				cliConnection.CliCommandWithoutTerminalOutput("delete", app.Name, "-f", "-r")
				fmt.Println("Deleting app", coloredAppName, "and its mapped routes")
			} else if *force {
				cliConnection.CliCommandWithoutTerminalOutput("delete", app.Name, "-f")
				fmt.Println("Deleting app", coloredAppName)
			} else {
				var confirmation string
				fmt.Printf("Really delete the app %s?%s ", table.PromptColor(app.Name), table.PromptColor(">"))
				fmt.Scanf("%s", &confirmation)
				if strings.EqualFold(confirmation, "y") || strings.EqualFold(confirmation, "yes") {
					if *routes {
						cliConnection.CliCommandWithoutTerminalOutput("delete", app.Name, "-f", "-r")
						fmt.Println("Deleting app", coloredAppName, "and its mapped routes")
					} else {
						cliConnection.CliCommandWithoutTerminalOutput("delete", app.Name, "-f")
						fmt.Println("Deleting app", coloredAppName)
					}
				}
			}
		}
	}
	if len(output) == 0 {
		fmt.Println(table.WarningColor("No apps found matching"), table.WarningColor(args))
	} else {
		fmt.Println(table.SuccessColor("OK"))
	}
}