profile

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 7 Imported by: 0

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

func CredentialKey(profileName, baseURL string) string

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:

  1. --profile flag
  2. APP_PROFILE env var
  3. default_profile in config
  4. Auto-select if exactly one profile exists
  5. Interactive picker (if available)
  6. Error

Returns ("", nil) when no profiles are configured (profile-less mode).

func ValidateName

func ValidateName(name string) error

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

func NewStore(configPath string) *Store

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) Create

func (s *Store) Create(p *Profile) error

Create adds a new profile. Returns an error if it already exists.

func (*Store) Delete

func (s *Store) Delete(name string) error

Delete removes a profile by name. Clears default_profile if it pointed to the deleted profile.

func (*Store) Get

func (s *Store) Get(name string) (*Profile, error)

Get returns a single profile by name.

func (*Store) List

func (s *Store) List() (map[string]*Profile, string, error)

List returns all profiles and the default profile name.

func (*Store) SetDefault

func (s *Store) SetDefault(name string) error

SetDefault sets the default profile.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL