예제 #1
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"))
	}
}
예제 #2
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"))
	}
}