config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config provides configuration management for the CLI.

Package config provides configuration management for the CLI.

Package config provides configuration management for the CLI.

Package config provides configuration management for the CLI.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidURL is returned when the URL is invalid.
	ErrInvalidURL = apperrors.NewValidation("invalid URL",
		apperrors.WithHint("URL must start with http:// or https://"))
	// ErrInvalidAPIKey is returned when the API key is invalid.
	ErrInvalidAPIKey = apperrors.NewValidation("invalid API key",
		apperrors.WithHint("API key must be at least 10 characters"))
	// ErrInstanceNotFound is returned when the instance is not found.
	ErrInstanceNotFound = apperrors.NewValidation("instance not found",
		apperrors.WithHint("check available instances with 'redmine config list'"))
	// ErrAPIKeyNotFound is returned when the API key is not found in keyring.
	ErrAPIKeyNotFound = apperrors.NewValidation("API key not found in keyring",
		apperrors.WithHint("run 'redmine login' to store your API key"))
)

Functions

func Dir

func Dir() string

Dir returns the configuration directory.

func Path

func Path() string

Path returns the configuration file path.

func ValidateAPIKey

func ValidateAPIKey(key string) error

ValidateAPIKey validates the given API key.

func ValidateInstance

func ValidateInstance(inst Instance, apiKeyFromKeyring bool) error

ValidateInstance validates the given instance configuration. If the API key is stored in a keyring (apiKeyFromKeyring=true), the API key check is skipped since the key is not in the Instance struct.

func ValidateURL

func ValidateURL(raw string) error

ValidateURL validates the given URL.

Types

type Config

type Config struct {
	Default   string              `yaml:"default"`
	Instances map[string]Instance `yaml:"instances"`
	Settings  Settings            `yaml:"settings"`
	Git       GitConfig           `yaml:"git"`
	Report    ReportConfig        `yaml:"report"`
}

Config holds the CLI configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

func (*Config) CurrentInstance

func (c *Config) CurrentInstance() (*Instance, bool)

CurrentInstance returns the current default instance.

func (*Config) GetInstance

func (c *Config) GetInstance(name string) (*Instance, bool)

GetInstance returns an instance by name.

type GitConfig

type GitConfig struct {
	AutoLink       bool   `yaml:"auto_link"`
	CommitPattern  string `yaml:"commit_pattern"`
	DefaultProject int    `yaml:"default_project"`
}

GitConfig holds Git integration settings.

type Instance

type Instance struct {
	Name   string `yaml:"-"`
	URL    string `yaml:"url"`
	APIKey string `yaml:"api_key"`
}

Instance represents a Redmine instance configuration.

type Keyring

type Keyring interface {
	// Get 从密钥环获取 API Key
	Get(instanceName string) (string, error)
	// Set 将 API Key 存储到密钥环
	Set(instanceName, apiKey string) error
	// Delete 从密钥环删除 API Key
	Delete(instanceName string) error
	// IsAvailable 检查密钥环是否可用
	IsAvailable() bool
}

Keyring 定义密钥环接口

func NewKeyring

func NewKeyring() Keyring

NewKeyring 创建密钥环实例 如果系统密钥环不可用,则降级到内存存储

type ReportConfig

type ReportConfig struct {
	TemplatesDir  string `yaml:"templates_dir"`
	DefaultFormat string `yaml:"default_format"`
}

ReportConfig holds report generation settings.

type Settings

type Settings struct {
	Timeout      time.Duration `yaml:"timeout"`
	Retries      int           `yaml:"retries"`
	OutputFormat string        `yaml:"output_format"`
	PageSize     int           `yaml:"page_size"`
}

Settings holds general CLI settings.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store handles configuration persistence.

func NewStore

func NewStore(configDir string) *Store

NewStore creates a new config store.

func NewStoreWithKeyring

func NewStoreWithKeyring(configDir string, kr Keyring) *Store

NewStoreWithKeyring creates a new config store with a specific keyring.

func (*Store) DeleteInstance

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

DeleteInstance deletes an instance from the configuration and keyring.

func (*Store) Load

func (s *Store) Load() (*Config, error)

Load loads the configuration from disk. If a keyring is available, API keys are resolved from the keyring instead of the YAML file (which stores them only as a fallback).

func (*Store) Save

func (s *Store) Save(cfg *Config) error

Save saves the configuration to disk.

func (*Store) SaveInstance

func (s *Store) SaveInstance(name string, inst Instance) error

SaveInstance saves an instance to the configuration. If the keyring is available, the API key is stored securely in the keyring and the YAML file only contains an empty api_key field.

func (*Store) SetDefault

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

SetDefault sets the default instance.

Jump to

Keyboard shortcuts

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