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


Golang terminal.PromptColor函數代碼示例

本文整理匯總了Golang中cf/terminal.PromptColor函數的典型用法代碼示例。如果您正苦於以下問題:Golang PromptColor函數的具體用法?Golang PromptColor怎麽用?Golang PromptColor使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: authenticate

func (cmd Login) authenticate(c *cli.Context) (apiResponse net.ApiResponse) {
	username := c.String("u")
	if username == "" {
		username = cmd.ui.Ask("Username%s", terminal.PromptColor(">"))
	}

	password := c.String("p")

	for i := 0; i < maxLoginTries; i++ {
		if password == "" || i > 0 {
			password = cmd.ui.AskForPassword("Password%s", terminal.PromptColor(">"))
		}

		cmd.ui.Say("Authenticating...")

		apiResponse = cmd.authenticator.Authenticate(username, password)
		if apiResponse.IsSuccessful() {
			cmd.ui.Ok()
			cmd.ui.Say("")
			break
		}

		cmd.ui.Say(apiResponse.Message)
	}
	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:26,代碼來源:login.go

示例2: Run

func (cmd Password) Run(c *cli.Context) {
	oldPassword := cmd.ui.AskForPassword("Current Password%s", term.PromptColor(">"))
	newPassword := cmd.ui.AskForPassword("New Password%s", term.PromptColor(">"))
	verifiedPassword := cmd.ui.AskForPassword("Verify Password%s", term.PromptColor(">"))

	if verifiedPassword != newPassword {
		cmd.ui.Failed("Password verification does not match")
		return
	}

	score, err := cmd.pwdRepo.GetScore(newPassword)
	if err != nil {
		cmd.ui.Failed(err.Error())
		return
	}
	cmd.ui.Say("Your password strength is: %s", score)

	cmd.ui.Say("Changing password...")
	err = cmd.pwdRepo.UpdatePassword(oldPassword, newPassword)

	if err != nil {
		if err.StatusCode == 401 {
			cmd.ui.Failed("Current password did not match")
		} else {
			cmd.ui.Failed(err.Error())
		}
		return
	}

	cmd.ui.Ok()

	cmd.configRepo.ClearSession()
	cmd.ui.Say("Please log back in.")
}
開發者ID:jbayer,項目名稱:cli,代碼行數:34,代碼來源:password.go

示例3: Run

func (cmd Password) Run(c *cli.Context) {
	oldPassword := cmd.ui.AskForPassword("Current Password%s", terminal.PromptColor(">"))
	newPassword := cmd.ui.AskForPassword("New Password%s", terminal.PromptColor(">"))
	verifiedPassword := cmd.ui.AskForPassword("Verify Password%s", terminal.PromptColor(">"))

	if verifiedPassword != newPassword {
		cmd.ui.Failed("Password verification does not match")
		return
	}

	score, apiResponse := cmd.pwdRepo.GetScore(newPassword)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}
	cmd.ui.Say("Your password strength is: %s", score)

	cmd.ui.Say("Changing password...")
	apiResponse = cmd.pwdRepo.UpdatePassword(oldPassword, newPassword)

	if apiResponse.IsNotSuccessful() {
		if apiResponse.StatusCode == 401 {
			cmd.ui.Failed("Current password did not match")
		} else {
			cmd.ui.Failed(apiResponse.Message)
		}
		return
	}

	cmd.ui.Ok()

	cmd.configRepo.ClearSession()
	cmd.ui.Say("Please log in again")
}
開發者ID:jalateras,項目名稱:cli,代碼行數:34,代碼來源:password.go

示例4: Run

func (cmd Password) Run(c *cli.Context) {
	oldPassword := cmd.ui.AskForPassword("Current Password%s", terminal.PromptColor(">"))
	newPassword := cmd.ui.AskForPassword("New Password%s", terminal.PromptColor(">"))
	verifiedPassword := cmd.ui.AskForPassword("Verify Password%s", terminal.PromptColor(">"))

	if verifiedPassword != newPassword {
		cmd.ui.Failed("Password verification does not match")
		return
	}

	cmd.ui.Say("Changing password...")
	apiErr := cmd.pwdRepo.UpdatePassword(oldPassword, newPassword)

	switch typedErr := apiErr.(type) {
	case nil:
	case errors.HttpError:
		if typedErr.StatusCode() == 401 {
			cmd.ui.Failed("Current password did not match")
		} else {
			cmd.ui.Failed(apiErr.Error())
		}
	default:
		cmd.ui.Failed(apiErr.Error())
	}

	cmd.ui.Ok()
	cmd.config.ClearSession()
	cmd.ui.Say("Please log in again")
}
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:29,代碼來源:password.go

示例5: mapValuesFromPrompt

