本文整理匯總了Golang中code/cloudfoundry/org/cli/plugin.CliConnection類的典型用法代碼示例。如果您正苦於以下問題:Golang CliConnection類的具體用法?Golang CliConnection怎麽用?Golang CliConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CliConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Delete
func Delete(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
urlValues := url.Values{}
urlValues.Add("names", args[1])
fmt.Printf("Deleting app %s...\n", appName)
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?%s", urlValues.Encode()))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
if _, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s", apps.Apps[0].Guid), "-X", "DELETE"); err != nil {
fmt.Printf("Failed to delete app %s\n", appName)
return
}
fmt.Println("OK")
}
示例2: Run
func (c *DemoCmd) Run(cliConnection plugin.CliConnection, args []string) {
switch args[0] {
case "list-apps":
fc, err := parseArguments(args)
if err != nil {
exit1(err.Error())
}
endpoint, err := cliConnection.ApiEndpoint()
if err != nil {
exit1("Error getting targeted endpoint: " + err.Error())
}
fmt.Printf("Listing apps @ endpoint %s/v2/apps...\n\n", endpoint)
allApps, err := getAllApps(cliConnection)
if err != nil {
exit1("Error curling v2/apps: " + err.Error())
}
for _, app := range allApps.Resources {
if (fc.IsSet("started") && app.Entity.State == "STARTED") ||
(fc.IsSet("stopped") && app.Entity.State == "STOPPED") ||
(!fc.IsSet("stopped") && !fc.IsSet("started")) {
fmt.Println(app.Entity.Name)
}
}
case "CLI-MESSAGE-UNINSTALL":
fmt.Println("Thanks for using this demo")
}
}
示例3: Poll
func Poll(cliConnection plugin.CliConnection, endpoint string, desired string, timeout time.Duration, timeoutMessage string) {
timeElapsed := 0 * time.Second
for timeElapsed < timeout {
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", endpoint, "-X", "GET")
FreakOut(err)
output := strings.Join(rawOutput, "")
if strings.Contains(output, desired) {
return
}
timeElapsed = timeElapsed + 1*time.Second
time.Sleep(1 * time.Second)
}
FreakOut(errors.New(timeoutMessage))
}
示例4: RunTask
func RunTask(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
taskName := args[2]
taskCommand := args[3]
fmt.Println("OK\n")
fmt.Printf("Running task %s on app %s...\n\n", taskName, appName)
go Logs(cliConnection, args)
time.Sleep(2 * time.Second) // b/c sharing the cliConnection makes things break
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
output := strings.Join(rawOutput, "")
apps := models.V3AppsModel{}
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
body := fmt.Sprintf(`{
"name": "%s",
"command": "%s"
}`, taskName, taskCommand)
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/tasks", appGuid), "-X", "POST", "-d", body)
if err != nil {
fmt.Printf("Failed to run task %s\n", taskName)
return
}
output = strings.Join(rawOutput, "")
task := models.V3TaskModel{}
err = json.Unmarshal([]byte(output), &task)
util.FreakOut(err)
if task.Guid == "" {
fmt.Printf("Failed to run task %s:\n%s\n", taskName, output)
return
}
util.Poll(cliConnection, fmt.Sprintf("/v3/tasks/%s", task.Guid), "SUCCEEDED", 1*time.Minute, "Task failed to run")
fmt.Printf("Task %s successfully completed.\n", task.Guid)
}
示例5: Tasks
func Tasks(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
fmt.Printf("Listing tasks for app %s...\n", appName)
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
output := strings.Join(rawOutput, "")
apps := V3AppsModel{}
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/tasks", appGuid), "-X", "GET")
FreakOut(err)
output = strings.Join(rawOutput, "")
tasks := V3TasksModel{}
err = json.Unmarshal([]byte(output), &tasks)
FreakOut(err)
if len(tasks.Tasks) > 0 {
tasksTable := NewTable([]string{("id"), ("state"), ("start time"), ("name"), ("command")})
for _, v := range tasks.Tasks {
tasksTable.Add(
strconv.Itoa(v.Id),
v.State,
v.CreatedAt.Format("Jan 2, 15:04:05 MST"),
v.Name,
v.Command,
)
}
tasksTable.Print()
} else {
fmt.Println("No v3 tasks found.")
}
}
示例6: Run
func (c *CliCmd) Run(cliConnection plugin.CliConnection, args []string) {
// Invoke the cf command passed as the set of arguments
// after the first argument.
//
// Calls to plugin.CliCommand([]string) must be done after the invocation
// of plugin.Start() to ensure the environment is bootstrapped.
output, err := cliConnection.CliCommand(args[1:]...)
// The call to plugin.CliCommand() returns an error if the cli command
// returns a non-zero return code. The output written by the CLI
// is returned in any case.
if err != nil {
fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
}
// Print the output returned from the CLI command.
fmt.Println("")
fmt.Println("---------- Command output from the plugin ----------")
for index, val := range output {
fmt.Println("#", index, " value: ", val)
}
fmt.Println("---------- FIN -----------")
}
示例7: Apps
func Apps(cliConnection plugin.CliConnection, args []string) {
mySpace, err := cliConnection.GetCurrentSpace()
util.FreakOut(err)
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("v3/apps?space_guids=%s", mySpace.Guid), "-X", "GET")
output := strings.Join(rawOutput, "")
util.FreakOut(err)
apps := V3AppsModel{}
err = json.Unmarshal([]byte(output), &apps)
util.FreakOut(err)
if len(apps.Apps) > 0 {
appsTable := util.NewTable([]string{("name"), ("total_desired_instances")})
for _, v := range apps.Apps {
appsTable.Add(
v.Name,
strconv.Itoa(v.Instances),
)
}
appsTable.Print()
} else {
fmt.Println("No v3 apps found.")
}
}
示例8: getAllApps
func getAllApps(cliConnection plugin.CliConnection) (AppsModel, error) {
nextURL := "v2/apps"
allApps := AppsModel{}
for nextURL != "" {
output, err := cliConnection.CliCommandWithoutTerminalOutput("curl", nextURL)
if err != nil {
return AppsModel{}, err
}
apps := AppsModel{}
err = json.Unmarshal([]byte(output[0]), &apps)
if err != nil {
return AppsModel{}, err
}
allApps.Resources = append(allApps.Resources, apps.Resources...)
nextURL = apps.NextURL
}
return allApps, nil
}
示例9: BindService
func BindService(cliConnection plugin.CliConnection, args []string) {
customParameters := "{}"
fc := flags.New()
fc.NewStringFlag("parameters", "c", "Valid JSON object containing service-specific configuration parameters, provided either in-line or in a file. For a list of supported configuration parameters, see documentation for the particular service offering.")
fc.Parse(args...)
if fc.IsSet("c") {
customParameters = fc.String("c")
}
appName := fc.Args()[1]
serviceInstanceName := fc.Args()[2]
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
serviceInstance, err := cliConnection.GetService(serviceInstanceName)
FreakOut(err)
serviceInstanceGuid := serviceInstance.Guid
body := fmt.Sprintf(`{
"type": "app",
"relationships": {
"app": {"guid" : "%s"},
"service_instance": {"guid": "%s"}
},
"data": {
"parameters": %s
}
}`, appGuid, serviceInstanceGuid, customParameters)
if _, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/service_bindings"), "-X", "POST", "-d", body); err != nil {
fmt.Printf("Failed to bind app %s to service instance %s\n", appName, serviceInstanceName)
return
}
fmt.Println("OK")
}
示例10: Processes
func Processes(cliConnection plugin.CliConnection, args []string) {
mySpace, err := cliConnection.GetCurrentSpace()
FreakOut(err)
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", "v3/processes?per_page=5000", "-X", "GET")
FreakOut(err)
output := strings.Join(rawOutput, "")
processes := V3ProcessesModel{}
err = json.Unmarshal([]byte(output), &processes)
FreakOut(err)
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", "v3/apps?per_page=5000", "-X", "GET")
FreakOut(err)
output = strings.Join(rawOutput, "")
apps := V3AppsModel{}
err = json.Unmarshal([]byte(output), &apps)
FreakOut(err)
appsMap := make(map[string]V3AppModel)
for _, app := range apps.Apps {
appsMap[app.Guid] = app
}
if len(processes.Processes) > 0 {
processesTable := NewTable([]string{("app"), ("type"), ("instances"), ("memory in MB"), ("disk in MB")})
for _, v := range processes.Processes {
if strings.Contains(v.Links.Space.Href, mySpace.Guid) {
appName := "N/A"
if v.Links.App.Href != "/v3/apps/" {
appGuid := strings.Split(v.Links.App.Href, "/v3/apps/")[1]
appName = appsMap[appGuid].Name
}
processesTable.Add(
appName,
v.Type,
strconv.Itoa(v.Instances),
strconv.Itoa(v.Memory)+"MB",
strconv.Itoa(v.Disk)+"MB",
)
}
}
processesTable.Print()
} else {
fmt.Println("No v3 processes found.")
}
}
示例11: Run
func (c *CoreCmd) Run(cliConnection plugin.CliConnection, args []string) {
if args[0] == "core-command" {
output, err := cliConnection.CliCommand(args[1:]...)
if err != nil {
fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
}
dumpOutput(output)
} else if args[0] == "core-command-quiet" {
output, err := cliConnection.CliCommandWithoutTerminalOutput(args[1:]...)
if err != nil {
fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
}
dumpOutput(output)
} else if args[0] == "awesomeness" {
cliConnection.CliCommand("plugins")
} else if len(args) == 2 && args[0] == "awesomeness" && args[1] == "easter_egg" {
fmt.Println(`
ZZZZ$Z$$$ZZ$$$$$77$777777777777777777777I77II7I?III?IIII???????+++????????++++++=++++++++++++++++++=++======+======+++++
ZZZZZZZZ$$ZZ$77777777777III777777I7777IIIIIIIII??IIIIII???????++++???????++++++++++++?????++++++++++========+===~+=+++++
ZZZZZZ$$$$$$77777$$77I77777777III77IIIIII7IIIII????II????I7$ZZZ$$7I???????++?+++++++++++++++++++++++==+=============++++
$ZZ77$7$$$$$777777777777I7777IIII77I777III?III??????IDNNMNNNNNDDDNNNDDO7????+++++=++=++++++++=++++====+========~~===++++
ZZ$$$7777$$$$$777777777777IIIIIIII7IIIIIIIIII?I??+IZNND8NNNMMMMNNNDDDNND8?+??+?++++++++++++++==+=+===++=======~~~====+++
$$$$$$$$Z$$$$7777777777I7I?II??IIIIII?III???????$DMNN8O8NNNNNNNNMMMMND8DNMD$+++?++==++++++++=======~===========~~======+
$$$$Z$$$$$$$7777I777IIIIII?IIIIIIIII?????+????ZNND8DDZZDDDDDDDNNNNNNMMMMNNNNNZ?++=====+++++++=====~~==~===~==~=~=~======
$$$7$$$7$777III777IIIIIIIIIII??III??III???++?$MNNDDD8$O88DDDNMNNNNNNMMMMMMDNMMN7+=====+++++==========~~~~~~~~~~=~======+
77777777777777IIIII7IIIII????????II?????++++$DN8Z7?+++=++???I$ODNNNMMMMMNNNNNMMM+=+===~==========~==~~~~~~~~~~~~=~======
$$77777777777I77IIIIIIII????II?III?????++++I8N$I?+======++???I$O8DDNNNMMNNNMNMNMZ+=+==~===~~====~==~~~~~~~~~~~~~~~======
$$77777777III77IIIIIIII??????I?I????+++++?I8NOI?=~~~~~~~~~==+?I7$ZDNNNNMMMMNNNMNMO+===~~===~~~~~~~~~~~~~~~~~~::~~=======
$$$$$$77II77IIIIIIIIIII?????????????+++++7NM87+=~:~~:~~~~~~==++I7$8DNNNMNMMMMMNMNMO=~=======~~~~~~~:~~~~~~:::::::~~=====
77777$$7IIII?II??II??????????++++??++===$NMNZI+=~~~~~~~~~~~==+?I7$OO8DNMNNNMNNMMNMM$==+++===~===~~~~~~~~:::::::::~~~====
7II?I7I77III???+????++???????++????+==~+$DMD$I+=======~=====+???I7$ZO8DDNNMMNNMMMMMD???+++++++==~=~~~~=~~~~~:::::~~~==+=
777I777$7II???????++++??????+++???++==+IONM8$I+============+++??II7$ZZODNNNMMMMMMMMM7?I??????+=====~~~~~~~~~~::::~~~===+
$7777$$ZZ7I7I??++?I?++?++???+++++++===7$DNNO7I++===~~=======++++++?I7$Z8NNNNNMNMNMMM8I7IIII7I+=====~+=~~::::~~~::~~~===+
ZZZOOZ8OO$7III?II77I?+++++++++=====+=?78DMMZI?=+===~=~=~==++=+++???II7Z8NMMMMMMMNMNMD7$$$I77I????+++?=~~~~~~~::::::~==++
O8888ZZZ88Z$$$$7777$7?I7?++=+=++====+7$8NMMOI?????+=+===?7$7IIIII77$ZZODNNMMMMMMNNMNN$OZ$7IIII?I??++?+?+=~~:~~:::::===++
O8DD8OOOOOOOZ$$$$$Z$$$Z$7I++++++====?$Z8MMM87?I77$I++++?$ZOZZZZOZ$OOOOO8NNMMMMMMNNNMMOZ$ZZ$$777I??+??+?+=~~:~~~::::~====
DDDD88OOOZZZZOOOZZOOOOZ$ZZ7+?+=++=++IOO8DNMDDDI777$ZI+?ZDDZ7$OOO8DMNO$ZODMMMNNNNMMMNMDOZZZZZ$III?I7$7I??=~~~~~~~:~==++++
888888888OOOO8OZO8OOOZO$7$Z+?+=+++??IZDNNMMOZDIZNDO7I=I8O$I?IOZZZZ???I7O8MMNNMMMMMMMMNOOZZZZZ7$$$77$77I++~:::::~:~====+?
DD8D8O8OOO888OOOZ8D8O88ZZ8+???IZO$???ONNMMMZIIII$Z7?+=7ZZ7??I77$7I++?I7ODMMMMMMMMNNNMMO8OOOZ$7$$$77$777I?=~~~~~~~===+++?
8D88OO88OOO8888OODD888OOO8OZ7$OO$8Z7ZO8NMMN7?+=====+?+I77I?=~~~~~=??I7Z8DMMMMNMMMMMNNMZZZZZ$$777$$$Z$$$7I+==~==~=====++?
8DDDO88888888DDD8DD88DD8O888OZ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ND88DNNDDNNNNNOOOOOOOZOZONDDMMMMMMMMMMMMMMMN8$7III777$$777I7I7$Z8NNNNNNNN88MMMMMNMND888DNZOO8DNZ77II777ZZ$7$O
NNNNNNDNDDD88888D8DNNNNNMDD8O8DD8DNDNNMMMMMMMMMMMMMMMDOZ$7II?I7777IIIII?7$$ODNDDDDDN88MNNMMNNND8OO8NODD8DN8O7II77$Z$$7$O
NNNNNNNNDDDDD888D8NDDDO8NMNMNNNMNNMMNNNMMMMMMMMMMMNDO7I?I????????I?++????I7Z8DDNN88N8DMNMNNMNDDNNNND88ZZOOZZ7II?IZ$ZZ7$$
NNNNNNNNNDDDD8DDNNDDDND8NMMMMMMNMNNMMMMMMMMNMMMNNZ$$7???++?+????+++++++++?I$O8NDDZ8D8DNNNNMMNDD8OZZZ7III???III7ZZ$ZOZZZ8
MMNDDNMMNNND8DNDNNNDD8DDNMNDNMMMMNMMMMMMMMMMMM8$7I???=++=++++++++==+==+++I7ZDDDDOZ8D8NNNNNNNNMND8888O7+?I?7$$77$$$$ZOOOO
NMMNNNNMNNNDDDNDDDD8888NMMNDNMMMMMMMMMMMMMMMMMZIII++++++==+=+++++==+++????7Z888DOZ8DDNNNNNNNNMNND88D8$?IIII777$$Z$$$Z$$$
NNNNNNMNNDDDNDDD8O8O8DDNMNNNNMMMMNNNMMMMMMMNNN7I?+++========++========++??I$8OO88O8DNMNNNNMDDNNMNDDDOO$I$7I??II??I777777
NNNMNNNND8DDD8DDO8D8DNDNDDNNDDNMNNNMMMMMMMNNNOI+++++=~~=====+====~=====+?I$$8DO88O8NNMNNNDD88DDDNNNN8OO8Z$77Z7?7O777$O$$
NDNNNDNNND8888O8OO8O8DDDNNDDDNNDNNMMMMMMNDDDO$?+==============~====+++++?I$8O888888MMMNN8ZZZ88DDNMMNND8Z$$IIIIII?IIII???
NNNMNDMMNM8Z8$ZOOO8OODDDDD888DNNMMMMMMMM8OZZO7++======~~~=======~~==++?+?I$ZOO8D88DND888OZOZ7ZZZO8DNMMMND88888Z77777I?I?
NNNNNDMMNMDDN$ZOZZOOZO88DN888DMMMMMMMMMMOZZ$$?=+===========~=====~===+++?I$ZOO8DDD8OOZ$$$7$$$8DDDDNMNNMMMD8O88OZ$$$OO77$
NNNNNNMMNNNDNMN8OZZO88O8D88DNMMMMMMMMMMNZ7II?+==========~======~=~===++??7ZOO888O$7$$$$I?IIII$O8DNMMMMMMMMNDD8ODD88888DO
DDNNDDNDDNNNNNNDNDOOOOOOO88MMMMMMMMMMMN8$III+===~=========~~=~~~==~==++?I$$ZZZZOOOZ7I?7$O888DNNNNNNMMMMMMMMNNDD88DNNDO$I
NNNNDDDNNNDNNNNNN88DDD8OZ$MMMMMMMMMMMMND7?++=======+===~~~~~~~~=~~~~~=+??7$$ZOO$7$ZO8DDNNNMMMMMMMMMMMMMMMMMMMD88DDD8888D
DNNNNNNNDDDDDNDDDDD888OZ$8MMMMMMMMMMMNDD87?++=~~=++++=~~~~~~~:~~~~~~===+?7ZZ$ZZODNNMNNDDNNNNMMMMMMMMMMMMMMMMMNMD8888DND8
DNNNNNNNNND88D8888OZ$ZZZ8NMMMMMMMMMMNNDDDO$I?+===+?++==~~~~~~~~~~~~====?7$ZOO8DDNNNNDDMMMMMMMMMMMMMMMMMMMMMNNNMN888888D8
NNDDND888OOO888OOOOO88DMMMMMMMMMMMMMNDD8DOOOD87I?I?+=~~~~~~=~~~~~===+I$ZOO8DNNMNNNNMMMMMMMMNMMMMMMMMMMMMMMMNMNMNDOOZOZO8
NDND888O8888DO888DDDDMMMMMMMMMMMMMMNND88D8DD8888DDD8O7III?++=+==++I$$Z88ODMMNNNMMMMNNMNDNNNNMMMMMMMMMNMMMMMMMNNMMOOOZZ88
NDDD8D8O8DDDD88888D8MMMMMMMMMMMMMMNDDDDDNNNDD8D8888OOOOOOOOO8OO8OZO8OODMD8NMMMMMMMMNNN8NNNNNMMMMMMMMMMMMMMMMMMMNMDDNDNDD
NNDDDDDD8888OOZOOZZZMMMMMMMMMMMMMNDNDN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MMMMMNMMMMMMMMMMMMNMMNMMMMNN
NMMNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNMMMMMMMMMMMMMMMNNMNN
NMMMNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNMMMMMMMMMMMMMMMMMMMNN
NMMMMMMMMMMMMMMNNMMMNDDDNMMMMMMMMNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNMMNMNNMNM
MMMMMMMMMMMMMNNND88NMMMMNDDMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNNMMMMNN
NMMMMMMMMMMNNNNNDDMMDDDNNNNNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNMMMMMMMMMNMMNNNMNNNNNNNNN
//.........這裏部分代碼省略.........
示例12: CancelTask
func CancelTask(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
taskName := args[2]
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
util.FreakOut(err)
output := strings.Join(rawOutput, "")
apps := models.V3AppsModel{}
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
appGuid := apps.Apps[0].Guid
rawTasksJson, err := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/tasks", appGuid))
util.FreakOut(err)
tasksJson := strings.Join(rawTasksJson, "")
tasks := models.V3TasksModel{}
err = json.Unmarshal([]byte(tasksJson), &tasks)
util.FreakOut(err)
var runningTasks []runningTask
for _, task := range tasks.Tasks {
if taskName == task.Name && task.State == "RUNNING" {
runningTasks = append(runningTasks, runningTask{task.Guid, task.Command, task.State, task.UpdatedAt})
}
}
if len(runningTasks) == 0 {
fmt.Println("No running task found. Task name:", taskName)
return
} else if len(runningTasks) == 1 {
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/tasks/%s/cancel", runningTasks[0].guid), "-X", "PUT", "-d", "{}")
util.FreakOut(err)
output := strings.Join(rawOutput, "")
fmt.Println(output)
return
} else {
fmt.Printf("Please select which task to cancel: \n\n")
tasksTable := util.NewTable([]string{"#", "Task Name", "Command", "State", "Time"})
for i, task := range runningTasks {
tasksTable.Add(
strconv.Itoa(i+1),
taskName,
task.command,
task.state,
fmt.Sprintf("%s", task.time.Format("Jan 2, 15:04:05 MST")),
)
}
tasksTable.Print()
var i int64 = -1
var str string
for i <= 0 || i > int64(len(runningTasks)) {
fmt.Printf("\nSelect from above > ")
fmt.Scanf("%s", &str)
i, _ = strconv.ParseInt(str, 10, 32)
}
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/tasks/%s/cancel", runningTasks[i-1].guid), "-X", "PUT", "-d", "{}")
util.FreakOut(err)
output := strings.Join(rawOutput, "")
fmt.Println(output)
}
}
示例13: Run
func (c *Test1) Run(cliConnection plugin.CliConnection, args []string) {
if args[0] == "new-api" {
token, _ := cliConnection.AccessToken()
fmt.Println("Access Token:", token)
fmt.Println("")
app, err := cliConnection.GetApp("test_app")
fmt.Println("err for test_app", err)
fmt.Println("test_app is: ", app)
hasOrg, _ := cliConnection.HasOrganization()
fmt.Println("Has Organization Targeted:", hasOrg)
currentOrg, _ := cliConnection.GetCurrentOrg()
fmt.Println("Current Org:", currentOrg)
org, _ := cliConnection.GetOrg(currentOrg.Name)
fmt.Println(currentOrg.Name, " Org:", org)
orgs, _ := cliConnection.GetOrgs()
fmt.Println("Orgs:", orgs)
hasSpace, _ := cliConnection.HasSpace()
fmt.Println("Has Space Targeted:", hasSpace)
currentSpace, _ := cliConnection.GetCurrentSpace()
fmt.Println("Current space:", currentSpace)
space, _ := cliConnection.GetSpace(currentSpace.Name)
fmt.Println("Space:", space)
spaces, _ := cliConnection.GetSpaces()
fmt.Println("Spaces:", spaces)
loggregator, _ := cliConnection.LoggregatorEndpoint()
fmt.Println("Loggregator Endpoint:", loggregator)
dopplerEndpoint, _ := cliConnection.DopplerEndpoint()
fmt.Println("Doppler Endpoint:", dopplerEndpoint)
user, _ := cliConnection.Username()
fmt.Println("Current user:", user)
userGUID, _ := cliConnection.UserGuid()
fmt.Println("Current user guid:", userGUID)
email, _ := cliConnection.UserEmail()
fmt.Println("Current user email:", email)
hasAPI, _ := cliConnection.HasAPIEndpoint()
fmt.Println("Has API Endpoint:", hasAPI)
api, _ := cliConnection.ApiEndpoint()
fmt.Println("Current api:", api)
version, _ := cliConnection.ApiVersion()
fmt.Println("Current api version:", version)
loggedIn, _ := cliConnection.IsLoggedIn()
fmt.Println("Is Logged In:", loggedIn)
isSSLDisabled, _ := cliConnection.IsSSLDisabled()
fmt.Println("Is SSL Disabled:", isSSLDisabled)
} else if args[0] == "test_1_cmd1" {
theFirstCmd()
} else if args[0] == "test_1_cmd2" {
theSecondCmd()
} else if args[0] == "CLI-MESSAGE-UNINSTALL" {
uninstalling()
}
}
示例14: uninstall
func uninstall(cliConnection plugin.CliConnection) {
fmt.Println("This plugin is being uninstalled, here are a list of apps you have running.")
cliConnection.CliCommand("apps")
}
示例15: Logs
func Logs(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
app := apps.Apps[0]
messageQueue := logs.NewNoaaMessageQueue()
bufferTime := 25 * time.Millisecond
ticker := time.NewTicker(bufferTime)
logChan := make(chan logs.Loggable)
errChan := make(chan error)
dopplerEndpoint, err := cliConnection.DopplerEndpoint()
FreakOut(err)
ssl, err := cliConnection.IsSSLDisabled()
FreakOut(err)
tlsConfig := net.NewTLSConfig([]tls.Certificate{}, ssl)
noaaConsumer := consumer.New(dopplerEndpoint, tlsConfig, http.ProxyFromEnvironment)
defer func() {
noaaConsumer.Close()
flushMessages(logChan, messageQueue)
}()
onConnect := func() {
fmt.Printf("Tailing logs for app %s...\r\n\r\n", appName)
}
noaaConsumer.SetOnConnectCallback(onConnect)
accessToken, err := cliConnection.AccessToken()
FreakOut(err)
c, e := noaaConsumer.TailingLogs(app.Guid, accessToken)
go func() {
for {
select {
case msg, ok := <-c:
if !ok {
ticker.Stop()
flushMessages(logChan, messageQueue)
close(logChan)
close(errChan)
return
}
messageQueue.PushMessage(msg)
case err := <-e:
if err != nil {
errChan <- err
ticker.Stop()
close(logChan)
close(errChan)
return
}
}
}
}()
go func() {
for range ticker.C {
flushMessages(logChan, messageQueue)
}
}()
for {
select {
case msg := <-logChan:
fmt.Printf("%s\r\n", logMessageOutput(msg, time.Local))
case err, ok := <-errChan:
if !ok {
FreakOut(err)
}
}
}
}