subcmd

package
v0.0.0-...-f626111 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GlobalFlag option value
	GlobalFlag bool
	SaveDirenv bool
	DebugMode  bool
)
View Source
var ConfigCmd = &gcli.Command{
	Name:    "config",
	Desc:    "Manage xenv configuration",
	Aliases: []string{"cfg"},
	Subs: []*gcli.Command{
		ConfigSetCmd(),
		ConfigGetCmd(),
		ConfigExportCmd(),
		ConfigImportCmd(),
	},
	Config: func(c *gcli.Command) {

		c.BoolOpt(&configOpts.edit, "edit", "e", false, "Edit the configuration file in the default editor")
	},
	Func: func(c *gcli.Command, args []string) error {

		if err := config.Mgr.Init(); err != nil {
			return fmt.Errorf("failed to load configuration: %w", err)
		}
		cfg := config.Mgr.Config
		c.Infoln("Loading config file:", cfg.ConfigFile())

		managedSdkKey := fmt.Sprintf("4. Managed SDKs(%d)", len(cfg.SDKs))
		show.AList("【Current Xenv Configuration】:", map[string]any{
			"1. Default Bin Dir":  cfg.BinDir,
			"2. Tool Install Dir": cfg.InstallDir,
			"3. Shell Hooks Dir":  cfg.ShellHooksDir,
			managedSdkKey:         cfg.SDKNames(),
		})

		return nil
	},
}

ConfigCmd the xenv config command

View Source
var EnvCmd = &gcli.Command{
	Name: "env",
	Desc: "Manage environment variables",
	Subs: []*gcli.Command{
		EnvSetCmd(),
		EnvUnsetCmd(),
		EnvListCmd(),
	},
	Func: func(c *gcli.Command, args []string) error {
		return listEnvs()
	},
}

EnvCmd the xenv env command

View Source
var InitCmd = &gcli.Command{
	Name: "init",
	Desc: "Initialize xenv configuration and environment",
	Func: func(c *gcli.Command, args []string) error {

		if err := config.Mgr.Init(); err != nil {
			return fmt.Errorf("failed to load configuration: %w", err)
		}

		cfgMgr := config.Mgr
		cfg := config.Mgr.Config

		configPath := cfg.ConfigFile()

		configDir := filepath.Dir(configPath)
		if err := util.EnsureDir(configDir); err != nil {
			return fmt.Errorf("failed to create config directory: %w", err)
		}

		if _, err := os.Stat(configPath); err == nil {
			if err := cfgMgr.LoadConfig(configPath); err != nil {
				fmt.Printf("Warning: failed to load existing config: %v\n", err)
			}
		} else {

			if err := cfgMgr.SaveConfig(configPath); err != nil {
				return fmt.Errorf("failed to save default config: %w", err)
			}
			fmt.Printf("Created default configuration at: %s\n", configPath)
		}

		if err := util.EnsureDir(cfgMgr.Config.BinDir); err != nil {
			return fmt.Errorf("failed to create bin directory: %w", err)
		}

		if err := util.EnsureDir(cfgMgr.Config.InstallDir); err != nil {
			return fmt.Errorf("failed to create install directory: %w", err)
		}

		if err := util.EnsureDir(cfgMgr.Config.ShellHooksDir); err != nil {
			return fmt.Errorf("failed to create shell scripts directory: %w", err)
		}

		fmt.Println("Xenv initialization completed successfully!")
		fmt.Printf("Configuration file: %s\n", configPath)
		fmt.Printf("Bin directory: %s\n", cfgMgr.Config.BinDir)
		fmt.Printf("Install directory: %s\n", cfgMgr.Config.InstallDir)
		fmt.Printf("Shell scripts directory: %s\n", cfgMgr.Config.ShellHooksDir)

		return nil
	},
}

InitCmd the xenv init command

View Source
var ListCmd = &gcli.Command{
	Name:    "list",
	Desc:    "List installed tools, environment variables, or PATH entries",
	Aliases: []string{"ls"},
	Subs: []*gcli.Command{
		ListToolsCmd(),
		ListEnvCmd(),
		ListPathCmd(),
		ListActivityCmd(),
		ListAllCmd(),
	},
	Func: func(c *gcli.Command, args []string) error {

		return listTools()
	},
}

ListCmd the xenv list command

View Source
var PathCmd = &gcli.Command{
	Name: "path",
	Desc: "Manage PATH environment variable",
	Subs: []*gcli.Command{
		PathAddCmd(),
		PathRemoveCmd(),
		PathListCmd(),
		PathSearchCmd(),
	},
	Func: func(c *gcli.Command, args []string) error {
		return listEnvPaths()
	},
}

