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


Golang CliConnection.IsLoggedIn方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/cli/plugin.CliConnection.IsLoggedIn方法的典型用法代碼示例。如果您正苦於以下問題:Golang CliConnection.IsLoggedIn方法的具體用法?Golang CliConnection.IsLoggedIn怎麽用?Golang CliConnection.IsLoggedIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/cli/plugin.CliConnection的用法示例。


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

示例1: GetEnvs

func (a *AppEnv) GetEnvs(cli plugin.CliConnection, args []string) ([]string, error) {
	if loggedIn, _ := cli.IsLoggedIn(); loggedIn == false {
		return nil, errors.New("You must login first!")
	}

	if len(args) <= 1 {
		return nil, errors.New("You must specify an app name")
	}

	cliOut, err := a.GetAppEnvFromCli(cli, args[1])

	vcapServicesExport := a.GetJsonAndFormat("VCAP_SERVICES", cliOut)
	vcapAppExport := a.GetJsonAndFormat("VCAP_APPLICATION", cliOut)

	envvars := []string{}

	if vcapServicesExport != "" {
		envvars = append(envvars, vcapServicesExport)
	}

	if vcapAppExport != "" {
		envvars = append(envvars, vcapAppExport)
	}

	return envvars, err
}
開發者ID:Samze,項目名稱:appenvs,代碼行數:26,代碼來源:appenv.go

示例2: Run

func (c *Test1) Run(cliConnection plugin.CliConnection, args []string) {
	if args[0] == "new-api" {
		token, _ := cliConnection.AccessToken()
		fmt.Println("Access Token:", token)
		fmt.Println("")

		app, err := cliConnection.GetApp("test_app")
		fmt.Println("err for test_app", err)
		fmt.Println("test_app is: ", app)

		hasOrg, _ := cliConnection.HasOrganization()
		fmt.Println("Has Organization Targeted:", hasOrg)
		currentOrg, _ := cliConnection.GetCurrentOrg()
		fmt.Println("Current Org:", currentOrg)
		org, _ := cliConnection.GetOrg(currentOrg.Name)
		fmt.Println(currentOrg.Name, " Org:", org)
		orgs, _ := cliConnection.GetOrgs()
		fmt.Println("Orgs:", orgs)
		hasSpace, _ := cliConnection.HasSpace()
		fmt.Println("Has Space Targeted:", hasSpace)
		currentSpace, _ := cliConnection.GetCurrentSpace()
		fmt.Println("Current space:", currentSpace)
		space, _ := cliConnection.GetSpace(currentSpace.Name)
		fmt.Println("Space:", space)
		spaces, _ := cliConnection.GetSpaces()
		fmt.Println("Spaces:", spaces)
		loggregator, _ := cliConnection.LoggregatorEndpoint()
		fmt.Println("Loggregator Endpoint:", loggregator)
		dopplerEndpoint, _ := cliConnection.DopplerEndpoint()
		fmt.Println("Doppler Endpoint:", dopplerEndpoint)

		user, _ := cliConnection.Username()
		fmt.Println("Current user:", user)
		userGUID, _ := cliConnection.UserGuid()
		fmt.Println("Current user guid:", userGUID)
		email, _ := cliConnection.UserEmail()
		fmt.Println("Current user email:", email)

		hasAPI, _ := cliConnection.HasAPIEndpoint()
		fmt.Println("Has API Endpoint:", hasAPI)
		api, _ := cliConnection.ApiEndpoint()
		fmt.Println("Current api:", api)
		version, _ := cliConnection.ApiVersion()
		fmt.Println("Current api version:", version)

		loggedIn, _ := cliConnection.IsLoggedIn()
		fmt.Println("Is Logged In:", loggedIn)
		isSSLDisabled, _ := cliConnection.IsSSLDisabled()
		fmt.Println("Is SSL Disabled:", isSSLDisabled)
	} else if args[0] == "test_1_cmd1" {
		theFirstCmd()
	} else if args[0] == "test_1_cmd2" {
		theSecondCmd()
	} else if args[0] == "CLI-MESSAGE-UNINSTALL" {
		uninstalling()
	}
}
開發者ID:Reejoshi,項目名稱:cli,代碼行數:57,代碼來源:test_1.go

示例3: 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 *FastPushPlugin) Run(cliConnection plugin.CliConnection, args []string) {
	// Ensure that the user called the command fast-push
	// alias fp is auto mapped
	var dryRun bool
	c.ui = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())

	cliLogged, err := cliConnection.IsLoggedIn()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	if cliLogged == false {
		panic("cannot perform fast-push without being logged in to CF")
	}

	if args[0] == "fast-push" || args[0] == "fp" {
		if len(args) == 1 {
			c.showUsage(args)
			return
		}
		// set flag for dry run
		fc := flags.New()
		fc.NewBoolFlag("dry", "d", "bool dry run flag")

		err := fc.Parse(args[1:]...)
		if err != nil {
			c.ui.Failed(err.Error())
		}
		// check if the user asked for a dry run or not
		if fc.IsSet("dry") {
			dryRun = fc.Bool("dry")
		} else {
			c.ui.Warn("warning: dry run not set, commencing fast push")
		}

		c.ui.Say("Running the fast-push command")
		c.ui.Say("Target app: %s \n", args[1])
		c.FastPush(cliConnection, args[1], dryRun)
	} else if args[0] == "fast-push-status" || args[0] == "fps" {
		c.FastPushStatus(cliConnection, args[1])
	} else {
		return
	}

}
開發者ID:riccardomc,項目名稱:cf-fastpush-plugin,代碼行數:59,代碼來源:main.go

示例4: DiegoMigrationCommand

func (cmd *DiegoMigrationCmd) DiegoMigrationCommand(cli plugin.CliConnection, args []string) {
	if nil == cli {
		fmt.Println("ERROR: CLI Connection is nil!")
		os.Exit(1)
	}

	fmt.Println("Crawling orgs and spaces for app info")

	//TODO - have dan explain why my code sucks

	if isLoggedIn, err := cli.IsLoggedIn(); err == nil && isLoggedIn != true {
		fmt.Println("You are not logged in. Please login using 'cf login' and try again")
		os.Exit(1)
	}

	if args[0] == "diego-migration" && args[1] == "report" {
		cmd.printDiegoReportForAllApps(cli)
	} else if args[0] == "diego-migration" && args[1] == "enable" && len(args) == 3 {
		cmd.toggleDiego(cli, args[2], true)
	} else if args[0] == "diego-migration" && args[1] == "disable" && len(args) == 3 {
		cmd.toggleDiego(cli, args[2], false)
	}

}
開發者ID:pivotalservices,項目名稱:diego-migration-plugin,代碼行數:24,代碼來源:diegomigration.go

示例5: CFMainChecks

// CFMainChecks is responsible if the environment is okay for running doctor
func (c *DoctorPlugin) CFMainChecks(cliConnection plugin.CliConnection) {
	cliLogged, err := cliConnection.IsLoggedIn()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	cliHasOrg, err := cliConnection.HasOrganization()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	cliHasSpace, err := cliConnection.HasSpace()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	if cliLogged == false {
		panic("doctor cannot work without being logged in to CF")
	}

	if cliHasOrg == false || cliHasSpace == false {
		c.ui.Warn("WARN: It seems that your cloudfoundry has no space or org...")
	}
}
開發者ID:afeld,項目名稱:cf-doctor-plugin,代碼行數:25,代碼來源:main.go


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