func (cmd CreateUserProvidedService) mapValuesFromPrompt(params string, paramsMap map[string]string) map[string]string {
	for _, param := range strings.Split(params, ",") {
		param = strings.Trim(param, " ")
		paramsMap[param] = cmd.ui.Ask("%s%s", param, terminal.PromptColor(">"))
	}
	return paramsMap
}
開發者ID:knolleary,項目名稱:cli,代碼行數:7,代碼來源:create_user_provided_service.go

示例6: Run

func (cmd DeleteServiceAuthToken) Run(c *cli.Context) {
	tokenLabel := c.Args()[0]
	tokenProvider := c.Args()[1]

	if c.Bool("f") == false {
		response := cmd.ui.Confirm(
			"Are you sure you want to delete %s?%s",
			terminal.EntityNameColor(fmt.Sprintf("%s %s", tokenLabel, tokenProvider)),
			terminal.PromptColor(">"),
		)
		if response == false {
			return
		}
	}

	cmd.ui.Say("Deleting service auth token as %s", terminal.EntityNameColor(cmd.config.Username()))
	token, apiResponse := cmd.authTokenRepo.FindByLabelAndProvider(tokenLabel, tokenProvider)
	if apiResponse.IsError() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}
	if apiResponse.IsNotFound() {
		cmd.ui.Ok()
		cmd.ui.Warn("Service Auth Token %s %s does not exist.", tokenLabel, tokenProvider)
		return
	}

	apiResponse = cmd.authTokenRepo.Delete(token)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
}
開發者ID:jalateras,項目名稱:cli,代碼行數:35,代碼來源:delete_service_auth_token.go

示例7: Run

func (cmd *DeleteSpace) Run(c *cli.Context) {
	space := cmd.spaceReq.GetSpace()
	force := c.Bool("f")

	if !force {
		response := strings.ToLower(cmd.ui.Ask(
			"Really delete space %s and everything associated with it?%s",
			term.EntityNameColor(space.Name),
			term.PromptColor(">"),
		))
		if response != "y" && response != "yes" {
			return
		}
	}

	cmd.ui.Say("Deleting space %s...", term.EntityNameColor(space.Name))
	err := cmd.spaceRepo.Delete(space)
	if err != nil {
		cmd.ui.Failed(err.Error())
		return
	}

	cmd.ui.Ok()
	return
}
開發者ID:jbayer,項目名稱:cli,代碼行數:25,代碼來源:delete_space.go

示例8: Run

func (cmd DeleteUser) Run(c *cli.Context) {
	username := c.Args()[0]
	force := c.Bool("f")

	if !force && !cmd.ui.Confirm("Really delete user %s?%s",
		terminal.EntityNameColor(username),
		terminal.PromptColor(">"),
	) {
		return
	}

	cmd.ui.Say("Deleting user %s as %s...",
		terminal.EntityNameColor(username),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	user, apiResponse := cmd.userRepo.FindByUsername(username)
	if apiResponse.IsError() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}
	if apiResponse.IsNotFound() {
		cmd.ui.Ok()
		cmd.ui.Warn("User %s does not exist.", username)
		return
	}

	apiResponse = cmd.userRepo.Delete(user)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
}
開發者ID:jalateras,項目名稱:cli,代碼行數:35,代碼來源:delete_user.go

示例9: Run

func (d *Delete) Run(c *cli.Context) {
	app := d.appReq.GetApplication()
	force := c.Bool("f")

	if !force {
		response := strings.ToLower(d.ui.Ask(
			"Really delete %s?%s",
			term.EntityNameColor(app.Name),
			term.PromptColor(">"),
		))
		if response != "y" && response != "yes" {
			return
		}
	}

	d.ui.Say("Deleting app %s...", term.EntityNameColor(app.Name))
	err := d.appRepo.Delete(app)
	if err != nil {
		d.ui.Failed(err.Error())
		return
	}

	d.ui.Ok()
	return
}
開發者ID:jbayer,項目名稱:cli,代碼行數:25,代碼來源:delete.go

示例10: promptForName

func (cmd Login) promptForName(names []string, listPrompt, itemPrompt string) string {
	nameIndex := 0
	var nameString string
	for nameIndex < 1 || nameIndex > len(names) {
		var err error

		// list header
		cmd.ui.Say(listPrompt)

		// only display list if it is shorter than 50
		if len(names) < 50 {
			for i, name := range names {
				cmd.ui.Say("%d. %s", i+1, name)
			}
		}

		nameString = cmd.ui.Ask("%s%s", itemPrompt, terminal.PromptColor(">"))
		nameIndex, err = strconv.Atoi(nameString)

		if err != nil {
			cmd.ui.Say("")
			nameIndex = 1
			return nameString
		}
	}

	return names[nameIndex-1]
}
開發者ID:jalateras,項目名稱:cli,代碼行數:28,代碼來源:login.go

