// CheckTarget confirms that the config has an API set and the user is logged // in. Optionally it will also check if an organization and space are targeted. func CheckTarget(config commands.Config, targetedOrganizationRequired bool, targetedSpaceRequired bool) error { if config.AccessToken() == "" && config.RefreshToken() == "" { return NotLoggedInError{ BinaryName: config.BinaryName(), } } if targetedOrganizationRequired { if config.TargetedOrganization().GUID == "" { return NoTargetedOrgError{ BinaryName: config.BinaryName(), } } if targetedSpaceRequired { if config.TargetedSpace().GUID == "" { return NoTargetedSpaceError{ BinaryName: config.BinaryName(), } } } } return nil }
func DisplayCurrentTargetInformation(config commands.Config, commandUI commands.UI) error { user, err := config.CurrentUser() if err != nil { return err } commandUI.DisplayPair("API endpoint", config.Target()) commandUI.DisplayPair("API version", config.APIVersion()) commandUI.DisplayPair("User", user.Name) commandUI.DisplayPair("Org", config.TargetedOrganization().Name) commandUI.DisplayPair("Space", config.TargetedSpace().Name) return nil }