config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config 提供 forge 的本地配置读写(例如默认 root 目录)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppConfigDir

func AppConfigDir() (string, error)

func AppName

func AppName() string

func BaseConfigDir

func BaseConfigDir() (string, error)

BaseConfigDir 返回配置根目录(不含应用子目录)。

优先级: 1) FORGE_CONFIG_DIR 2) XDG_CONFIG_HOME 3) ~/.config

func ConfigPath

func ConfigPath() (string, error)

func Save

func Save(cfg Config) (string, error)

Save 写入配置文件(会自动创建目录)。 如果 Commands 为空,会自动填充默认命令列表,确保用户首次使用时即可看到并编辑。

func SaveRoot

func SaveRoot(root string) (string, error)

SaveRoot 在尽量保留现有配置(例如 Commands)的前提下,仅更新 root 并写入配置文件。

说明: - 如果配置文件不存在:会创建新配置文件(只写入 root)。 - 如果配置文件损坏/无法解析:会以 root 为准覆盖写入,避免用户被卡住无法修复。

Types

type CommandConfig

type CommandConfig struct {
	Name    string   `json:"name"`    // TUI 中显示的名称
	Command string   `json:"command"` // 可执行文件名(需在 $PATH 中)
	Args    []string `json:"args"`    // 传给命令的参数列表
}

CommandConfig 描述一个可执行的启动命令。

func DefaultCommands

func DefaultCommands() []CommandConfig

DefaultCommands 返回内置默认命令列表。

type Config

type Config struct {
	Root     string          `json:"root"`
	Commands []CommandConfig `json:"commands,omitempty"`
	Projects []ProjectConfig `json:"projects,omitempty"`
}

func Load

func Load() (cfg Config, exists bool, err error)

Load 读取配置文件。 exists=false 表示配置文件不存在(不算错误)。

func (Config) GetCommands

func (c Config) GetCommands() []CommandConfig

GetCommands 返回配置中的命令列表;如果用户未自定义则返回默认值。

func (Config) GetProjects

func (c Config) GetProjects() []ProjectConfig

GetProjects 返回配置中的项目书签列表。

type ProjectConfig

type ProjectConfig struct {
	Name string `json:"name"` // 显示名称(如 "my-blog")
	Path string `json:"path"` // 项目路径(如 "~/Projects/my-blog")
}

ProjectConfig 描述一个项目书签,用于快速跳转。

Jump to

Keyboard shortcuts

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