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() }
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), })) } } }
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() }
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 }
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"), }, } }
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 }
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")) } }
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() }
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() }
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() }
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() }
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 }
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 }
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() } }
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() }
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 = REQUEST_TTY_YES } if fc.IsSet("tt") && fc.Bool("tt") { sshOptions.TerminalRequest = REQUEST_TTY_FORCE } if fc.Bool("T") { sshOptions.TerminalRequest = REQUEST_TTY_NO } return sshOptions, nil }
func (cmd *DeleteOrphanedRoutes) Execute(c flags.FlagContext) { force := c.Bool("f") if !force { response := cmd.ui.Confirm(T("Really delete orphaned routes?{{.Prompt}}", map[string]interface{}{"Prompt": terminal.PromptColor(">")})) if !response { return } } cmd.ui.Say(T("Getting routes as {{.Username}} ...\n", map[string]interface{}{"Username": terminal.EntityNameColor(cmd.config.Username())})) apiErr := cmd.routeRepo.ListRoutes(func(route models.Route) bool { if len(route.Apps) == 0 { cmd.ui.Say(T("Deleting route {{.Route}}...", map[string]interface{}{"Route": terminal.EntityNameColor(route.Host + "." + route.Domain.Name)})) apiErr := cmd.routeRepo.Delete(route.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return false } } return true }) if apiErr != nil { cmd.ui.Failed(T("Failed fetching routes.\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()})) return } cmd.ui.Ok() }
func (cmd *Logs) Execute(c flags.FlagContext) { app := cmd.appReq.GetApplication() if c.Bool("recent") { cmd.recentLogsFor(app) } else { cmd.tailLogsFor(app) } }
func (cmd *ShowApp) Execute(c flags.FlagContext) { app := cmd.appReq.GetApplication() if c.Bool("guid") { cmd.ui.Say(app.Guid) } else { cmd.ShowApp(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name) } }
func (cmd *Scale) confirmRestart(context flags.FlagContext, appName string) bool { if context.Bool("f") { return true } else { result := cmd.ui.Confirm(T("This will cause the app to restart. Are you sure you want to scale {{.AppName}}?", map[string]interface{}{"AppName": terminal.EntityNameColor(appName)})) cmd.ui.Say("") return result } }
func (cmd *DeleteServiceKey) Execute(c flags.FlagContext) { serviceInstanceName := c.Args()[0] serviceKeyName := c.Args()[1] if !c.Bool("f") { if !cmd.ui.ConfirmDelete(T("service key"), serviceKeyName) { return } } cmd.ui.Say(T("Deleting key {{.ServiceKeyName}} for service instance {{.ServiceInstanceName}} as {{.CurrentUser}}...", map[string]interface{}{ "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), "ServiceInstanceName": terminal.EntityNameColor(serviceInstanceName), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) serviceInstance, err := cmd.serviceRepo.FindInstanceByName(serviceInstanceName) if err != nil { cmd.ui.Ok() cmd.ui.Warn(T("Service instance {{.ServiceInstanceName}} does not exist.", map[string]interface{}{ "ServiceInstanceName": serviceInstanceName, })) return } serviceKey, err := cmd.serviceKeyRepo.GetServiceKey(serviceInstance.Guid, serviceKeyName) if err != nil || serviceKey.Fields.Guid == "" { switch err.(type) { case *errors.NotAuthorizedError: cmd.ui.Say(T("No service key {{.ServiceKeyName}} found for service instance {{.ServiceInstanceName}}", map[string]interface{}{ "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), "ServiceInstanceName": terminal.EntityNameColor(serviceInstanceName)})) return default: cmd.ui.Ok() cmd.ui.Warn(T("Service key {{.ServiceKeyName}} does not exist for service instance {{.ServiceInstanceName}}.", map[string]interface{}{ "ServiceKeyName": serviceKeyName, "ServiceInstanceName": serviceInstanceName, })) return } } err = cmd.serviceKeyRepo.DeleteServiceKey(serviceKey.Fields.Guid) if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Ok() }
func (cmd *ShowOrg) Execute(c flags.FlagContext) { org := cmd.orgReq.GetOrganization() if c.Bool("guid") { cmd.ui.Say(org.Guid) } else { cmd.ui.Say(T("Getting info for org {{.OrgName}} as {{.Username}}...", map[string]interface{}{ "OrgName": terminal.EntityNameColor(org.Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) cmd.ui.Ok() cmd.ui.Say("") table := terminal.NewTable(cmd.ui, []string{terminal.EntityNameColor(org.Name) + ":", "", ""}) domains := []string{} for _, domain := range org.Domains { domains = append(domains, domain.Name) } spaces := []string{} for _, space := range org.Spaces { spaces = append(spaces, space.Name) } spaceQuotas := []string{} for _, spaceQuota := range org.SpaceQuotas { spaceQuotas = append(spaceQuotas, spaceQuota.Name) } quota := org.QuotaDefinition orgQuota := fmt.Sprintf(T("{{.QuotaName}} ({{.MemoryLimit}}M memory limit, {{.InstanceMemoryLimit}} instance memory limit, {{.RoutesLimit}} routes, {{.ServicesLimit}} services, paid services {{.NonBasicServicesAllowed}})", map[string]interface{}{ "QuotaName": quota.Name, "MemoryLimit": quota.MemoryLimit, "InstanceMemoryLimit": formatters.InstanceMemoryLimit(quota.InstanceMemoryLimit), "RoutesLimit": quota.RoutesLimit, "ServicesLimit": quota.ServicesLimit, "NonBasicServicesAllowed": formatters.Allowed(quota.NonBasicServicesAllowed)})) if cmd.pluginCall { cmd.populatePluginModel(org, quota) } else { table.Add("", T("domains:"), terminal.EntityNameColor(strings.Join(domains, ", "))) table.Add("", T("quota:"), terminal.EntityNameColor(orgQuota)) table.Add("", T("spaces:"), terminal.EntityNameColor(strings.Join(spaces, ", "))) table.Add("", T("space quotas:"), terminal.EntityNameColor(strings.Join(spaceQuotas, ", "))) table.Print() } } }
func (cmd *Plugins) Execute(c flags.FlagContext) { var version string cmd.ui.Say(T("Listing Installed Plugins...")) plugins := cmd.config.Plugins() var table terminal.Table if c.Bool("checksum") { cmd.ui.Say(T("Computing sha1 for installed plugins, this may take a while ...")) table = terminal.NewTable(cmd.ui, []string{T("Plugin Name"), T("Version"), T("Command Name"), "sha1", T("Command Help")}) } else { table = terminal.NewTable(cmd.ui, []string{T("Plugin Name"), T("Version"), T("Command Name"), T("Command Help")}) } for pluginName, metadata := range plugins { if metadata.Version.Major == 0 && metadata.Version.Minor == 0 && metadata.Version.Build == 0 { version = "N/A" } else { version = fmt.Sprintf("%d.%d.%d", metadata.Version.Major, metadata.Version.Minor, metadata.Version.Build) } for _, command := range metadata.Commands { args := []string{pluginName, version} if command.Alias != "" { args = append(args, command.Name+", "+command.Alias) } else { args = append(args, command.Name) } if c.Bool("checksum") { checksum := utils.NewSha1Checksum(metadata.Location) sha1, err := checksum.ComputeFileSha1() if err != nil { args = append(args, "n/a") } else { args = append(args, fmt.Sprintf("%x", sha1)) } } args = append(args, command.HelpText) table.Add(args...) } } cmd.ui.Ok() cmd.ui.Say("") table.Print() }
func (cmd *ServiceKey) Execute(c flags.FlagContext) { serviceInstance := cmd.serviceInstanceRequirement.GetServiceInstance() serviceKeyName := c.Args()[1] if !c.Bool("guid") { cmd.ui.Say(T("Getting key {{.ServiceKeyName}} for service instance {{.ServiceInstanceName}} as {{.CurrentUser}}...", map[string]interface{}{ "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) } serviceKey, err := cmd.serviceKeyRepo.GetServiceKey(serviceInstance.Guid, serviceKeyName) if err != nil { switch err.(type) { case *errors.NotAuthorizedError: cmd.ui.Say(T("No service key {{.ServiceKeyName}} found for service instance {{.ServiceInstanceName}}", map[string]interface{}{ "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name)})) return default: cmd.ui.Failed(err.Error()) return } } if c.Bool("guid") { cmd.ui.Say(serviceKey.Fields.Guid) } else { if serviceKey.Fields.Name == "" { cmd.ui.Say(T("No service key {{.ServiceKeyName}} found for service instance {{.ServiceInstanceName}}", map[string]interface{}{ "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name)})) return } jsonBytes, err := json.MarshalIndent(serviceKey.Credentials, "", " ") if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Say("") cmd.ui.Say(string(jsonBytes)) } }
func (cmd Login) decideEndpoint(c flags.FlagContext) (string, bool) { endpoint := c.String("a") skipSSL := c.Bool("skip-ssl-validation") if endpoint == "" { endpoint = cmd.config.ApiEndpoint() skipSSL = cmd.config.IsSSLDisabled() || skipSSL } if endpoint == "" { endpoint = cmd.ui.Ask(T("API endpoint")) } else { cmd.ui.Say(T("API endpoint: {{.Endpoint}}", map[string]interface{}{"Endpoint": terminal.EntityNameColor(endpoint)})) } return endpoint, skipSSL }
func (cmd *DeleteSharedDomain) Execute(c flags.FlagContext) { domainName := c.Args()[0] force := c.Bool("f") cmd.ui.Say(T("Deleting domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{ "DomainName": terminal.EntityNameColor(domainName), "Username": terminal.EntityNameColor(cmd.config.Username())})) domain, apiErr := cmd.domainRepo.FindByNameInOrg(domainName, cmd.orgReq.GetOrganizationFields().Guid) switch apiErr.(type) { case nil: if !domain.Shared { cmd.ui.Failed(T("domain {{.DomainName}} is an owned domain, not a shared domain.", map[string]interface{}{"DomainName": domainName})) return } case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(apiErr.Error()) return default: cmd.ui.Failed(T("Error finding domain {{.DomainName}}\n{{.ApiErr}}", map[string]interface{}{ "DomainName": domainName, "ApiErr": apiErr.Error()})) return } if !force { answer := cmd.ui.Confirm(T("This domain is shared across all orgs.\nDeleting it will remove all associated routes, and will make any app with this domain unreachable.\nAre you sure you want to delete the domain {{.DomainName}}? ", map[string]interface{}{"DomainName": domainName})) if !answer { return } } apiErr = cmd.domainRepo.DeleteSharedDomain(domain.Guid) if apiErr != nil { cmd.ui.Failed(T("Error deleting domain {{.DomainName}}\n{{.ApiErr}}", map[string]interface{}{"DomainName": domainName, "ApiErr": apiErr.Error()})) return } cmd.ui.Ok() }
func (cmd *DeleteApp) Execute(c flags.FlagContext) { appName := c.Args()[0] if !c.Bool("f") { response := cmd.ui.ConfirmDelete(T("app"), appName) if !response { return } } cmd.ui.Say(T("Deleting app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(appName), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) app, apiErr := cmd.appRepo.Read(appName) switch apiErr.(type) { case nil: // no error case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(T("App {{.AppName}} does not exist.", map[string]interface{}{"AppName": appName})) return default: cmd.ui.Failed(apiErr.Error()) } if c.Bool("r") { for _, route := range app.Routes { apiErr = cmd.routeRepo.Delete(route.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) } } } apiErr = cmd.appRepo.Delete(app.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) } cmd.ui.Ok() }
func (cmd *Push) restart(app models.Application, params models.AppParams, c flags.FlagContext) { if app.State != T("stopped") { cmd.ui.Say("") app, _ = cmd.appStopper.ApplicationStop(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name) } cmd.ui.Say("") if c.Bool("no-start") { return } if params.HealthCheckTimeout != nil { cmd.appStarter.SetStartTimeoutInSeconds(*params.HealthCheckTimeout) } cmd.appStarter.ApplicationStart(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name) }
func (cmd *Curl) Execute(c flags.FlagContext) { path := c.Args()[0] method := c.String("X") headers := c.StringSlice("H") body := c.String("d") verbose := c.Bool("v") reqHeader := strings.Join(headers, "\n") if verbose { trace.EnableTrace() } responseHeader, responseBody, apiErr := cmd.curlRepo.Request(method, path, reqHeader, body) if apiErr != nil { cmd.ui.Failed(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()})) } if verbose { return } if c.Bool("i") { cmd.ui.Say(responseHeader) } if c.String("output") != "" { err := cmd.writeToFile(responseBody, c.String("output")) if err != nil { cmd.ui.Failed(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 }
func (cmd *DeleteDomain) Execute(c flags.FlagContext) { domainName := c.Args()[0] domain, apiErr := cmd.domainRepo.FindByNameInOrg(domainName, cmd.orgReq.GetOrganizationFields().Guid) switch apiErr.(type) { case nil: if domain.Shared { cmd.ui.Failed(T("domain {{.DomainName}} is a shared domain, not an owned domain.", map[string]interface{}{ "DomainName": domainName})) return } case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(apiErr.Error()) return default: cmd.ui.Failed(T("Error finding domain {{.DomainName}}\n{{.ApiErr}}", map[string]interface{}{"DomainName": domainName, "ApiErr": apiErr.Error()})) return } if !c.Bool("f") { if !cmd.ui.ConfirmDelete(T("domain"), domainName) { return } } cmd.ui.Say(T("Deleting domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{ "DomainName": terminal.EntityNameColor(domainName), "Username": terminal.EntityNameColor(cmd.config.Username())})) apiErr = cmd.domainRepo.Delete(domain.Guid) if apiErr != nil { cmd.ui.Failed(T("Error deleting domain {{.DomainName}}\n{{.ApiErr}}", map[string]interface{}{"DomainName": domainName, "ApiErr": apiErr.Error()})) return } cmd.ui.Ok() }