當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CliConnection.CliCommandWithoutTerminalOutput方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/cli/plugin.CliConnection.CliCommandWithoutTerminalOutput方法的典型用法代碼示例。如果您正苦於以下問題:Golang CliConnection.CliCommandWithoutTerminalOutput方法的具體用法?Golang CliConnection.CliCommandWithoutTerminalOutput怎麽用?Golang CliConnection.CliCommandWithoutTerminalOutput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/cli/plugin.CliConnection的用法示例。


在下文中一共展示了CliConnection.CliCommandWithoutTerminalOutput方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Curl

func Curl(cli plugin.CliConnection, result interface{}, args ...string) error {
	output, err := cli.CliCommandWithoutTerminalOutput(append([]string{"curl"}, args...)...)
	if err != nil {
		return err
	}

	buf := []byte(strings.Join(output, "\n"))

	var errorResponse curlError
	err = json.Unmarshal(buf, &errorResponse)
	if err != nil {
		return err
	}

	if errorResponse.Code != 0 {
		return errors.New(errorResponse.Description)
	}

	if result != nil {
		err = json.Unmarshal(buf, result)
		if err != nil {
			return err
		}
	}

	return nil
}
開發者ID:sykesm,項目名稱:diego-ssh,代碼行數:27,代碼來源:curl.go

示例2: Run

func (c *AppLister) Run(cliConnection plugin.CliConnection, args []string) {
	orgs, err := cliConnection.GetOrgs()
	if err != nil {
		fmt.Println("Error getting orgs:", err)
		os.Exit(1)
	}

	for _, org := range orgs {
		_, err := cliConnection.CliCommandWithoutTerminalOutput("t", "-o", org.Name)
		if err != nil {
			fmt.Println("Error targeting org: ", org.Name)
			os.Exit(1)
		}

		apps, err := cliConnection.GetApps()
		if err != nil {
			fmt.Println("Error getting applications from org: ", org.Name)
			os.Exit(1)
		}

		for _, app := range apps {
			fmt.Println(app.Name)
		}
	}
}
開發者ID:simonleung8,項目名稱:cli-plugin-examples,代碼行數:25,代碼來源:main.go

示例3: getAppGuid

func getAppGuid(cliConnection plugin.CliConnection, appName string) string {
	repo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), func(err error) {
		if err != nil {
			fmt.Println("\nERROR:", err)
			os.Exit(1)
		}
	})
	spaceGuid := repo.SpaceFields().Guid

	cmd := []string{"curl", fmt.Sprintf("/v2/spaces/%v/apps?q=name:%v&inline-relations-depth=1", spaceGuid, appName)}
	output, err := cliConnection.CliCommandWithoutTerminalOutput(cmd...)
	if err != nil {
		for _, e := range output {
			fmt.Println(e)
		}
		os.Exit(1)
	}

	search := &Search{}
	if err := json.Unmarshal([]byte(strings.Join(output, "")), &search); err != nil {
		fmt.Println("\nERROR:", err)
		os.Exit(1)
	}

	return search.Resources[0].Metadata.Guid
}
開發者ID:swisscom,項目名稱:cf-statistics-plugin,代碼行數:26,代碼來源:plugin_hook.go

示例4: runServiceOpen

func (plugin OpenPlugin) runServiceOpen(cliConnection plugin.CliConnection, args []string) {
	output, err := cliConnection.CliCommandWithoutTerminalOutput("service", args[1], "--guid")
	if err != nil {
		fmt.Fprintln(os.Stdout, "error: service does not exist")
		os.Exit(1)
	}
	serviceInstanceGUID := strings.TrimSpace(output[0])

	output, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v2/service_instances/%s", serviceInstanceGUID))
	if err != nil {
		fmt.Fprintln(os.Stdout, "error: service does not exist")
		os.Exit(1)
	}
	jsonStr := ""
	for _, line := range output {
		jsonStr += line + "\n"
	}

	response := serviceInstanceResponse{}
	json.Unmarshal([]byte(jsonStr), &response)

	url := response.Entity.DashboardURL
	if url == "" {
		fmt.Println("No dashboard available")
	} else {
		open.Run(url)
	}
}
開發者ID:whitfiea,項目名稱:cf-plugin-open,代碼行數:28,代碼來源:open.go

示例5: startedApps

func startedApps(cliConnection plugin.CliConnection, url string) ([]StartedApp, error) {
	appsJson, err := cliConnection.CliCommandWithoutTerminalOutput("curl", url)
	if nil != err {
		return nil, err
	}
	data := strings.Join(appsJson, "\n")
	var appsData map[string]interface{}
	json.Unmarshal([]byte(data), &appsData)

	apps := []StartedApp{}
	for _, app := range appsData["resources"].([]interface{}) {
		entity := app.(map[string]interface{})["entity"].(map[string]interface{})
		state := entity["state"].(string)
		if state == "STARTED" {
			metadata := app.(map[string]interface{})["metadata"].(map[string]interface{})
			result := StartedApp{
				Name:     entity["name"].(string),
				Guid:     metadata["guid"].(string),
				SpaceUrl: entity["space_url"].(string),
				State:    state,
			}
			apps = append(apps, result)
		}
	}

	if nil != appsData["next_url"] {
		next, _ := startedApps(cliConnection, appsData["next_url"].(string))
		apps = append(apps, next...)
	}

	return apps, err
}
開發者ID:davidehringer,項目名稱:cf-ip-query-plugin,代碼行數:32,代碼來源:api.go

示例6: GetAllApps

