本文整理汇总了Golang中github.com/simonleung8/flags.FlagContext.Bool方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagContext.Bool方法的具体用法?Golang FlagContext.Bool怎么用?Golang FlagContext.Bool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/simonleung8/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.Bool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Execute
func (cmd *PurgeServiceInstance) Execute(c flags.FlagContext) {
instanceName := c.Args()[0]
instance, err := cmd.serviceRepo.FindInstanceByName(instanceName)
if err != nil {
if _, ok := err.(*errors.ModelNotFoundError); ok {
cmd.ui.Warn(T("Service instance {{.InstanceName}} not found", map[string]interface{}{"InstanceName": instanceName}))
return
}
cmd.ui.Failed(err.Error())
}
force := c.Bool("f")
if !force {
cmd.ui.Warn(cmd.scaryWarningMessage())
confirmed := cmd.ui.Confirm(T("Really purge service instance {{.InstanceName}} from Cloud Foundry?",
map[string]interface{}{"InstanceName": instanceName},
))
if !confirmed {
return
}
}
cmd.ui.Say(T("Purging service {{.InstanceName}}...", map[string]interface{}{"InstanceName": instanceName}))
err = cmd.serviceRepo.PurgeServiceInstance(instance)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例2: Execute
func (cmd *ShowService) Execute(c flags.FlagContext) {
serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
if cmd.pluginCall {
cmd.populatePluginModel(serviceInstance)
return
}
if c.Bool("guid") {
cmd.ui.Say(serviceInstance.Guid)
} else {
cmd.ui.Say("")
cmd.ui.Say(T("Service instance: {{.ServiceName}}", map[string]interface{}{"ServiceName": terminal.EntityNameColor(serviceInstance.Name)}))
if serviceInstance.IsUserProvided() {
cmd.ui.Say(T("Service: {{.ServiceDescription}}",
map[string]interface{}{
"ServiceDescription": terminal.EntityNameColor(T("user-provided")),
}))
} else {
cmd.ui.Say(T("Service: {{.ServiceDescription}}",
map[string]interface{}{
"ServiceDescription": terminal.EntityNameColor(serviceInstance.ServiceOffering.Label),
}))
cmd.ui.Say(T("Plan: {{.ServicePlanName}}",
map[string]interface{}{
"ServicePlanName": terminal.EntityNameColor(serviceInstance.ServicePlan.Name),
}))
cmd.ui.Say(T("Description: {{.ServiceDescription}}", map[string]interface{}{"ServiceDescription": terminal.EntityNameColor(serviceInstance.ServiceOffering.Description)}))
cmd.ui.Say(T("Documentation url: {{.URL}}",
map[string]interface{}{
"URL": terminal.EntityNameColor(serviceInstance.ServiceOffering.DocumentationUrl),
}))
cmd.ui.Say(T("Dashboard: {{.URL}}",
map[string]interface{}{
"URL": terminal.EntityNameColor(serviceInstance.DashboardUrl),
}))
cmd.ui.Say("")
cmd.ui.Say(T("Last Operation"))
cmd.ui.Say(T("Status: {{.State}}",
map[string]interface{}{
"State": terminal.EntityNameColor(ServiceInstanceStateToStatus(serviceInstance.LastOperation.Type, serviceInstance.LastOperation.State, serviceInstance.IsUserProvided())),
}))
cmd.ui.Say(T("Message: {{.Message}}",
map[string]interface{}{
"Message": terminal.EntityNameColor(serviceInstance.LastOperation.Description),
}))
if "" != serviceInstance.LastOperation.CreatedAt {
cmd.ui.Say(T("Started: {{.Started}}",
map[string]interface{}{
"Started": terminal.EntityNameColor(serviceInstance.LastOperation.CreatedAt),
}))
}
cmd.ui.Say(T("Updated: {{.Updated}}",
map[string]interface{}{
"Updated": terminal.EntityNameColor(serviceInstance.LastOperation.UpdatedAt),
}))
}
}
}
示例3: Execute
func (cmd *DeleteServiceAuthTokenFields) Execute(c flags.FlagContext) {
tokenLabel := c.Args()[0]
tokenProvider := c.Args()[1]
if c.Bool("f") == false {
if !cmd.ui.ConfirmDelete(T("service auth token"), fmt.Sprintf("%s %s", tokenLabel, tokenProvider)) {
return
}
}
cmd.ui.Say(T("Deleting service auth token as {{.CurrentUser}}",
map[string]interface{}{
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
token, apiErr := cmd.authTokenRepo.FindByLabelAndProvider(tokenLabel, tokenProvider)
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Service Auth Token {{.Label}} {{.Provider}} does not exist.", map[string]interface{}{"Label": tokenLabel, "Provider": tokenProvider}))
return
default:
cmd.ui.Failed(apiErr.Error())
}
apiErr = cmd.authTokenRepo.Delete(token)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
}
示例4: Execute
func (cmd *DeleteServiceBroker) Execute(c flags.FlagContext) {
brokerName := c.Args()[0]
if !c.Bool("f") && !cmd.ui.ConfirmDelete(T("service-broker"), brokerName) {
return
}
cmd.ui.Say(T("Deleting service broker {{.Name}} as {{.Username}}...",
map[string]interface{}{
"Name": terminal.EntityNameColor(brokerName),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
broker, apiErr := cmd.repo.FindByName(brokerName)
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Service Broker {{.Name}} does not exist.", map[string]interface{}{"Name": brokerName}))
return
default:
cmd.ui.Failed(apiErr.Error())
return
}
apiErr = cmd.repo.Delete(broker.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
return
}
示例5: printer
func (cmd *OrgUsers) printer(c flags.FlagContext) userprint.UserPrinter {
var roles []string
if c.Bool("a") {
roles = []string{models.ORG_USER}
} else {
roles = []string{models.ORG_MANAGER, models.BILLING_MANAGER, models.ORG_AUDITOR}
}
if cmd.pluginCall {
return userprint.NewOrgUsersPluginPrinter(
cmd.pluginModel,
cmd.userLister(),
roles,
)
}
return &userprint.OrgUsersUiPrinter{
Ui: cmd.ui,
UserLister: cmd.userLister(),
Roles: roles,
RoleDisplayNames: map[string]string{
models.ORG_USER: T("USERS"),
models.ORG_MANAGER: T("ORG MANAGER"),
models.BILLING_MANAGER: T("BILLING MANAGER"),
models.ORG_AUDITOR: T("ORG AUDITOR"),
},
}
}
示例6: createBuildpack
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c flags.FlagContext) (buildpack models.Buildpack, apiErr error) {
position, err := strconv.Atoi(c.Args()[2])
if err != nil {
apiErr = fmt.Errorf(T("Error {{.ErrorDescription}} is being passed in as the argument for 'Position' but 'Position' requires an integer. For more syntax help, see `cf create-buildpack -h`.", map[string]interface{}{"ErrorDescription": c.Args()[2]}))
return
}
enabled := c.Bool("enable")
disabled := c.Bool("disable")
if enabled && disabled {
apiErr = errors.New(T("Cannot specify both {{.Enabled}} and {{.Disabled}}.", map[string]interface{}{
"Enabled": "enabled",
"Disabled": "disabled",
}))
return
}
var enableOption *bool
if enabled {
enableOption = &enabled
}
if disabled {
disabled = false
enableOption = &disabled
}
buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)
return
}
示例7: Execute
func (cmd *ListRoutes) Execute(c flags.FlagContext) {
flag := c.Bool("orglevel")
if flag {
cmd.ui.Say(T("Getting routes for org {{.OrgName}} as {{.Username}} ...\n",
map[string]interface{}{
"Username": terminal.EntityNameColor(cmd.config.Username()),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
}))
} else {
cmd.ui.Say(T("Getting routes for org {{.OrgName}} / space {{.SpaceName}} as {{.Username}} ...\n",
map[string]interface{}{
"Username": terminal.EntityNameColor(cmd.config.Username()),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
}))
}
table := cmd.ui.Table([]string{T("space"), T("host"), T("domain"), T("apps"), T("service")})
noRoutes := true
var apiErr error
if flag {
apiErr = cmd.routeRepo.ListAllRoutes(func(route models.Route) bool {
noRoutes = false
appNames := []string{}
for _, app := range route.Apps {
appNames = append(appNames, app.Name)
}
table.Add(route.Space.Name, route.Host, route.Domain.Name, strings.Join(appNames, ","), route.ServiceInstance.Name)
return true
})
} else {
apiErr = cmd.routeRepo.ListRoutes(func(route models.Route) bool {
noRoutes = false
appNames := []string{}
for _, app := range route.Apps {
appNames = append(appNames, app.Name)
}
table.Add(route.Space.Name, route.Host, route.Domain.Name, strings.Join(appNames, ","), route.ServiceInstance.Name)
return true
})
}
table.Print()
if apiErr != nil {
cmd.ui.Failed(T("Failed fetching routes.\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()}))
return
}
if noRoutes {
cmd.ui.Say(T("No routes found"))
}
}
示例8: Execute
func (cmd *PurgeServiceOffering) Execute(c flags.FlagContext) {
serviceName := c.Args()[0]
offering, apiErr := cmd.serviceRepo.FindServiceOfferingByLabelAndProvider(serviceName, c.String("p"))
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
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
default:
cmd.ui.Failed(apiErr.Error())
}
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
}
cmd.ui.Say(T("Purging service {{.ServiceName}}...", map[string]interface{}{"ServiceName": serviceName}))
err := cmd.serviceRepo.PurgeServiceOffering(offering)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例9: Execute
func (cmd *DeleteQuota) Execute(c flags.FlagContext) {
quotaName := c.Args()[0]
if !c.Bool("f") {
response := cmd.ui.ConfirmDelete("quota", quotaName)
if !response {
return
}
}
cmd.ui.Say(T("Deleting quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(quotaName),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota, apiErr := cmd.quotaRepo.FindByName(quotaName)
switch (apiErr).(type) {
case nil: // no error
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Quota {{.QuotaName}} does not exist", map[string]interface{}{"QuotaName": quotaName}))
return
default:
cmd.ui.Failed(apiErr.Error())
}
apiErr = cmd.quotaRepo.Delete(quota.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
}
cmd.ui.Ok()
}
示例10: Execute
func (cmd *DeleteSecurityGroup) Execute(context flags.FlagContext) {
name := context.Args()[0]
cmd.ui.Say(T("Deleting security group {{.security_group}} as {{.username}}",
map[string]interface{}{
"security_group": terminal.EntityNameColor(name),
"username": terminal.EntityNameColor(cmd.configRepo.Username()),
}))
if !context.Bool("f") {
response := cmd.ui.ConfirmDelete(T("security group"), name)
if !response {
return
}
}
group, err := cmd.securityGroupRepo.Read(name)
switch err.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("Security group {{.security_group}} does not exist", map[string]interface{}{"security_group": name}))
return
default:
cmd.ui.Failed(err.Error())
}
err = cmd.securityGroupRepo.Delete(group.Guid)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例11: Execute
func (cmd *PurgeServiceInstance) Execute(c flags.FlagContext) {
instanceName := c.Args()[0]
instance, apiErr := cmd.serviceRepo.FindInstanceByName(instanceName)
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Warn(T("Service instance {{.InstanceName}} not found",
map[string]interface{}{"InstanceName": instanceName},
))
return
default:
cmd.ui.Failed(apiErr.Error())
}
confirmed := c.Bool("f")
if !confirmed {
cmd.ui.Warn(cmd.scaryWarningMessage())
confirmed = cmd.ui.Confirm(T("Really purge service instance {{.InstanceName}} from Cloud Foundry?",
map[string]interface{}{"InstanceName": instanceName},
))
}
if !confirmed {
return
}
cmd.ui.Say(T("Purging service {{.InstanceName}}...", map[string]interface{}{"InstanceName": instanceName}))
err := cmd.serviceRepo.PurgeServiceInstance(instance)
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例12: getAppParamsFromManifest
func (cmd *Push) getAppParamsFromManifest(c flags.FlagContext) []models.AppParams {
if c.Bool("no-manifest") {
return []models.AppParams{}
}
var path string
if c.String("f") != "" {
path = c.String("f")
} else {
var err error
path, err = os.Getwd()
if err != nil {
cmd.ui.Failed(T("Could not determine the current working directory!"), err)
}
}
m, err := cmd.manifestRepo.ReadManifest(path)
if err != nil {
if m.Path == "" && c.String("f") == "" {
return []models.AppParams{}
} else {
cmd.ui.Failed(T("Error reading manifest file:\n{{.Err}}", map[string]interface{}{"Err": err.Error()}))
}
}
apps, err := m.Applications()
if err != nil {
cmd.ui.Failed("Error reading manifest file:\n%s", err)
}
cmd.ui.Say(T("Using manifest file {{.Path}}\n",
map[string]interface{}{"Path": terminal.EntityNameColor(m.Path)}))
return apps
}
示例13: Execute
func (cmd *DeleteSpace) Execute(c flags.FlagContext) {
spaceName := c.Args()[0]
if !c.Bool("f") {
if !cmd.ui.ConfirmDelete(T("space"), spaceName) {
return
}
}
cmd.ui.Say(T("Deleting space {{.TargetSpace}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
map[string]interface{}{
"TargetSpace": terminal.EntityNameColor(spaceName),
"TargetOrg": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
space := cmd.spaceReq.GetSpace()
apiErr := cmd.spaceRepo.Delete(space.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
if cmd.config.SpaceFields().Guid == space.Guid {
cmd.config.SetSpaceFields(models.SpaceFields{})
cmd.ui.Say(T("TIP: No space targeted, use '{{.CfTargetCommand}}' to target a space",
map[string]interface{}{"CfTargetCommand": cf.Name() + " target -s"}))
}
return
}
示例14: Execute
func (cmd *ListStack) Execute(c flags.FlagContext) {
stackName := c.Args()[0]
stack, apiErr := cmd.stacksRepo.FindByName(stackName)
if c.Bool("guid") {
cmd.ui.Say(stack.Guid)
} else {
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Say(T("Getting stack '{{.Stack}}' in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{"Stack": stackName,
"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
cmd.ui.Ok()
cmd.ui.Say("")
table := terminal.NewTable(cmd.ui, []string{T("name"), T("description")})
table.Add(stack.Name, stack.Description)
table.Print()
}
}
示例15: Execute
func (cmd *DeleteUser) Execute(c flags.FlagContext) {
username := c.Args()[0]
force := c.Bool("f")
if !force && !cmd.ui.ConfirmDelete(T("user"), username) {
return
}
cmd.ui.Say(T("Deleting user {{.TargetUser}} as {{.CurrentUser}}...",
map[string]interface{}{
"TargetUser": terminal.EntityNameColor(username),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
user, apiErr := cmd.userRepo.FindByUsername(username)
switch apiErr.(type) {
case nil:
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(T("User {{.TargetUser}} does not exist.", map[string]interface{}{"TargetUser": username}))
return
default:
cmd.ui.Failed(apiErr.Error())
return
}
apiErr = cmd.userRepo.Delete(user.Guid)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
}