Documentation
¶
Overview ¶
Package profile provides named profile management for CLI tools.
A profile bundles a base URL with optional app-specific settings, letting users and agents target different environments or accounts with --profile or APP_PROFILE without env var juggling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CredentialKey ¶
CredentialKey returns the credential store key for a profile. With a profile: "profile:<name>". Without: the base URL.
func Resolve ¶
func Resolve(opts ResolveOptions) (string, error)
Resolve determines the active profile using strict precedence:
- --profile flag
- APP_PROFILE env var
- default_profile in config
- Auto-select if exactly one profile exists
- Interactive picker (if available)
- Error
Returns ("", nil) when no profiles are configured (profile-less mode).
func ValidateName ¶
ValidateName checks that a profile name is well-formed.
Types ¶
type Profile ¶
type Profile struct {
Name string `json:"-"`
BaseURL string `json:"base_url"`
Extra map[string]json.RawMessage `json:"extra,omitempty"`
}
Profile is a named environment configuration.
type ResolveOptions ¶
type ResolveOptions struct {
// FlagValue is the --profile flag value (highest priority).
FlagValue string
// EnvVar is the environment variable value (e.g., APP_PROFILE).
EnvVar string
// DefaultProfile is the default_profile from config.
DefaultProfile string
// Profiles is the set of known profiles.
Profiles map[string]*Profile
// Interactive is true when the user can be prompted (TTY, no --agent/--json).
// When true and multiple profiles exist with no selection, Picker is called.
Interactive bool
// Picker prompts the user to choose a profile. Only called when
// Interactive is true and multiple profiles exist with no other selection.
// Returns the chosen profile name. If nil, resolution fails instead of prompting.
Picker func(names []string) (string, error)
}
ResolveOptions controls how profile resolution behaves.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages named profiles in a JSON config file.
func NewStore ¶
NewStore creates a profile store backed by configPath (e.g., ~/.config/myapp/config.json). The file and parent directory are created on first write.
func (*Store) Delete ¶
Delete removes a profile by name. Clears default_profile if it pointed to the deleted profile.
func (*Store) SetDefault ¶
SetDefault sets the default profile.