Golang cf-terminal.WarningColor类(方法)实例源码

下面列出了Golang cf-terminal.WarningColor 类(方法)源码代码实例,从而了解它的用法。

作者: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"))
	}
}

作者:nsn    项目:cl   
func (cmd *Stop) ApplicationStop(app cf.Application) (updatedApp cf.Application, err error) {
	if app.State == "stopped" {
		updatedApp = app
		cmd.ui.Say(terminal.WarningColor("App " + app.Name + " is already stopped"))
		return
	}

	cmd.ui.Say("Stopping app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields.Name),
		terminal.EntityNameColor(cmd.config.SpaceFields.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	params := cf.NewEmptyAppParams()
	params.Set("state", "STOPPED")

	updatedApp, apiResponse := cmd.appRepo.Update(app.Guid, params)
	if apiResponse.IsNotSuccessful() {
		err = errors.New(apiResponse.Message)
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	return
}

作者:knollear    项目:cl   
func (cmd *Stop) ApplicationStop(app models.Application) (updatedApp models.Application, err error) {
	if app.State == "stopped" {
		updatedApp = app
		cmd.ui.Say(terminal.WarningColor("App " + app.Name + " is already stopped"))
		return
	}

	cmd.ui.Say("Stopping app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	state := "STOPPED"
	updatedApp, apiErr := cmd.appRepo.Update(app.Guid, models.AppParams{State: &state})
	if apiErr != nil {
		err = errors.New(apiErr.Error())
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	return
}

作者:jul    项目:cl   
func (cmd *Stop) Run(c *cli.Context) {
	app := cmd.appReq.GetApplication()
	if app.State == "stopped" {
		cmd.ui.Say(terminal.WarningColor("App " + app.Name + " is already stopped"))
	} else {
		cmd.ApplicationStop(app)
	}
}

作者:jalatera    项目:cl   
func (cmd *Start) ApplicationStart(app cf.Application) (updatedApp cf.Application, err error) {
	if app.State == "started" {
		cmd.ui.Say(terminal.WarningColor("App " + app.Name + " is already started"))
		return
	}

	cmd.ui.Say("Starting app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.Organization.Name),
		terminal.EntityNameColor(cmd.config.Space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	updatedApp, apiResponse := cmd.appRepo.Start(app)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()

	logChan := make(chan *logmessage.Message, 1000)
	go cmd.displayLogMessages(logChan)

	onConnect := func() {
		cmd.ui.Say("\n%s", terminal.HeaderColor("Staging..."))
	}

	stopLoggingChan := make(chan bool)
	go cmd.logRepo.TailLogsFor(app, onConnect, logChan, stopLoggingChan, 1)

	instances, apiResponse := cmd.appRepo.GetInstances(updatedApp)
	for apiResponse.IsNotSuccessful() {
		if apiResponse.ErrorCode != cf.APP_NOT_STAGED {
			cmd.ui.Say("")
			cmd.ui.Failed(apiResponse.Message)
			return
		}

		cmd.ui.Wait(1 * time.Second)
		instances, apiResponse = cmd.appRepo.GetInstances(updatedApp)
	}

	stopLoggingChan <- true

	cmd.ui.Say("")

	cmd.startTime = time.Now()

	for cmd.displayInstancesStatus(app, instances) {
		cmd.ui.Wait(1 * time.Second)
		instances, _ = cmd.appRepo.GetInstances(updatedApp)
	}
	return
}

作者:nota-j    项目:cl   
func (cmd Authenticate) Metadata() command_metadata.CommandMetadata {
	return command_metadata.CommandMetadata{
		Name:        "auth",
		Description: "Authenticate user non-interactively",
		Usage: "CF_NAME auth USERNAME PASSWORD\n\n" +
			terminal.WarningColor("WARNING:\n   Providing your password as a command line option is highly discouraged\n   Your password may be visible to others and may be recorded in your shell history\n\n") +
			"EXAMPLE:\n" +
			"   CF_NAME auth [email protected] \"my password\" (use quotes for passwords with a space)\n" +
			"   CF_NAME auth [email protected] \"\\\"password\\\"\" (escape quotes if used in password)",
	}
}

作者:jbaye    项目:cl   
func (s *Stop) ApplicationStop(app cf.Application) {
	if app.State == "stopped" {
		s.ui.Say(term.WarningColor("Application " + app.Name + " is already stopped."))
		return
	}

	s.ui.Say("Stopping %s...", term.EntityNameColor(app.Name))

	err := s.appRepo.Stop(app)
	if err != nil {
		s.ui.Failed(err.Error())
		return
	}
	s.ui.Ok()
}

作者:jbaye    项目:cl   
func coloredState(state string) (colored string) {
	switch state {
	case "started", "running":
		colored = term.SuccessColor("running")
	case "stopped":
		colored = term.StoppedColor("stopped")
	case "flapping":
		colored = term.WarningColor("flapping")
	case "starting":
		colored = term.AdvisoryColor("starting")
	default:
		colored = term.FailureColor(state)
	}

	return
}

作者:nota-j    项目:cl   
func ColoredAppState(app models.ApplicationFields) string {
	appState := strings.ToLower(app.State)

	if app.RunningInstances == 0 {
		if appState == "stopped" {
			return appState
		} else {
			return terminal.CrashedColor(appState)
		}
	}

	if app.RunningInstances < app.InstanceCount {
		return terminal.WarningColor(appState)
	}

	return appState
}

作者:jalatera    项目:cl   
func coloredInstanceState(instance cf.ApplicationInstance) (colored string) {
	state := string(instance.State)
	switch state {
	case "started", "running":
		colored = terminal.StartedColor("running")
	case "stopped":
		colored = terminal.StoppedColor("stopped")
	case "flapping":
		colored = terminal.WarningColor("crashing")
	case "starting":
		colored = terminal.AdvisoryColor("starting")
	default:
		colored = terminal.FailureColor(state)
	}

	return
}

作者:nota-j    项目:cl   
func ColoredAppInstances(app models.ApplicationFields) string {
	healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount)

	if app.RunningInstances == 0 {
		if strings.ToLower(app.State) == "stopped" {
			return healthString
		} else {
			return terminal.CrashedColor(healthString)
		}
	}

	if app.RunningInstances < app.InstanceCount {
		return terminal.WarningColor(healthString)
	}

	return healthString
}

作者:nota-j    项目:cl   
func ColoredInstanceState(instance models.AppInstanceFields) (colored string) {
	state := string(instance.State)
	switch state {
	case "started", "running":
		colored = "running"
	case "stopped":
		colored = terminal.StoppedColor("stopped")
	case "flapping":
		colored = terminal.CrashedColor("crashing")
	case "down":
		colored = terminal.CrashedColor("down")
	case "starting":
		colored = terminal.AdvisoryColor("starting")
	default:
		colored = terminal.WarningColor(state)
	}

	return
}

作者:nsn    项目:cl   
func (cmd *Start) ApplicationStart(app cf.Application) (updatedApp cf.Application, err error) {
	if app.State == "started" {
		cmd.ui.Say(terminal.WarningColor("App " + app.Name + " is already started"))
		return
	}

	stopLoggingChan := make(chan bool, 1)
	defer close(stopLoggingChan)
	loggingStartedChan := make(chan bool)
	defer close(loggingStartedChan)

	go cmd.tailStagingLogs(app, loggingStartedChan, stopLoggingChan)

	<-loggingStartedChan

	cmd.ui.Say("Starting app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields.Name),
		terminal.EntityNameColor(cmd.config.SpaceFields.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	params := cf.NewEmptyAppParams()
	params.Set("state", "STARTED")
	updatedApp, apiResponse := cmd.appRepo.Update(app.Guid, params)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()

	cmd.waitForInstancesToStage(updatedApp)
	stopLoggingChan <- true

	cmd.ui.Say("")

	cmd.waitForOneRunningInstance(app.Guid)
	cmd.ui.Say(terminal.HeaderColor("\nApp started\n"))

	cmd.appDisplayer.ShowApp(app)
	return
}

作者:jul    项目:cl   
func (cmd *Start) ApplicationStart(app models.Application) (updatedApp models.Application, err error) {
	if app.State == "started" {
		cmd.ui.Say(terminal.WarningColor("App " + app.Name + " is already started"))
		return
	}

	stopLoggingChan := make(chan bool, 1)
	defer close(stopLoggingChan)
	loggingStartedChan := make(chan bool)
	defer close(loggingStartedChan)

	go cmd.tailStagingLogs(app, loggingStartedChan, stopLoggingChan)

	<-loggingStartedChan

	cmd.ui.Say("Starting app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	state := "STARTED"
	updatedApp, apiErr := cmd.appRepo.Update(app.Guid, models.AppParams{State: &state})
	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()

	cmd.waitForInstancesToStage(updatedApp)
	stopLoggingChan <- true

	cmd.ui.Say("")

	cmd.waitForOneRunningInstance(updatedApp)
	cmd.ui.Say(terminal.HeaderColor("\nApp started\n"))

	cmd.appDisplayer.ShowApp(updatedApp)
	return
}

作者:nsn    项目:cl   
func (cmd Login) setApi(c *cli.Context) (apiResponse net.ApiResponse) {
	api := c.String("a")
	if api == "" {
		api = cmd.config.Target
	}

	if api == "" {
		api = cmd.ui.Ask("API endpoint%s", terminal.PromptColor(">"))
	} else {
		cmd.ui.Say("API endpoint: %s", terminal.EntityNameColor(api))
	}

	endpoint, apiResponse := cmd.endpointRepo.UpdateEndpoint(api)

	if !strings.HasPrefix(endpoint, "https://") {
		cmd.ui.Say(terminal.WarningColor("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n"))
	}

	return
}

作者:jbaye    项目:cl   
func (cmd Api) setNewApiEndpoint(endpoint string) {
	cmd.ui.Say("Setting api endpoint to %s...", term.EntityNameColor(endpoint))

	request, apiErr := cmd.gateway.NewRequest("GET", endpoint+"/v2/info", "", nil)

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	scheme := request.URL.Scheme
	if scheme != "http" && scheme != "https" {
		cmd.ui.Failed("API Endpoints should start with https:// or http://")
		return
	}

	serverResponse := new(InfoResponse)
	apiErr = cmd.gateway.PerformRequestForJSONResponse(request, &serverResponse)

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	err := cmd.saveEndpoint(endpoint, serverResponse)

	if err != nil {
		cmd.ui.Failed(err.Error())
		return
	}

	cmd.ui.Ok()

	if scheme == "http" {
		cmd.ui.Say(term.WarningColor("\nWarning: Insecure http API Endpoint detected. Secure https API Endpoints are recommended.\n"))
	}

	cmd.showApiEndpoint()

	cmd.ui.Say(term.NotLoggedInText())
}

作者:jibin-tom    项目:cl   
func (cmd Api) SetApiEndpoint(endpoint string) {
	if strings.HasSuffix(endpoint, "/") {
		endpoint = strings.TrimSuffix(endpoint, "/")
	}

	cmd.ui.Say("Setting api endpoint to %s...", terminal.EntityNameColor(endpoint))

	endpoint, apiErr := cmd.endpointRepo.UpdateEndpoint(endpoint)
	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	if !strings.HasPrefix(endpoint, "https://") {
		cmd.ui.Say(terminal.WarningColor("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n"))
	}

	cmd.ui.ShowConfiguration(cmd.config)
}

作者:nota-j    项目:cl   
func (command Login) Metadata() command_metadata.CommandMetadata {
	return command_metadata.CommandMetadata{
		Name:        "login",
		ShortName:   "l",
		Description: "Log user in",
		Usage: "CF_NAME login [-a API_URL] [-u USERNAME] [-p PASSWORD] [-o ORG] [-s SPACE]\n\n" +
			terminal.WarningColor("WARNING:\n   Providing your password as a command line option is highly discouraged\n   Your password may be visible to others and may be recorded in your shell history\n\n") +
			"EXAMPLE:\n" +
			"   CF_NAME login (omit username and password to login interactively -- CF_NAME will prompt for both)\n" +
			"   CF_NAME login -u [email protected] -p pa55woRD (specify username and password as arguments)\n" +
			"   CF_NAME login -u [email protected] -p \"my password\" (use quotes for passwords with a space)\n" +
			"   CF_NAME login -u [email protected] -p \"\\\"password\\\"\" (escape quotes if used in password)",
		Flags: []cli.Flag{
			flag_helpers.NewStringFlag("a", "API endpoint (e.g. https://api.example.com)"),
			flag_helpers.NewStringFlag("u", "Username"),
			flag_helpers.NewStringFlag("p", "Password"),
			flag_helpers.NewStringFlag("o", "Org"),
			flag_helpers.NewStringFlag("s", "Space"),
			cli.BoolFlag{Name: "skip-ssl-validation", Usage: "Please don't"},
		},
	}
}

作者:jbaye    项目:cl   
func (s *Start) ApplicationStart(app cf.Application) {
	if app.State == "started" {
		s.ui.Say(term.WarningColor("Application " + app.Name + " is already started."))
		return
	}

	s.ui.Say("Starting %s...", term.EntityNameColor(app.Name))

	apiErr := s.appRepo.Start(app)
	if apiErr != nil {
		s.ui.Failed(apiErr.Error())
		return
	}

	s.ui.Ok()

	instances, apiErr := s.appRepo.GetInstances(app)

	for apiErr != nil {
		if apiErr.ErrorCode != "170002" {
			s.ui.Say("")
			s.ui.Failed(apiErr.Error())
			return
		}

		s.ui.Wait(1 * time.Second)
		instances, apiErr = s.appRepo.GetInstances(app)
		s.ui.LoadingIndication()
	}

	s.ui.Say("")

	s.startTime = time.Now()

	for s.displayInstancesStatus(app, instances) {
		s.ui.Wait(1 * time.Second)
		instances, _ = s.appRepo.GetInstances(app)
	}
}

作者:nsn    项目:cl   
func NewApp(cmdRunner commands.Runner) (app *cli.App, err error) {
	helpCommand := cli.Command{
		Name:        "help",
		ShortName:   "h",
		Description: "Show help",
		Usage:       fmt.Sprintf("%s help [COMMAND]", cf.Name()),
		Action: func(c *cli.Context) {
			args := c.Args()
			if len(args) > 0 {
				cli.ShowCommandHelp(c, args[0])
			} else {
				showAppHelp(c.App)
			}
		},
	}

	app = cli.NewApp()
	app.Usage = cf.Usage
	app.Version = cf.Version
	app.Action = helpCommand.Action
	app.Commands = []cli.Command{
		helpCommand,
		{
			Name:        "api",
			Description: "Set or view target api url",
			Usage:       fmt.Sprintf("%s api [URL]", cf.Name()),
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("api", c)
			},
		},
		{
			Name:        "app",
			Description: "Display health and status for app",
			Usage:       fmt.Sprintf("%s app APP", cf.Name()),
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("app", c)
			},
		},
		{
			Name:        "apps",
			ShortName:   "a",
			Description: "List all apps in the target space",
			Usage:       fmt.Sprintf("%s apps", cf.Name()),
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("apps", c)
			},
		},
		{
			Name:        "auth",
			Description: "Authenticate user non-interactively",
			Usage: fmt.Sprintf("%s auth USERNAME PASSWORD\n\n", cf.Name()) +
				terminal.WarningColor("WARNING:\n   Providing your password as a command line option is highly discouraged\n   Your password may be visible to others and may be recorded in your shell history\n\n") +
				"EXAMPLE:\n" +
				fmt.Sprintf("   %s auth [email protected] \"my password\" (use quotes for passwords with a space)\n", cf.Name()) +
				fmt.Sprintf("   %s auth [email protected] \"\\\"password\\\"\" (escape quotes if used in password)", cf.Name()),
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("auth", c)
			},
		},
		{
			Name:        "bind-service",
			ShortName:   "bs",
			Description: "Bind a service instance to an app",
			Usage:       fmt.Sprintf("%s bind-service APP SERVICE_INSTANCE", cf.Name()),
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("bind-service", c)
			},
		},
		{
			Name:        "buildpacks",
			Description: "List all buildpacks",
			Usage:       fmt.Sprintf("%s buildpacks", cf.Name()),
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("buildpacks", c)
			},
		},
		{
			Name:        "create-buildpack",
			Description: "Create a buildpack",
			Usage:       fmt.Sprintf("%s create-buildpack BUILDPACK PATH POSITION [--enable|--disable]", cf.Name()),
			Flags: []cli.Flag{
				cli.BoolFlag{Name: "enable", Usage: "Enable the buildpack"},
				cli.BoolFlag{Name: "disable", Usage: "Disable the buildpack"},
			},
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("create-buildpack", c)
			},
		},
		{
			Name:        "create-domain",
			Description: "Create a domain in an org for later use",
			Usage:       fmt.Sprintf("%s create-domain ORG DOMAIN", cf.Name()),
			Action: func(c *cli.Context) {
				cmdRunner.RunCmdByName("create-domain", c)
			},
		},
		{
			Name:        "create-org",
			ShortName:   "co",
			Description: "Create an org",
//.........这里部分代码省略.........


问题


面经


文章

微信
公众号

扫码关注公众号