示例11: promptForName

func (cmd Login) promptForName(names []string, listPrompt, itemPrompt string) string {
	nameIndex := 0
	var nameString string
	for nameIndex < 1 || nameIndex > len(names) {
		var err error

		// list header
		cmd.ui.Say(listPrompt)

		// only display list if it is shorter than maxChoices
		if len(names) < maxChoices {
			for i, name := range names {
				cmd.ui.Say("%d. %s", i+1, name)
			}
		} else {
			cmd.ui.Say("There are too many options to display, please type in the name.")
		}

		nameString = cmd.ui.Ask("%s%s", itemPrompt, terminal.PromptColor(">"))
		if nameString == "" {
			return ""
		}

		nameIndex, err = strconv.Atoi(nameString)

		if err != nil {
			nameIndex = 1
			return nameString
		}
	}

	return names[nameIndex-1]
}
開發者ID:juggernaut,項目名稱:cli,代碼行數:33,代碼來源:login.go

示例12: ConfirmDelete

func (ui *FakeUI) ConfirmDelete(modelType, modelName string) bool {
	return ui.Confirm(
		"Really delete the %s %s?%s",
		modelType,
		term.EntityNameColor(modelName),
		term.PromptColor(">"))
}
開發者ID:nota-ja,項目名稱:cli,代碼行數:7,代碼來源:ui.go

示例13: authenticate

func (cmd Login) authenticate(c *cli.Context) {
	usernameFlagValue := c.String("u")
	passwordFlagValue := c.String("p")

	prompts, err := cmd.authenticator.GetLoginPromptsAndSaveUAAServerURL()
	if err != nil {
		cmd.ui.Failed(err.Error())
	}
	passwordKeys := []string{}
	credentials := make(map[string]string)
	for key, prompt := range prompts {
		if prompt.Type == configuration.AuthPromptTypePassword {
			passwordKeys = append(passwordKeys, key)
		} else if key == "username" && usernameFlagValue != "" {
			credentials[key] = usernameFlagValue
		} else {
			credentials[key] = cmd.ui.Ask("%s%s", prompt.DisplayName, terminal.PromptColor(">"))
		}
	}

	for i := 0; i < maxLoginTries; i++ {
		for _, key := range passwordKeys {
			if key == "password" && passwordFlagValue != "" {
				credentials[key] = passwordFlagValue
				passwordFlagValue = ""
			} else {
				credentials[key] = cmd.ui.AskForPassword("%s%s", prompts[key].DisplayName, terminal.PromptColor(">"))
			}
		}

		cmd.ui.Say("Authenticating...")
		err = cmd.authenticator.Authenticate(credentials)

		if err == nil {
			cmd.ui.Ok()
			cmd.ui.Say("")
			break
		}

		cmd.ui.Say(err.Error())
	}

	if err != nil {
		cmd.ui.Failed("Unable to authenticate.")
	}
}
開發者ID:julz,項目名稱:cli,代碼行數:46,代碼來源:login.go

示例14: Run

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
}
開發者ID:jalateras,項目名稱:cli,代碼行數:56,代碼來源:delete_space.go

示例15: authenticate

func (cmd Login) authenticate(c *cli.Context) {
	prompts, err := cmd.authenticator.GetLoginPromptsAndSaveUAAServerURL()
	if err != nil {
		cmd.ui.Failed(err.Error())
	}
	var passwordKey string
	credentials := make(map[string]string)
	for key, prompt := range prompts {
		if prompt.Type == configuration.AuthPromptTypePassword {
			passwordKey = key
		} else if key == "username" && c.String("u") != "" {
			credentials[key] = c.String("u")
		} else {
			credentials[key] = cmd.ui.Ask("%s%s", prompt.DisplayName, terminal.PromptColor(">"))
		}
	}

	password := c.String("p")
	passwordPrompt := prompts[passwordKey]

	for i := 0; i < maxLoginTries; i++ {
		if password == "" || i > 0 {
			password = cmd.ui.AskForPassword("%s%s", passwordPrompt.DisplayName, terminal.PromptColor(">"))
		}

		cmd.ui.Say("Authenticating...")

		credentials[passwordKey] = password
		err = cmd.authenticator.Authenticate(credentials)

		if err == nil {
			cmd.ui.Ok()
			cmd.ui.Say("")
			break
		}

		cmd.ui.Say(err.Error())
	}

	if err != nil {
		cmd.ui.Failed("Unable to authenticate.")
	}
}
開發者ID:knolleary,項目名稱:cli,代碼行數:43,代碼來源:login.go


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