作者:knollear
项目:cl
func (ui terminalUI) ShowConfiguration(config configuration.Reader) {
if config.HasAPIEndpoint() {
ui.Say("API endpoint: %s (API version: %s)",
EntityNameColor(config.ApiEndpoint()),
EntityNameColor(config.ApiVersion()))
}
if !config.IsLoggedIn() {
ui.Say(NotLoggedInText())
return
} else {
ui.Say("User: %s", EntityNameColor(config.UserEmail()))
}
if !config.HasOrganization() && !config.HasSpace() {
command := fmt.Sprintf("%s target -o ORG -s SPACE", cf.Name())
ui.Say("No org or space targeted, use '%s'", CommandColor(command))
return
}
if config.HasOrganization() {
ui.Say("Org: %s", EntityNameColor(config.OrganizationFields().Name))
} else {
command := fmt.Sprintf("%s target -o Org", cf.Name())
ui.Say("Org: No org targeted, use '%s'", CommandColor(command))
}
if config.HasSpace() {
ui.Say("Space: %s", EntityNameColor(config.SpaceFields().Name))
} else {
command := fmt.Sprintf("%s target -s SPACE", cf.Name())
ui.Say("Space: No space targeted, use '%s'", CommandColor(command))
}
}
作者:knollear
项目:cl
func (req ApiEndpointRequirement) Execute() (success bool) {
if req.config.ApiEndpoint() == "" {
loginTip := terminal.CommandColor(fmt.Sprintf("%s login", cf.Name()))
apiTip := terminal.CommandColor(fmt.Sprintf("%s api", cf.Name()))
req.ui.Say("No API endpoint targeted. Use '%s' or '%s' to target an endpoint.", loginTip, apiTip)
return false
}
return true
}
作者:jalatera
项目:cl
func loadConfig(termUI terminal.UI, configRepo configuration.ConfigurationRepository) (config *configuration.Configuration) {
config, err := configRepo.Get()
if err != nil {
termUI.Failed(fmt.Sprintf(
"Error loading config. Please reset target (%s) and log in (%s).",
terminal.CommandColor(fmt.Sprintf("%s target", cf.Name())),
terminal.CommandColor(fmt.Sprintf("%s login", cf.Name())),
))
configRepo.Delete()
os.Exit(1)
return
}
return
}
作者:nota-j
项目:cl
func (cmd *DeleteSpace) Run(c *cli.Context) {
spaceName := c.Args()[0]
if !c.Bool("f") {
if !cmd.ui.ConfirmDelete("space", spaceName) {
return
}
}
cmd.ui.Say("Deleting space %s in org %s as %s...",
terminal.EntityNameColor(spaceName),
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
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().Name == spaceName {
cmd.config.SetSpaceFields(models.SpaceFields{})
cmd.ui.Say("TIP: No space targeted, use '%s target -s' to target a space", cf.Name())
}
return
}
作者:nsn
项目:cl
func (cmd Target) setSpace(spaceName string) (err error) {
if !cmd.config.IsLoggedIn() {
cmd.ui.Failed("You must be logged in to set a space. Use '%s login'.", cf.Name())
return
}
if !cmd.config.HasOrganization() {
cmd.ui.Failed("An org must be targeted before targeting a space")
return
}
space, apiResponse := cmd.spaceRepo.FindByName(spaceName)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed("Unable to access space %s.\n%s", spaceName, apiResponse.Message)
return
}
err = cmd.configRepo.SetSpace(space.SpaceFields)
if err != nil {
cmd.ui.Failed("Error setting space in config file.\n%s", err)
return
}
return
}
作者:knollear
项目:cl
func (cmd Api) setApiEndpoint(endpoint string, skipSSL bool) {
if strings.HasSuffix(endpoint, "/") {
endpoint = strings.TrimSuffix(endpoint, "/")
}
cmd.config.SetSSLDisabled(skipSSL)
endpoint, err := cmd.endpointRepo.UpdateEndpoint(endpoint)
if err != nil {
cmd.config.SetApiEndpoint("")
cmd.config.SetSSLDisabled(false)
switch typedErr := err.(type) {
case *errors.InvalidSSLCert:
cfApiCommand := terminal.CommandColor(fmt.Sprintf("%s api --skip-ssl-validation", cf.Name()))
tipMessage := fmt.Sprintf("TIP: Use '%s' to continue with an insecure API endpoint", cfApiCommand)
cmd.ui.Failed("Invalid SSL Cert for %s\n%s", typedErr.URL, tipMessage)
default:
cmd.ui.Failed(typedErr.Error())
}
}
if !strings.HasPrefix(endpoint, "https://") {
cmd.ui.Say(terminal.WarningColor("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n"))
}
}
作者:pmuell
项目:cl
func displayCrashDialog() {
formattedString := `
d8888 888 888 888 888 .d8888b. 888 888 888 888 .d8888b. 888 d8P .d8888b.
d88888 888 o 888 888 o 888 d88P Y88b 888 888 888 888 d88P Y88b 888 d8P d88P Y88b
d88P888 888 d8b 888 888 d8b 888 Y88b. 888 888 888 888 888 888 888 d8P Y88b.
d88P 888 888 d888b 888 888 d888b 888 "Y888b. 8888888888 888 888 888 888d88K "Y888b.
d88P 888 888d88888b888 888d88888b888 "Y88b. 888 888 888 888 888 8888888b "Y88b.
d88P 888 88888P Y88888 88888P Y88888 "888 888 888 888 888 888 888 888 Y88b "888
d8888888888 8888P Y8888 8888P Y8888 Y88b d88P 888 888 Y88b. .d88P Y88b d88P 888 Y88b Y88b d88P d8b
d88P 888 888P Y888 888P Y888 "Y8888P" 888 888 "Y88888P" "Y8888P" 888 Y88b "Y8888P" Y8P
Something completely unexpected happened. This is a bug in %s.
Please file this bug : https://github.com/cloudfoundry/cli/issues
Tell us that you ran this command:
%s
and got this stack trace:
%s
`
stackTrace := "\t" + strings.Replace(string(debug.Stack()), "\n", "\n\t", -1)
println(fmt.Sprintf(formattedString, cf.Name(), strings.Join(os.Args, " "), stackTrace))
os.Exit(1)
}
作者:juggernau
项目:cl
func (cmd *BindService) Run(c *cli.Context) {
app := cmd.appReq.GetApplication()
serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
cmd.ui.Say("Binding service %s to app %s in org %s / space %s as %s...",
terminal.EntityNameColor(serviceInstance.Name),
terminal.EntityNameColor(app.Name),
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
terminal.EntityNameColor(cmd.config.SpaceFields().Name),
terminal.EntityNameColor(cmd.config.Username()),
)
err := cmd.BindApplication(app, serviceInstance)
if err != nil {
if err, ok := err.(cferrors.HttpError); ok && err.ErrorCode() == AppAlreadyBoundErrorCode {
cmd.ui.Ok()
cmd.ui.Warn("App %s is already bound to %s.", app.Name, serviceInstance.Name)
return
} else {
cmd.ui.Failed(err.Error())
}
}
cmd.ui.Ok()
cmd.ui.Say("TIP: Use '%s push' to ensure your env variable changes take effect", cf.Name())
}
作者:normalnorma
项目:cl
func (cmd *BindService) Run(c *cli.Context) {
app := cmd.appReq.GetApplication()
serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
cmd.ui.Say("Binding service %s to app %s in org %s / space %s as %s...",
terminal.EntityNameColor(serviceInstance.Name),
terminal.EntityNameColor(app.Name),
terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
terminal.EntityNameColor(cmd.config.SpaceFields().Name),
terminal.EntityNameColor(cmd.config.Username()),
)
apiResponse := cmd.BindApplication(app, serviceInstance)
if apiResponse.IsNotSuccessful() && apiResponse.ErrorCode != AppAlreadyBoundErrorCode {
cmd.ui.Failed(apiResponse.Message)
}
cmd.ui.Ok()
if apiResponse.ErrorCode == AppAlreadyBoundErrorCode {
cmd.ui.Warn("App %s is already bound to %s.", app.Name, serviceInstance.Name)
return
}
cmd.ui.Say("TIP: Use '%s push' to ensure your env variable changes take effect", cf.Name())
}
作者:jalatera
项目:cl
func (cmd *UnsetEnv) Run(c *cli.Context) {
varName := c.Args()[1]
app := cmd.appReq.GetApplication()
cmd.ui.Say("Removing env variable %s from app %s in org %s / space %s as %s...",
terminal.EntityNameColor(varName),
terminal.EntityNameColor(app.Name),
terminal.EntityNameColor(cmd.config.Organization.Name),
terminal.EntityNameColor(cmd.config.Space.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
envVars := app.EnvironmentVars
if !envVarFound(varName, envVars) {
cmd.ui.Ok()
cmd.ui.Warn("Env variable %s was not set.", varName)
return
}
delete(envVars, varName)
apiResponse := cmd.appRepo.SetEnv(app, envVars)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
cmd.ui.Say("TIP: Use '%s push' to ensure your env variable changes take effect", cf.Name())
}
作者:knollear
项目:cl
func (cmd CreateSpace) Run(c *cli.Context) {
spaceName := c.Args()[0]
orgName := c.String("o")
orgGuid := ""
if orgName == "" {
orgName = cmd.config.OrganizationFields().Name
orgGuid = cmd.config.OrganizationFields().Guid
}
cmd.ui.Say("Creating space %s in org %s as %s...",
terminal.EntityNameColor(spaceName),
terminal.EntityNameColor(orgName),
terminal.EntityNameColor(cmd.config.Username()),
)
if orgGuid == "" {
org, apiErr := cmd.orgRepo.FindByName(orgName)
switch apiErr.(type) {
case nil:
case errors.ModelNotFoundError:
cmd.ui.Failed("Org %s does not exist or is not accessible", orgName)
return
default:
cmd.ui.Failed("Error finding org %s\n%s", orgName, apiErr.Error())
return
}
orgGuid = org.Guid
}
space, apiErr := cmd.spaceRepo.Create(spaceName, orgGuid)
if apiErr != nil {
if apiErr.ErrorCode() == cf.SPACE_EXISTS {
cmd.ui.Ok()
cmd.ui.Warn("Space %s already exists", spaceName)
return
}
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
var err error
err = cmd.spaceRoleSetter.SetSpaceRole(space, models.SPACE_MANAGER, cmd.config.UserGuid(), cmd.config.Username())
if err != nil {
cmd.ui.Failed(err.Error())
return
}
err = cmd.spaceRoleSetter.SetSpaceRole(space, models.SPACE_DEVELOPER, cmd.config.UserGuid(), cmd.config.Username())
if err != nil {
cmd.ui.Failed(err.Error())
return
}
cmd.ui.Say("\nTIP: Use '%s' to target new space", terminal.CommandColor(cf.Name()+" target -o "+orgName+" -s "+space.Name))
}
作者:jalatera
项目:cl
func (cmd *DeleteSpace) Run(c *cli.Context) {
spaceName := c.Args()[0]
force := c.Bool("f")
cmd.ui.Say("Deleting space %s in org %s as %s...",
terminal.EntityNameColor(spaceName),
terminal.EntityNameColor(cmd.config.Organization.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
space, apiResponse := cmd.spaceRepo.FindByName(spaceName)
if apiResponse.IsError() {
cmd.ui.Failed(apiResponse.Message)
return
}
if apiResponse.IsNotFound() {
cmd.ui.Ok()
cmd.ui.Warn("Space %s does not exist.", spaceName)
return
}
if !force {
response := cmd.ui.Confirm(
"Really delete space %s and everything associated with it?%s",
terminal.EntityNameColor(spaceName),
terminal.PromptColor(">"),
)
if !response {
return
}
}
apiResponse = cmd.spaceRepo.Delete(space)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
config, err := cmd.configRepo.Get()
if err != nil {
cmd.ui.ConfigFailure(err)
return
}
if config.Space.Name == spaceName {
config.Space = cf.Space{}
cmd.configRepo.Save()
cmd.ui.Say("TIP: No space targeted, use '%s target -s' to target a space", cf.Name())
}
return
}
作者:knollear
项目:cl
func (req targetedOrgApiRequirement) Execute() (success bool) {
if !req.config.HasOrganization() {
message := fmt.Sprintf("No org targeted, use '%s' to target an org.",
terminal.CommandColor(cf.Name()+" target -o ORG"))
req.ui.Failed(message)
return false
}
return true
}
作者:jalatera
项目:cl
func (cmd Target) Run(c *cli.Context) {
orgName := c.String("o")
spaceName := c.String("s")
shouldShowTarget := (orgName == "" && spaceName == "")
if shouldShowTarget {
cmd.ui.ShowConfiguration(cmd.config)
if !cmd.config.HasOrganization() {
cmd.ui.Say("No org targeted, use '%s target -o' to target an org", cf.Name())
}
if !cmd.config.HasSpace() {
cmd.ui.Say("No space targeted, use '%s target -s' to target a space", cf.Name())
}
return
}
if orgName != "" {
err := cmd.setOrganization(orgName)
if spaceName == "" && cmd.config.IsLoggedIn() {
cmd.showConfig()
cmd.ui.Say("No space targeted, use '%s target -s' to target a space", cf.Name())
return
}
if err != nil {
return
}
}
if spaceName != "" {
err := cmd.setSpace(spaceName)
if err != nil {
return
}
}
cmd.showConfig()
return
}
作者:nota-j
项目:cl
func getCommand(metadata command_metadata.CommandMetadata, runner command_runner.Runner) cli.Command {
return cli.Command{
Name: metadata.Name,
ShortName: metadata.ShortName,
Description: metadata.Description,
Usage: strings.Replace(metadata.Usage, "CF_NAME", cf.Name(), -1),
Action: func(context *cli.Context) {
runner.RunCmdByName(metadata.Name, context)
},
Flags: metadata.Flags,
}
}
作者:knollear
项目:cl
func (req TargetedSpaceRequirement) Execute() (success bool) {
if !req.config.HasOrganization() {
message := fmt.Sprintf("No org and space targeted, use '%s' to target an org and space",
terminal.CommandColor(cf.Name()+" target -o ORG -s SPACE"))
req.ui.Failed(message)
return false
}
if !req.config.HasSpace() {
message := fmt.Sprintf("No space targeted, use '%s' to target a space", terminal.CommandColor("cf target -s"))
req.ui.Failed(message)
return false
}
return true
}
作者:normalnorma
项目:cl
func (cmd Start) waitForInstancesToStage(app models.Application) {
stagingStartTime := time.Now()
_, apiResponse := cmd.appInstancesRepo.GetInstances(app.Guid)
for apiResponse.IsNotSuccessful() && time.Since(stagingStartTime) < cmd.StagingTimeout {
if apiResponse.ErrorCode != cf.APP_NOT_STAGED {
cmd.ui.Say("")
cmd.ui.Failed(fmt.Sprintf("%s\n\nTIP: use '%s' for more information",
apiResponse.Message,
terminal.CommandColor(fmt.Sprintf("%s logs %s --recent", cf.Name(), app.Name))))
return
}
cmd.ui.Wait(cmd.PingerThrottle)
_, apiResponse = cmd.appInstancesRepo.GetInstances(app.Guid)
}
return
}
作者:nota-j
项目:cl
func (cmd Start) waitForInstancesToStage(app models.Application) {
stagingStartTime := time.Now()
_, err := cmd.appInstancesRepo.GetInstances(app.Guid)
for err != nil && time.Since(stagingStartTime) < cmd.StagingTimeout {
if err, ok := err.(errors.HttpError); ok && err.ErrorCode() != errors.APP_NOT_STAGED {
cmd.ui.Say("")
cmd.ui.Failed(fmt.Sprintf("%s\n\nTIP: use '%s' for more information",
err.Error(),
terminal.CommandColor(fmt.Sprintf("%s logs %s --recent", cf.Name(), app.Name))))
return
}
cmd.ui.Wait(cmd.PingerThrottle)
_, err = cmd.appInstancesRepo.GetInstances(app.Guid)
}
return
}
作者:jalatera
项目:cl
func (ui terminalUI) ShowConfiguration(config *configuration.Configuration) {
ui.Say("API endpoint: %s (API version: %s)",
EntityNameColor(config.Target),
EntityNameColor(config.ApiVersion))
if !config.IsLoggedIn() {
ui.Say("Logged out, use '%s' to login", CommandColor(cf.Name()+" login USERNAME"))
} else {
ui.Say("User: %s", EntityNameColor(config.UserEmail()))
}
if config.HasOrganization() {
ui.Say("Org: %s", EntityNameColor(config.Organization.Name))
}
if config.HasSpace() {
ui.Say("Space: %s", EntityNameColor(config.Space.Name))
}
}
作者:knollear
项目:cl
func (cmd CreateUserFields) Run(c *cli.Context) {
username := c.Args()[0]
password := c.Args()[1]
cmd.ui.Say("Creating user %s as %s...",
terminal.EntityNameColor(username),
terminal.EntityNameColor(cmd.config.Username()),
)
apiErr := cmd.userRepo.Create(username, password)
if apiErr != nil {
cmd.ui.Failed("Error creating user %s.\n%s", terminal.EntityNameColor(username), apiErr.Error())
return
}
cmd.ui.Ok()
cmd.ui.Say("\nTIP: Assign roles with '%s set-org-role' and '%s set-space-role'", cf.Name(), cf.Name())
}