本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/terminal.NewUI函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUI函数的具体用法?Golang NewUI怎么用?Golang NewUI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUI函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *NozzlerCmd) Run(cliConnection plugin.CliConnection, args []string) {
var debug bool
if args[0] != "nozzle" {
return
}
c.ui = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())
fc := flags.NewFlagContext(setupFlags())
err := fc.Parse(args[1:]...)
if err != nil {
c.ui.Failed(err.Error())
}
if fc.IsSet("debug") {
debug = fc.Bool("debug")
}
dopplerEndpoint, err := cliConnection.DopplerEndpoint()
if err != nil {
c.ui.Failed(err.Error())
}
authToken, err := cliConnection.AccessToken()
if err != nil {
c.ui.Failed(err.Error())
}
client := firehose.NewClient(authToken, dopplerEndpoint, debug, c.ui)
client.Start()
}
示例2: NewListAppsCommand
func NewListAppsCommand(cliConnection api.Connection, orgName string, spaceName string, runtime ui.Runtime) (ui.ListAppsCommand, error) {
username, err := cliConnection.Username()
if err != nil {
return ui.ListAppsCommand{}, err
}
if spaceName != "" {
space, err := cliConnection.GetSpace(spaceName)
if err != nil || space.Guid == "" {
return ui.ListAppsCommand{}, err
}
orgName = space.Organization.Name
}
traceEnv := os.Getenv("CF_TRACE")
traceLogger := trace.NewLogger(false, traceEnv, "")
tUI := terminal.NewUI(os.Stdin, terminal.NewTeePrinter(), traceLogger)
cmd := ui.ListAppsCommand{
Username: username,
Organization: orgName,
Space: spaceName,
UI: tUI,
Runtime: runtime,
}
return cmd, nil
}
示例3: newRequestForFile
func newRequestForFile(method, fullUrl string, body *os.File) (req *Request, apiErr error) {
ui := terminal.NewUI(os.Stdin, &cliutil.NonPrinter{})
progressReader := net.NewProgressReader(body, ui, 5*time.Second)
progressReader.Seek(0, 0)
fileStats, err := body.Stat()
if err != nil {
apiErr = fmt.Errorf("%s: %s", "Error getting file info", err.Error())
return
}
request, err := http.NewRequest(method, fullUrl, progressReader)
if err != nil {
apiErr = fmt.Errorf("%s: %s", "Error building request", err.Error())
return
}
fileSize := fileStats.Size()
progressReader.SetTotalSize(fileSize)
request.ContentLength = fileSize
if err != nil {
apiErr = fmt.Errorf("%s: %s", "Error building request", err.Error())
return
}
return newRequest(request, progressReader)
}
示例4: setupDependencies
func setupDependencies() (deps *cliDependencies) {
deps = new(cliDependencies)
deps.termUI = terminal.NewUI(os.Stdin)
deps.manifestRepo = manifest.NewManifestDiskRepository()
deps.configRepo = configuration.NewRepositoryFromFilepath(configuration.DefaultFilePath(), func(err error) {
if err != nil {
deps.termUI.Failed(fmt.Sprintf("Config error: %s", err))
}
})
i18n.T = i18n.Init(deps.configRepo)
terminal.UserAskedForColors = deps.configRepo.ColorEnabled()
terminal.InitColorSupport()
if os.Getenv("CF_TRACE") != "" {
trace.Logger = trace.NewLogger(os.Getenv("CF_TRACE"))
} else {
trace.Logger = trace.NewLogger(deps.configRepo.Trace())
}
deps.gateways = map[string]net.Gateway{
"auth": net.NewUAAGateway(deps.configRepo),
"cloud-controller": net.NewCloudControllerGateway(deps.configRepo, time.Now),
"uaa": net.NewUAAGateway(deps.configRepo),
}
deps.apiRepoLocator = api.NewRepositoryLocator(deps.configRepo, deps.gateways)
return
}
示例5: Run
func (s *FirehoseStatsCmd) Run(cliConnection plugin.CliConnection, args []string) {
if args[0] != "firehose-stats" {
return
}
s.cfUI = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())
dopplerEndpoint, err := cliConnection.DopplerEndpoint()
if err != nil {
s.cfUI.Failed(err.Error())
}
authToken, err := cliConnection.AccessToken()
if err != nil {
s.cfUI.Failed(err.Error())
}
firehoseChan := make(chan *events.Envelope)
client := firehose.NewClient(authToken, dopplerEndpoint, s.cfUI, firehoseChan)
client.Start()
statsUI := stats.New(client, s.cfUI, cliConnection)
statsUI.Start()
}
示例6: CallCoreCommand
func (cmd *CliRpcCmd) CallCoreCommand(args []string, retVal *bool) error {
defer func() {
recover()
}()
var err error
cmdRegistry := command_registry.Commands
cmd.outputBucket = &[]string{}
cmd.outputCapture.SetOutputBucket(cmd.outputBucket)
if cmdRegistry.CommandExists(args[0]) {
deps := command_registry.NewDependency()
//set deps objs to be the one used by all other codegangsta commands
//once all commands are converted, we can make fresh deps for each command run
deps.Config = cmd.cliConfig
deps.RepoLocator = cmd.repoLocator
deps.Ui = terminal.NewUI(os.Stdin, cmd.outputCapture.(*terminal.TeePrinter))
err = cmd.newCmdRunner.Command(args, deps, false)
} else {
//call codegangsta command
err = cmd.coreCommandRunner.Run(append([]string{"CF_NAME"}, args...))
}
if err != nil {
*retVal = false
return err
}
*retVal = true
return nil
}
示例7: NewDependency
func NewDependency() Dependency {
deps := Dependency{}
deps.TeePrinter = terminal.NewTeePrinter()
deps.Ui = terminal.NewUI(os.Stdin, deps.TeePrinter)
deps.ManifestRepo = manifest.NewManifestDiskRepository()
errorHandler := func(err error) {
if err != nil {
deps.Ui.Failed(fmt.Sprintf("Config error: %s", err))
}
}
deps.Config = core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), errorHandler)
deps.PluginConfig = plugin_config.NewPluginConfig(errorHandler)
deps.Detector = &detection.JibberJabberDetector{}
terminal.UserAskedForColors = deps.Config.ColorEnabled()
terminal.InitColorSupport()
if os.Getenv("CF_TRACE") != "" {
trace.Logger = trace.NewLogger(os.Getenv("CF_TRACE"))
} else {
trace.Logger = trace.NewLogger(deps.Config.Trace())
}
deps.Gateways = map[string]net.Gateway{
"auth": net.NewUAAGateway(deps.Config, deps.Ui),
"cloud-controller": net.NewCloudControllerGateway(deps.Config, time.Now, deps.Ui),
"uaa": net.NewUAAGateway(deps.Config, deps.Ui),
}
deps.RepoLocator = api.NewRepositoryLocator(deps.Config, deps.Gateways)
deps.PluginModels = &pluginModels{Application: nil}
return deps
}
示例8: Run
func (c *NozzlerCmd) Run(cliConnection plugin.CliConnection, args []string) {
var options *firehose.ClientOptions
traceLogger := trace.NewLogger(os.Stdout, true, os.Getenv("CF_TRACE"), "")
c.ui = terminal.NewUI(os.Stdin, os.Stdout, terminal.NewTeePrinter(os.Stdout), traceLogger)
switch args[0] {
case "nozzle":
options = c.buildClientOptions(args)
case "app-nozzle":
options = c.buildClientOptions(args)
appModel, err := cliConnection.GetApp(args[1])
if err != nil {
c.ui.Warn(err.Error())
return
}
options.AppGUID = appModel.Guid
default:
return
}
dopplerEndpoint, err := cliConnection.DopplerEndpoint()
if err != nil {
c.ui.Failed(err.Error())
}
authToken, err := cliConnection.AccessToken()
if err != nil {
c.ui.Failed(err.Error())
}
client := firehose.NewClient(authToken, dopplerEndpoint, options, c.ui)
client.Start()
}
示例9: WildcardCommandApps
func (cmd *Wildcard) WildcardCommandApps(cliConnection plugin.CliConnection, args []string) {
InitializeCliDependencies()
defer panic.HandlePanics()
cmd.getMatchedApps(cliConnection, args)
cmd.ui = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())
table := terminal.NewTable(cmd.ui, []string{T("name"), T("requested state"), T("instances"), T("memory"), T("disk"), T("urls")})
for _, app := range cmd.matchedApps {
var urls []string
for _, route := range app.Routes {
if route.Host == "" {
urls = append(urls, route.Domain.Name)
}
urls = append(urls, fmt.Sprintf("%s.%s", route.Host, route.Domain.Name))
}
table.Add(
app.Name,
app.State,
strconv.Itoa(app.RunningInstances),
formatters.ByteSize(app.Memory*formatters.MEGABYTE),
formatters.ByteSize(app.DiskQuota*formatters.MEGABYTE),
strings.Join(urls, ", "),
)
}
table.Print()
}
示例10: handlePanics
func handlePanics() {
panic_printer.UI = terminal.NewUI(os.Stdin)
commandArgs := strings.Join(os.Args, " ")
stackTrace := generateBacktrace()
err := recover()
panic_printer.DisplayCrashDialog(err, commandArgs, stackTrace)
if err != nil {
os.Exit(1)
}
}
示例11: handlePanics
func handlePanics(args []string, printer terminal.Printer, logger trace.Printer) {
panicPrinter := panicprinter.NewPanicPrinter(terminal.NewUI(os.Stdin, Writer, printer, logger))
commandArgs := strings.Join(args, " ")
stackTrace := generateBacktrace()
err := recover()
panicPrinter.DisplayCrashDialog(err, commandArgs, stackTrace)
if err != nil {
os.Exit(1)
}
}
示例12: Run
/*
* This function must be implemented by any plugin because it is part of the
* plugin interface defined by the core CLI.
*
* Run(....) is the entry point when the core CLI is invoking a command defined
* by a plugin. The first parameter, plugin.CliConnection, is a struct that can
* be used to invoke cli commands. The second paramter, args, is a slice of
* strings. args[0] will be the name of the command, and will be followed by
* any additional arguments a cli user typed in.
*
* Any error handling should be handled with the plugin itself (this means printing
* user facing errors). The CLI will exit 0 if the plugin exits 0 and will exit
* 1 should the plugin exits nonzero.
*/
func (c *DoctorPlugin) Run(cliConnection plugin.CliConnection, args []string) {
fmt.Printf("\n\n")
var triageApps []string
var triageRoutes []string
var triageServices []string
c.ui = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())
c.ui.Say(terminal.WarningColor("doctor: time to triage cloudfoundry"))
fmt.Printf("\n")
c.CFMainChecks(cliConnection)
listOfRunningApps := c.AppsStateRunning(cliConnection)
listOfStoppedApps := c.AppsStateStopped(cliConnection)
triageApps = c.CheckUpApps(cliConnection, triageApps, listOfRunningApps, listOfStoppedApps)
triageRoutes = c.CheckUpRoutes(cliConnection, triageRoutes)
triageServices = c.CheckUpServices(cliConnection, triageServices)
if len(triageApps) == 0 && len(triageRoutes) == 0 && len(triageServices) == 0 {
c.ui.Say(terminal.SuccessColor("doctor: Everything looks OK!"))
return
}
// doctor run results
if len(triageApps) > 0 {
c.ui.Say(terminal.WarningColor("Detected triage points for apps: "))
for _, v := range triageApps {
c.ui.Say(terminal.LogStderrColor(strings.Split(v, "___")[0]+" <---> ") + terminal.LogStderrColor(strings.Split(v, "___")[1]))
}
}
c.ui.Say(" ")
if len(triageRoutes) > 0 {
c.ui.Say(terminal.WarningColor("Following routes do not have any app bound to them:"))
for _, y := range triageRoutes {
c.ui.Say(terminal.LogStderrColor(y))
}
}
fmt.Printf("\n")
if len(triageServices) > 0 {
c.ui.Say(terminal.WarningColor("Following services do not have any app bound to them:"))
for _, y := range triageServices {
c.ui.Say(terminal.LogStderrColor(y))
}
}
}
示例13: New
func New(ccTarget string, uaaTarget string, username string, password string) (*CFServices, error) {
cfs := CFServices{
CCTarget: ccTarget,
UAATarget: uaaTarget,
Username: username,
Password: password,
SessionID: uuid.New(),
}
cfs.gateways = make(map[string]net.Gateway)
cfs.configFilePath = strings.Replace(config_helpers.DefaultFilePath(), ".json", "."+cfs.SessionID+".json", -1)
cfs.config = core_config.NewRepositoryFromFilepath(cfs.configFilePath,
func(err error) {
if err != nil {
fmt.Printf("Config error: %s", err)
}
})
cfs.config.SetApiEndpoint(ccTarget)
cfs.config.SetAuthenticationEndpoint(uaaTarget)
cfs.config.SetUaaEndpoint(uaaTarget)
cfs.config.SetSSLDisabled(true)
cfs.teePrinter = terminal.NewTeePrinter()
cfs.termUI = terminal.NewUI(os.Stdin, cfs.teePrinter)
cfs.detector = &detection.JibberJabberDetector{}
T = Init(cfs.config, cfs.detector)
terminal.UserAskedForColors = cfs.config.ColorEnabled()
terminal.InitColorSupport()
cfs.gateways["cloud-controller"] = net.NewCloudControllerGateway(cfs.config, time.Now, cfs.termUI)
cfs.gateways["auth"] = net.NewUAAGateway(cfs.config, cfs.termUI)
cfs.gateways["uaa"] = net.NewUAAGateway(cfs.config, cfs.termUI)
cfs.authRepo = authentication.NewUAAAuthenticationRepository(cfs.gateways["uaa"], cfs.config)
cfs.Organizations = organizations.NewCloudControllerOrganizationRepository(cfs.config, cfs.gateways["cloud-controller"])
cfs.Spaces = spaces.NewCloudControllerSpaceRepository(cfs.config, cfs.gateways["cloud-controller"])
cfs.Services = api.NewCloudControllerServiceRepository(cfs.config, cfs.gateways["cloud-controller"])
cfs.Plans = api.NewCloudControllerServicePlanRepository(cfs.config, cfs.gateways["cloud-controller"])
err := cfs.authRepo.Authenticate(map[string]string{
"username": username,
"password": password,
})
return &cfs, err
}
示例14: GetOrg
func (cmd *CliRpcCmd) GetOrg(orgName string, retVal *plugin_models.GetOrg_Model) error {
defer func() {
recover()
}()
deps := commandregistry.NewDependency(cmd.stdout, cmd.logger, dialTimeout)
//set deps objs to be the one used by all other commands
//once all commands are converted, we can make fresh deps for each command run
deps.Config = cmd.cliConfig
deps.RepoLocator = cmd.repoLocator
deps.PluginModels.Organization = retVal
cmd.terminalOutputSwitch.DisableTerminalOutput(true)
deps.UI = terminal.NewUI(os.Stdin, cmd.stdout, cmd.terminalOutputSwitch.(*terminal.TeePrinter), cmd.logger)
return cmd.newCmdRunner.Command([]string{"org", orgName}, deps, true)
}
示例15: GetSpaceUsers
func (cmd *CliRpcCmd) GetSpaceUsers(args []string, retVal *[]plugin_models.User) error {
defer func() {
recover()
}()
deps := command_registry.NewDependency()
//set deps objs to be the one used by all other codegangsta commands
//once all commands are converted, we can make fresh deps for each command run
deps.Config = cmd.cliConfig
deps.RepoLocator = cmd.repoLocator
deps.PluginModels.Users = retVal
cmd.terminalOutputSwitch.DisableTerminalOutput(true)
deps.Ui = terminal.NewUI(os.Stdin, cmd.terminalOutputSwitch.(*terminal.TeePrinter))
return cmd.newCmdRunner.Command(append([]string{"space-users"}, args...), deps, true)
}