Documentation
¶
Index ¶
- Constants
- func FlagFragmentIfNotActive(profileName string) string
- func NewConfigCmd() *cobra.Command
- func OAuthAuthenticateHint(profileName string) string
- func ProfileDisplayName(profileName string) string
- func ProfileFlagFragment(profileName string) string
- func ResolveConfigurationForProfile(profileName string) (*profiles.Configuration, error)
- func WithProfileSelector(ctx context.Context, sel ProfileSelector) context.Context
- type ProfileSelector
- type ProfileSource
Constants ¶
const EnvProfile = "DASH0_PROFILE"
EnvProfile is the environment variable that selects a named profile for the current invocation, overriding the active profile recorded on disk.
Variables ¶
This section is empty.
Functions ¶
func FlagFragmentIfNotActive ¶ added in v1.14.0
FlagFragmentIfNotActive returns " --profile X" when X is non-empty AND X is NOT the currently active profile (per ~/.dash0/profiles.json). It returns "" otherwise, including when X is empty. Use this in follow-up hints emitted by commands like `profiles create` and `config show` where the hint text might point at a profile that is already (or just became) active, in which case `--profile X` is redundant.
Lookup errors bias toward eliding the fragment — better to print an ambiguous short hint than a confidently-wrong long one.
func OAuthAuthenticateHint ¶ added in v1.14.0
OAuthAuthenticateHint returns the follow-up hint printed after marking a profile as OAuth via `profiles create --oauth` or `profiles update --oauth`. In human mode it points at `dash0 login`. In agent mode it points at the escape hatches that an agent can actually execute (`DASH0_AUTH_TOKEN` or `profiles update --oauth=false --auth-token ... --force`), because `dash0 login` itself refuses to run in agent mode.
func ProfileDisplayName ¶ added in v1.14.0
ProfileDisplayName turns a profile-scoping hint into a noun phrase for error messages and prompts. Pass "" when the operation is implicitly acting on the active profile (no --profile was passed) to get "the active profile"; pass the actual profile name when the user is addressing a profile explicitly.
ProfileDisplayName("") // "the active profile"
ProfileDisplayName("prod") // `profile "prod"`
The helper deliberately does not consult the on-disk active profile — the caller knows whether --profile was passed and is the right place to make that choice.
func ProfileFlagFragment ¶ added in v1.14.0
ProfileFlagFragment returns the " --profile X" fragment to splice into a command hint like `dash0 login`. Pass "" when the hint should NOT mention a profile (because the user did not pass --profile); pass the actual profile name to splice it in.
fmt.Sprintf("Run `dash0 login%s`.", ProfileFlagFragment("")) // Run `dash0 login`.
fmt.Sprintf("Run `dash0 login%s`.", ProfileFlagFragment("prod")) // Run `dash0 login --profile prod`.
Like ProfileDisplayName, this helper trusts the caller's choice and does not consult the on-disk active profile.
func ResolveConfigurationForProfile ¶ added in v1.11.0
func ResolveConfigurationForProfile(profileName string) (*profiles.Configuration, error)
ResolveConfigurationForProfile loads the named profile from the store and applies environment variable overrides on top. It returns a "profile not found" error that lists the available profiles when no profile with the given name exists. When profileName is empty, callers should use the normal active-profile resolution chain; this function only handles explicit selections.
func WithProfileSelector ¶ added in v1.11.0
func WithProfileSelector(ctx context.Context, sel ProfileSelector) context.Context
WithProfileSelector returns a new context carrying the given selector.
Types ¶
type ProfileSelector ¶ added in v1.11.0
type ProfileSelector struct {
// Name is the explicit profile name. An empty string means the selector
// is absent and callers should use the active profile.
Name string
// Source identifies where the Name came from.
Source ProfileSource
}
ProfileSelector records an explicit profile selection and its source.
func ProfileSelectorFromContext ¶ added in v1.11.0
func ProfileSelectorFromContext(ctx context.Context) ProfileSelector
ProfileSelectorFromContext returns the selector stored in ctx, or an empty selector if none is present.
func ResolveProfileSelector ¶ added in v1.11.0
func ResolveProfileSelector(flagValue string) ProfileSelector
ResolveProfileSelector returns the explicit profile selector derived from the --profile flag value and the DASH0_PROFILE environment variable. Empty strings are treated as "not set" and fall through to the next precedence step, which means the caller should use the active profile.
func (ProfileSelector) IsSet ¶ added in v1.11.0
func (s ProfileSelector) IsSet() bool
IsSet reports whether the selector has a non-empty explicit name.
type ProfileSource ¶ added in v1.11.0
type ProfileSource int
ProfileSource identifies where an explicit profile selection came from.
const ( // ProfileSourceNone indicates no explicit selection (the active profile is used). ProfileSourceNone ProfileSource = iota // ProfileSourceFlag indicates the selection came from the --profile flag. ProfileSourceFlag // ProfileSourceEnv indicates the selection came from the DASH0_PROFILE env var. ProfileSourceEnv )
func (ProfileSource) Description ¶ added in v1.11.0
func (s ProfileSource) Description() string
Description returns a human-readable source description suitable for displaying in `config show` alongside a profile name.