func GetAllApps(cliConnection plugin.CliConnection) ([]AppModel, error) {
	response, err := cliConnection.CliCommandWithoutTerminalOutput("curl", "v2/apps")

	apps := AppsModel{}
	err = json.Unmarshal([]byte(response[0]), &apps)

	return apps.Resources, err
}
開發者ID:simonleung8,項目名稱:cli-plugin-examples,代碼行數:8,代碼來源:apps_repository.go

示例7: Curl

// Curl calls cf curl  and return the resulting json. This method will panic if
// the api is depricated
func Curl(cli plugin.CliConnection, path string) (map[string]interface{}, error) {
	output, err := cli.CliCommandWithoutTerminalOutput("curl", path)

	if nil != err {
		return nil, err
	}

	return parseOutput(output)
}
開發者ID:krujos,項目名稱:cfcurl,代碼行數:11,代碼來源:cfcurl.go

示例8: scaleUp

func (app *AppStatus) scaleUp(cliConnection plugin.CliConnection) {
	// If not already started, start it
	if app.state != "started" {
		cliConnection.CliCommandWithoutTerminalOutput("start", app.name)
		app.state = "started"
	}
	app.countRequested++
	cliConnection.CliCommandWithoutTerminalOutput("scale", "-i", strconv.Itoa(app.countRequested), app.name)
}
開發者ID:TomG713,項目名稱:scaleover-plugin,代碼行數:9,代碼來源:scaleover_plugin.go

示例9: setServiceCreds

func setServiceCreds(conn plugin.CliConnection, name string, creds map[string]interface{}) error {
	marshaled, err := json.Marshal(creds)
	if err != nil {
		return err
	}

	_, err = conn.CliCommandWithoutTerminalOutput("uups", name, "-p", string(marshaled[:]))
	return err
}
開發者ID:jmcarp,項目名稱:cf-mups,代碼行數:9,代碼來源:main.go

示例10: KillInstanceZero

func (plugin ConsolePlugin) KillInstanceZero(cliConnection plugin.CliConnection, appGuid string) {

	plugin.Log("Killing instance 0.\n", false)

	// Kill the first instance and wait for it to come back up
	appURL := fmt.Sprintf("/v2/apps/%v/instances/0", appGuid)
	cmd := []string{"curl", appURL, "-X", "DELETE"}

	cliConnection.CliCommandWithoutTerminalOutput(cmd...)
}
開發者ID:tianhonglouis,項目名稱:cf-console,代碼行數:10,代碼來源:console.go

示例11: scaleDown

func (app *AppStatus) scaleDown(cliConnection plugin.CliConnection) {
	app.countRequested--
	// If going to zero, stop the app
	if app.countRequested == 0 {
		cliConnection.CliCommandWithoutTerminalOutput("stop", app.name)
		app.state = "stopped"
	} else {
		cliConnection.CliCommandWithoutTerminalOutput("scale", "-i", strconv.Itoa(app.countRequested), app.name)
	}
}
開發者ID:TomG713,項目名稱:scaleover-plugin,代碼行數:10,代碼來源:scaleover_plugin.go

示例12: ChangeInstanceCount

func (plugin ConsolePlugin) ChangeInstanceCount(cliConnection plugin.CliConnection, appGuid string, instances int) {

	plugin.Log(fmt.Sprintf("Changing instance count to %v.\n", instances), false)

	appURL := fmt.Sprintf("/v2/apps/%v", appGuid)
	newCommand := fmt.Sprintf("{\"instances\":%v}", instances)
	cmd := []string{"curl", appURL, "-X", "PUT", "-d", newCommand}

	cliConnection.CliCommandWithoutTerminalOutput(cmd...)
}
開發者ID:tianhonglouis,項目名稱:cf-console,代碼行數:10,代碼來源:console.go

示例13: organizationName

func organizationName(cliConnection plugin.CliConnection, org_url string) (string, error) {
	output, error := cliConnection.CliCommandWithoutTerminalOutput("curl", org_url)
	if error != nil {
		return "", error
	}
	data := strings.Join(output, "\n")
	var org map[string]interface{}
	json.Unmarshal([]byte(data), &org)
	entity := org["entity"].(map[string]interface{})
	return entity["name"].(string), error
}
開發者ID:davidehringer,項目名稱:cf-ip-query-plugin,代碼行數:11,代碼來源:api.go

示例14: RetrieveAppNameEnv

func (c *CopyEnv) RetrieveAppNameEnv(cliConnection plugin.CliConnection, app_name string) ([]string, error) {
	output, err := cliConnection.CliCommandWithoutTerminalOutput("env", app_name)

	if err != nil {
		for _, val := range output {
			fmt.Println(val)
		}
	}

	return output, err
}
開發者ID:Samze,項目名稱:copyenv,代碼行數:11,代碼來源:copyenv.go

示例15: GetAppsInOneOrg

func GetAppsInOneOrg(cliConnection plugin.CliConnection, orgName string) ([]plugin_models.GetAppsModel, error) {
	_, err := cliConnection.CliCommandWithoutTerminalOutput("target", "-o", orgName)
	if err != nil {
		return []plugin_models.GetAppsModel{}, errors.New("Failed to target org '" + orgName + "'")
	}

	apps, err := cliConnection.GetApps()
	if err != nil {
		return []plugin_models.GetAppsModel{}, errors.New("Failed to get apps in organization '" + orgName + "'")
	}

	return apps, nil
}
開發者ID:simonleung8,項目名稱:cli-plugin-examples,代碼行數:13,代碼來源:list-apps.go


注:本文中的github.com/cloudfoundry/cli/plugin.CliConnection.CliCommandWithoutTerminalOutput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。