本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/flags.FlagContext.IsSet方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagContext.IsSet方法的具體用法?Golang FlagContext.IsSet怎麽用?Golang FlagContext.IsSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.IsSet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Requirements
func (cmd *SSH) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires APP_NAME as argument") + "\n\n" + commandregistry.Commands.CommandUsage("ssh"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1)
}
if fc.IsSet("i") && fc.Int("i") < 0 {
cmd.ui.Failed(fmt.Sprintf(T("Incorrect Usage:")+" %s\n\n%s", T("Value for flag 'app-instance-index' cannot be negative"), commandregistry.Commands.CommandUsage("ssh")))
return nil, fmt.Errorf("Incorrect usage: app-instance-index cannot be negative")
}
var err error
cmd.opts, err = options.NewSSHOptions(fc)
if err != nil {
cmd.ui.Failed(fmt.Sprintf(T("Incorrect Usage:")+" %s\n\n%s", err.Error(), commandregistry.Commands.CommandUsage("ssh")))
return nil, err
}
cmd.appReq = requirementsFactory.NewApplicationRequirement(cmd.opts.AppName)
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
cmd.appReq,
}
return reqs, nil
}
示例2: Execute
func (cmd *UpdateUserProvidedService) Execute(c flags.FlagContext) error {
serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
if !serviceInstance.IsUserProvided() {
return errors.New(T("Service Instance is not user provided"))
}
drainURL := c.String("l")
credentials := strings.Trim(c.String("p"), `'"`)
routeServiceURL := c.String("r")
credentialsMap := make(map[string]interface{})
if c.IsSet("p") {
jsonBytes, err := util.GetContentsFromFlagValue(credentials)
if err != nil {
return err
}
err = json.Unmarshal(jsonBytes, &credentialsMap)
if err != nil {
for _, param := range strings.Split(credentials, ",") {
param = strings.Trim(param, " ")
credentialsMap[param] = cmd.ui.Ask(param)
}
}
}
cmd.ui.Say(T("Updating user provided service {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
map[string]interface{}{
"ServiceName": terminal.EntityNameColor(serviceInstance.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
serviceInstance.Params = credentialsMap
serviceInstance.SysLogDrainURL = drainURL
serviceInstance.RouteServiceURL = routeServiceURL
err := cmd.userProvidedServiceInstanceRepo.Update(serviceInstance.ServiceInstanceFields)
if err != nil {
return err
}
cmd.ui.Ok()
cmd.ui.Say(T("TIP: Use '{{.CFRestageCommand}}' for any bound apps to ensure your env variable changes take effect",
map[string]interface{}{
"CFRestageCommand": terminal.CommandColor(cf.Name + " restage"),
}))
if routeServiceURL == "" && credentials == "" && drainURL == "" {
cmd.ui.Warn(T("No flags specified. No changes were made."))
}
return nil
}
示例3: Execute
func (cmd *Curl) Execute(c flags.FlagContext) error {
path := c.Args()[0]
headers := c.StringSlice("H")
var method string
var body string
if c.IsSet("d") {
method = "POST"
jsonBytes, err := util.GetContentsFromOptionalFlagValue(c.String("d"))
if err != nil {
return err
}
body = string(jsonBytes)
}
if c.IsSet("X") {
method = c.String("X")
}
reqHeader := strings.Join(headers, "\n")
responseHeader, responseBody, apiErr := cmd.curlRepo.Request(method, path, reqHeader, body)
if apiErr != nil {
return errors.New(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()}))
}
if trace.LoggingToStdout && !cmd.pluginCall {
return nil
}
if c.Bool("i") {
cmd.ui.Say(responseHeader)
}
if c.String("output") != "" {
err := cmd.writeToFile(responseBody, c.String("output"))
if err != nil {
return errors.New(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": err}))
}
} else {
if strings.Contains(responseHeader, "application/json") {
buffer := bytes.Buffer{}
err := json.Indent(&buffer, []byte(responseBody), "", " ")
if err == nil {
responseBody = buffer.String()
}
}
cmd.ui.Say(responseBody)
}
return nil
}
示例4: Requirements
func (cmd *UnmapRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 2 {
cmd.ui.Failed(T("Incorrect Usage. Requires app_name, domain_name as arguments\n\n") + commandregistry.Commands.CommandUsage("unmap-route"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 2)
}
if fc.IsSet("port") && (fc.IsSet("hostname") || fc.IsSet("path")) {
cmd.ui.Failed(T("Cannot specify port together with hostname and/or path."))
return nil, fmt.Errorf("Cannot specify port together with hostname and/or path.")
}
domainName := fc.Args()[1]
cmd.appReq = requirementsFactory.NewApplicationRequirement(fc.Args()[0])
cmd.domainReq = requirementsFactory.NewDomainRequirement(domainName)
var reqs []requirements.Requirement
if fc.String("path") != "" {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--path'", cf.RoutePathMinimumAPIVersion))
}
if fc.IsSet("port") {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--port'", cf.TCPRoutingMinimumAPIVersion))
}
reqs = append(reqs, []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
cmd.appReq,
cmd.domainReq,
}...)
return reqs, nil
}
示例5: Execute
func (cmd *Files) Execute(c flags.FlagContext) error {
app := cmd.appReq.GetApplication()
var instance int
if c.IsSet("i") {
instance = c.Int("i")
if instance < 0 {
return errors.New(T("Invalid instance: {{.Instance}}\nInstance must be a positive integer",
map[string]interface{}{
"Instance": instance,
}))
}
if instance >= app.InstanceCount {
return errors.New(T("Invalid instance: {{.Instance}}\nInstance must be less than {{.InstanceCount}}",
map[string]interface{}{
"Instance": instance,
"InstanceCount": app.InstanceCount,
}))
}
}
cmd.ui.Say(T("Getting files for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"AppName": terminal.EntityNameColor(app.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
path := "/"
if len(c.Args()) > 1 {
path = c.Args()[1]
}
list, err := cmd.appFilesRepo.ListFiles(app.GUID, instance, path)
if err != nil {
return err
}
cmd.ui.Ok()
cmd.ui.Say("")
if list == "" {
cmd.ui.Say("Empty file or folder")
} else {
cmd.ui.Say("%s", list)
}
return nil
}
示例6: Execute
func (cmd *PurgeServiceOffering) Execute(c flags.FlagContext) error {
serviceName := c.Args()[0]
var offering models.ServiceOffering
if c.IsSet("p") {
var err error
offering, err = cmd.serviceRepo.FindServiceOfferingByLabelAndProvider(serviceName, c.String("p"))
if err != nil {
if _, ok := err.(*errors.ModelNotFoundError); ok {
cmd.ui.Warn(T("Service offering does not exist\nTIP: If you are trying to purge a v1 service offering, you must set the -p flag."))
return nil
}
return err
}
} else {
offerings, err := cmd.serviceRepo.FindServiceOfferingsByLabel(serviceName)
if err != nil {
if _, ok := err.(*errors.ModelNotFoundError); ok {
cmd.ui.Warn(T("Service offering does not exist\nTIP: If you are trying to purge a v1 service offering, you must set the -p flag."))
return nil
}
return err
}
offering = offerings[0]
}
confirmed := c.Bool("f")
if !confirmed {
cmd.ui.Warn(scaryWarningMessage())
confirmed = cmd.ui.Confirm(T("Really purge service offering {{.ServiceName}} from Cloud Foundry?",
map[string]interface{}{"ServiceName": serviceName},
))
}
if !confirmed {
return nil
}
cmd.ui.Say(T("Purging service {{.ServiceName}}...", map[string]interface{}{"ServiceName": serviceName}))
err := cmd.serviceRepo.PurgeServiceOffering(offering)
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例7: Requirements
func (cmd *PurgeServiceOffering) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("purge-service-offering"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
if fc.IsSet("p") {
reqs = append(reqs, requirementsFactory.NewMaxAPIVersionRequirement("Option '-p'", cf.ServiceAuthTokenMaximumAPIVersion))
}
return reqs, nil
}
示例8: Requirements
func (cmd *UpdateSpaceQuota) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("update-space-quota"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedOrgRequirement(),
}
if fc.IsSet("a") {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '-a'", cf.SpaceAppInstanceLimitMinimumAPIVersion))
}
return reqs, nil
}
示例9: Requirements
func (cmd *Target) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
usageReq := requirements.NewUsageRequirement(commandregistry.CLICommandUsagePresenter(cmd),
T("No argument required"),
func() bool {
return len(fc.Args()) != 0
},
)
reqs := []requirements.Requirement{
usageReq,
requirementsFactory.NewAPIEndpointRequirement(),
}
if fc.IsSet("o") || fc.IsSet("s") {
reqs = append(reqs, requirementsFactory.NewLoginRequirement())
}
return reqs, nil
}
示例10: Requirements
func (cmd *UpdateUserProvidedService) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("update-user-provided-service"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1)
}
cmd.serviceInstanceReq = requirementsFactory.NewServiceInstanceRequirement(fc.Args()[0])
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
cmd.serviceInstanceReq,
}
if fc.IsSet("r") {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '-r'", cf.MultipleAppPortsMinimumAPIVersion))
}
return reqs, nil
}
示例11: Requirements
func (cmd *CreateQuota) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("create-quota"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
if fc.IsSet("a") {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '-a'", cf.OrgAppInstanceLimitMinimumAPIVersion))
}
if fc.IsSet("reserved-route-ports") {
reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--reserved-route-ports'", cf.ReservedRoutePortsMinimumAPIVersion))
}
return reqs, nil
}
示例12: Requirements
func (cmd *CreateServiceBroker) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
if len(fc.Args()) != 4 {
cmd.ui.Failed(T("Incorrect Usage. Requires SERVICE_BROKER, USERNAME, PASSWORD, URL as arguments\n\n") + commandregistry.Commands.CommandUsage("create-service-broker"))
return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 4)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
if fc.IsSet("space-scoped") {
reqs = append(
reqs,
requirementsFactory.NewTargetedSpaceRequirement(),
requirementsFactory.NewMinAPIVersionRequirement("--space-scoped", cf.SpaceScopedMaximumAPIVersion),
)
}
return reqs, nil
}
示例13: NewSSHOptions
func NewSSHOptions(fc flags.FlagContext) (*SSHOptions, error) {
sshOptions := &SSHOptions{}
sshOptions.AppName = fc.Args()[0]
sshOptions.Index = uint(fc.Int("i"))
sshOptions.SkipHostValidation = fc.Bool("k")
sshOptions.SkipRemoteExecution = fc.Bool("N")
sshOptions.Command = fc.StringSlice("c")
if fc.IsSet("L") {
for _, arg := range fc.StringSlice("L") {
forwardSpec, err := sshOptions.parseLocalForwardingSpec(arg)
if err != nil {
return sshOptions, err
}
sshOptions.ForwardSpecs = append(sshOptions.ForwardSpecs, *forwardSpec)
}
}
if fc.IsSet("t") && fc.Bool("t") {
sshOptions.TerminalRequest = RequestTTYYes
}
if fc.IsSet("tt") && fc.Bool("tt") {
sshOptions.TerminalRequest = RequestTTYForce
}
if fc.Bool("T") {
sshOptions.TerminalRequest = RequestTTYNo
}
return sshOptions, nil
}
示例14: Execute
func (cmd *CreateSpaceQuota) Execute(context flags.FlagContext) error {
name := context.Args()[0]
org := cmd.config.OrganizationFields()
cmd.ui.Say(T("Creating space quota {{.QuotaName}} for org {{.OrgName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(name),
"OrgName": terminal.EntityNameColor(org.Name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota := models.SpaceQuota{
Name: name,
OrgGUID: org.GUID,
}
memoryLimit := context.String("m")
if memoryLimit != "" {
parsedMemory, errr := formatters.ToMegabytes(memoryLimit)
if errr != nil {
return errors.New(T("Invalid memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": memoryLimit, "Err": errr}))
}
quota.MemoryLimit = parsedMemory
}
instanceMemoryLimit := context.String("i")
var parsedMemory int64
var err error
if instanceMemoryLimit == "-1" || instanceMemoryLimit == "" {
parsedMemory = -1
} else {
parsedMemory, err = formatters.ToMegabytes(instanceMemoryLimit)
if err != nil {
return errors.New(T("Invalid instance memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": instanceMemoryLimit, "Err": err}))
}
}
quota.InstanceMemoryLimit = parsedMemory
if context.IsSet("r") {
quota.RoutesLimit = context.Int("r")
}
if context.IsSet("s") {
quota.ServicesLimit = context.Int("s")
}
if context.IsSet("allow-paid-service-plans") {
quota.NonBasicServicesAllowed = true
}
if context.IsSet("a") {
quota.AppInstanceLimit = context.Int("a")
} else {
quota.AppInstanceLimit = resources.UnlimitedAppInstances
}
if context.IsSet("reserved-route-ports") {
quota.ReservedRoutePortsLimit = json.Number(strconv.Itoa(context.Int("reserved-route-ports")))
}
err = cmd.quotaRepo.Create(quota)
httpErr, ok := err.(errors.HTTPError)
if ok && httpErr.ErrorCode() == errors.QuotaDefinitionNameTaken {
cmd.ui.Ok()
cmd.ui.Warn(T("Space Quota Definition {{.QuotaName}} already exists", map[string]interface{}{"QuotaName": quota.Name}))
return nil
}
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}
示例15: Execute
func (cmd *UpdateBuildpack) Execute(c flags.FlagContext) error {
buildpack := cmd.buildpackReq.GetBuildpack()
cmd.ui.Say(T("Updating buildpack {{.BuildpackName}}...", map[string]interface{}{"BuildpackName": terminal.EntityNameColor(buildpack.Name)}))
updateBuildpack := false
if c.IsSet("i") {
position := c.Int("i")
buildpack.Position = &position
updateBuildpack = true
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
return errors.New(T("Cannot specify both {{.Enabled}} and {{.Disabled}}.", map[string]interface{}{
"Enabled": "enabled",
"Disabled": "disabled",
}))
}
if enabled {
buildpack.Enabled = &enabled
updateBuildpack = true
}
if disabled {
disabled = false
buildpack.Enabled = &disabled
updateBuildpack = true
}
lock := c.Bool("lock")
unlock := c.Bool("unlock")
if lock && unlock {
return errors.New(T("Cannot specify both lock and unlock options."))
}
path := c.String("p")
if path != "" && (lock || unlock) {
return errors.New(T("Cannot specify buildpack bits and lock/unlock."))
}
if lock {
buildpack.Locked = &lock
updateBuildpack = true
}
if unlock {
unlock = false
buildpack.Locked = &unlock
updateBuildpack = true
}
var (
buildpackFile *os.File
buildpackFileName string
err error
)
if path != "" {
buildpackFile, buildpackFileName, err = cmd.buildpackBitsRepo.CreateBuildpackZipFile(path)
if err != nil {
cmd.ui.Warn(T("Failed to create a local temporary zip file for the buildpack"))
return err
}
}
if updateBuildpack {
newBuildpack, err := cmd.buildpackRepo.Update(buildpack)
if err != nil {
return errors.New(T("Error updating buildpack {{.Name}}\n{{.Error}}", map[string]interface{}{
"Name": terminal.EntityNameColor(buildpack.Name),
"Error": err.Error(),
}))
}
buildpack = newBuildpack
}
if path != "" {
err := cmd.buildpackBitsRepo.UploadBuildpack(buildpack, buildpackFile, buildpackFileName)
if err != nil {
return errors.New(T("Error uploading buildpack {{.Name}}\n{{.Error}}", map[string]interface{}{
"Name": terminal.EntityNameColor(buildpack.Name),
"Error": err.Error(),
}))
}
}
cmd.ui.Ok()
return nil
}