PathCmd the xenv path command

View Source
var ToolsCmd = &gcli.Command{
	Name:    "tools",
	Desc:    "Manage local development SDK, tools (install, list, etc.)",
	Aliases: []string{"t", "tool"},
	Subs: []*gcli.Command{
		ToolsInstallCmd(),
		ToolsUninstallCmd(),
		ToolsUpdateCmd(),
		ToolsShowCmd(),
		ToolsListCmd(),
		ToolsRegisterCmd(),
		ToolsIndexCmd(),
	},
	Config: func(c *gcli.Command) {

	},
}

ToolsCmd the xenv tools command

Functions

func ConfigExportCmd

func ConfigExportCmd() *gcli.Command

ConfigExportCmd command for exporting configuration

func ConfigGetCmd

func ConfigGetCmd() *gcli.Command

ConfigGetCmd command for getting configuration values

func ConfigImportCmd

func ConfigImportCmd() *gcli.Command

ConfigImportCmd command for importing configuration

func ConfigSetCmd

func ConfigSetCmd() *gcli.Command

ConfigSetCmd command for setting configuration values

func EnvListCmd

func EnvListCmd() *gcli.Command

EnvListCmd command for listing environment variables

func EnvSetCmd

func EnvSetCmd() *gcli.Command

EnvSetCmd command for setting environment variables

Test run:

// pwsh
$env:XENV_HOOK_SHELL="pwsh"; kite xenv set TEST003 value003

func EnvUnsetCmd

func EnvUnsetCmd() *gcli.Command

EnvUnsetCmd command for unsetting environment variables

func GetOpFlag

func GetOpFlag() models.OpFlag

GetOpFlag 根据参数获取操作标识

func ListActivityCmd

func ListActivityCmd() *gcli.Command

ListActivityCmd lists active tools and settings

func ListAllCmd

func ListAllCmd() *gcli.Command

ListAllCmd lists everything

func ListEnvCmd

func ListEnvCmd() *gcli.Command

ListEnvCmd lists environment variables

func ListPathCmd

func ListPathCmd() *gcli.Command

ListPathCmd lists PATH entries

func ListToolsCmd

func ListToolsCmd() *gcli.Command

ListToolsCmd lists tools (similar to the one in tools subcommand)

func NewShellCmd

func NewShellCmd() *gcli.Command

NewShellCmd the xenv shell command

func NewUnuseCmd

func NewUnuseCmd() *gcli.Command

NewUnuseCmd the xenv unuse command

func NewUseCmd

func NewUseCmd() *gcli.Command

NewUseCmd the xenv use command

func PathAddCmd

func PathAddCmd() *gcli.Command

PathAddCmd command for adding a path to PATH

func PathListCmd

func PathListCmd() *gcli.Command

PathListCmd command for listing PATH entries

func PathRemoveCmd

func PathRemoveCmd() *gcli.Command

PathRemoveCmd command for removing a path from PATH

func PathSearchCmd

func PathSearchCmd() *gcli.Command

PathSearchCmd command for searching PATH entries

func ShellDirenvCmd

func ShellDirenvCmd() *gcli.Command

ShellDirenvCmd the xenv init shell direnv command

  • 仅在配置了 xenv shell 命令时,cd 到新目录会自动调用当前命令
  • 监听进入目录时,自动检测 .xenv.toml 文件,并加载里面的配置

func ShellHookInitCmd

func ShellHookInitCmd() *gcli.Command

ShellHookInitCmd the xenv hook init command

  • 配置了 xenv shell 命令到 user 配置文件后,会自动执行该命令
  • 调用当前命令,可以返回脚本内容自动执行

func ToolsIndexCmd

func ToolsIndexCmd() *gcli.Command

ToolsIndexCmd command for 将本地的工具信息索引到 local.json

func ToolsInstallCmd

func ToolsInstallCmd() *gcli.Command

ToolsInstallCmd command for installing tools

func ToolsListCmd

func ToolsListCmd() *gcli.Command

ToolsListCmd command for listing tools

func ToolsRegisterCmd

func ToolsRegisterCmd() *gcli.Command

func ToolsShowCmd

func ToolsShowCmd() *gcli.Command

ToolsShowCmd command for showing tool info

func ToolsUninstallCmd

func ToolsUninstallCmd() *gcli.Command

ToolsUninstallCmd command for uninstalling tools

func ToolsUpdateCmd

func ToolsUpdateCmd() *gcli.Command

ToolsUpdateCmd command for updating tools

Types

This section is empty.

Jump to

Keyboard shortcuts

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