示例#1
0
文件: target.go 项目: jasonkeene/cli
func (cmd *Target) Execute(c flags.FlagContext) error {
	orgName := c.String("o")
	spaceName := c.String("s")

	if orgName != "" {
		err := cmd.setOrganization(orgName)
		if err != nil {
			return err
		} else if spaceName == "" {
			spaceList, apiErr := cmd.getSpaceList()
			if apiErr == nil && len(spaceList) == 1 {
				cmd.setSpace(spaceList[0].Name)
			}
		}
	}

	if spaceName != "" {
		err := cmd.setSpace(spaceName)
		if err != nil {
			return err
		}
	}

	err := cmd.ui.ShowConfiguration(cmd.config)
	if err != nil {
		return err
	}
	cmd.ui.NotifyUpdateIfNeeded(cmd.config)
	if !cmd.config.IsLoggedIn() {
		return fmt.Errorf(terminal.NotLoggedInText())
	}
	return nil
}
示例#2
0
文件: login.go 项目: yingkitw/cli
func (req LoginRequirement) Execute() error {

	if apiErr := req.apiEndpointRequirement.Execute(); apiErr != nil {
		return apiErr
	}

	if !req.config.IsLoggedIn() {
		return errors.New(terminal.NotLoggedInText())
	}

	return nil
}
示例#3
0
文件: login.go 项目: GABONIA/cli
func (req LoginRequirement) Execute() (success bool) {
	if !req.apiEndpointRequirement.Execute() {
		return false
	}

	if !req.config.IsLoggedIn() {
		req.ui.Say(terminal.NotLoggedInText())
		return false
	}

	return true
}
示例#4
0
func (uaa UAAAuthenticationRepository) RefreshAuthToken() (updatedToken string, apiErr error) {
	data := url.Values{
		"refresh_token": {uaa.config.RefreshToken()},
		"grant_type":    {"refresh_token"},
		"scope":         {""},
	}

	apiErr = uaa.getAuthToken(data)
	updatedToken = uaa.config.AccessToken()

	if apiErr != nil {
		fmt.Printf("%s\n\n", terminal.NotLoggedInText())
		os.Exit(1)
	}

	return
}
示例#5
0
文件: main.go 项目: wendorf/web-cli
func (ui *browserUI) ShowConfiguration(config core_config.Reader) {
	table := terminal.NewTable(ui, []string{"", ""})

	if config.HasAPIEndpoint() {
		table.Add(
			T("API endpoint:"),
			T("{{.ApiEndpoint}} (API version: {{.ApiVersionString}})",
				map[string]interface{}{
					"ApiEndpoint":      terminal.EntityNameColor(config.ApiEndpoint()),
					"ApiVersionString": terminal.EntityNameColor(config.ApiVersion()),
				}),
		)
	}

	if !config.IsLoggedIn() {
		table.Print()
		ui.Say(terminal.NotLoggedInText())
		return
	} else {
		table.Add(
			T("User:"******"%s target -o ORG -s SPACE", cf.Name())
		ui.Say(T("No org or space targeted, use '{{.CFTargetCommand}}'",
			map[string]interface{}{
				"CFTargetCommand": terminal.CommandColor(command),
			}))
		return
	}

	if config.HasOrganization() {
		table.Add(
			T("Org:"),
			terminal.EntityNameColor(config.OrganizationFields().Name),
		)
	} else {
		command := fmt.Sprintf("%s target -o Org", cf.Name())
		table.Add(
			T("Org:"),
			T("No org targeted, use '{{.CFTargetCommand}}'",
				map[string]interface{}{
					"CFTargetCommand": terminal.CommandColor(command),
				}),
		)
	}

	if config.HasSpace() {
		table.Add(
			T("Space:"),
			terminal.EntityNameColor(config.SpaceFields().Name),
		)
	} else {
		command := fmt.Sprintf("%s target -s SPACE", cf.Name())
		table.Add(
			T("Space:"),
			T("No space targeted, use '{{.CFTargetCommand}}'", map[string]interface{}{"CFTargetCommand": terminal.CommandColor(command)}),
		)
	}

	table.Print()
}