environment

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const KmdoExportedLayout = "2006-01-02 15:04:05"
View Source
const (
	KmdoHomeEnvKey = "KMDO_HOME"
)

Variables

View Source
var (
	BuildTag   string
	BuildGitID string
)
View Source
var BashTpl = `` /* 2200-byte string literal not displayed */
View Source
var KmdoEnv = KmdoEnvironment{
	HomePath:       "",
	LoginConfig:    "",
	BinPath:        "",
	SharedPath:     "",
	CurrentExecute: "",
	RootEnvPath:    "",
	EnvPath:        "",
	EtcPath:        "",
	KmEnv:          nil,
	DefaultEnv:     nil,
	Exported:       false,
	Modules:        make([]KmdoModule, 0),
}

KmdoEnv is the global environment instance

View Source
var KmdoExportedKey = "KMDO_EXPORTED"

Functions

func ForceReinitEnv

func ForceReinitEnv() error

func GenerateShellWithTemplate

func GenerateShellWithTemplate(configs []EnvNsConfig, outputPath string, templateStr, externalTemplatePath string) error

GenerateShellWithTemplate generates Shell script from template (external file > template string) Core Design: Does NOT care about template source (built-in/user-defined), only processes content Parameters:

configs: Original configuration data slice (env namespaces and their configs)
outputPath: Path to save the generated Shell script (required, cannot be empty)
templateStr: Template content string (used when externalTemplatePath is empty; can be built-in/user-defined)
externalTemplatePath: External template file path (optional; takes priority if provided)

Returns:

error: Error occurred during generation (validation/parsing/rendering/file operation)

func GenerateTemplate

func GenerateTemplate(filePath string) error

GenerateTemplate creates a default config template file

func InitEnv

func InitEnv() error

InitEnv initializes the complete application environment

func KmdoDefaultConfigPath

func KmdoDefaultConfigPath() string

func KmdoEnvConfigPath

func KmdoEnvConfigPath() string

Types

type EnvConfig

type EnvConfig struct {
	Type  string `json:"type"`  // EnvNsConfig type: "env" or "script"
	ID    int    `json:"id"`    // Unique identifier (note: original JSON has duplicate ID=2, code allows but warns)
	Key   string `json:"key"`   // Environment variable or script key
	Value string `json:"value"` // Corresponding value/path
	Hide  bool   `json:"hide"`  // Whether to hide the config in display
	Desc  string `json:"desc"`  // Description of the config
}

EnvConfig defines the structure of individual environment/script configuration Corresponding to the "envs" field items in JSON

type EnvNsConfig

type EnvNsConfig struct {
	Namespace string               `json:"namespace"` // Project namespace
	Envs      map[string]EnvConfig `json:"envs"`      // Key-value map of environment/script configs
	Exports   []string             `json:"exports"`   // List of config keys to export
}

EnvNsConfig defines the top-level configuration structure Matches the root JSON structure

func GenerateKmdoEnv

func GenerateKmdoEnv() *EnvNsConfig

func LoadEnvNsConfig

func LoadEnvNsConfig(filePath string) (*EnvNsConfig, error)

LoadConfig reads JSON config from file and parses into EnvNsConfig struct Parameters:

filePath: Path to the config JSON file

Returns:

*EnvNsConfig: Parsed config instance
error: Error if file read or JSON parse fails

func NewConfig

func NewConfig() *EnvNsConfig

NewConfig creates a new empty EnvNsConfig instance

func (*EnvNsConfig) GetEnvConfig

func (c *EnvNsConfig) GetEnvConfig(key string) (EnvConfig, bool)

GetEnvConfig retrieves an EnvConfig by its key in the Envs map Parameters:

key: The key of the EnvConfig to retrieve (e.g., "project_path2")

Returns:

EnvConfig: The retrieved EnvConfig
bool: True if key exists, false otherwise

func (*EnvNsConfig) SaveConfig

func (c *EnvNsConfig) SaveConfig(filePath string) error

SaveConfig writes the current EnvNsConfig struct to a JSON file Parameters:

filePath: Path to save the config file

Returns:

error: Error if directory creation or file write fails

func (*EnvNsConfig) Validate

func (c *EnvNsConfig) Validate() error

Validate checks if the config has valid structure Returns error if required fields are missing or invalid

type KmdoEnvironment

type KmdoEnvironment struct {
	HomePath       string // Main application directory
	LoginConfig    string // Configuration file path
	BinPath        string // Binary/executable directory
	SharedPath     string // Shared data directory
	CurrentExecute string // Path to current executable
	RootEnvPath    string // kmdo.env path
	EnvPath        string // env config path
	EtcPath        string // env config path
	KmEnv          *EnvNsConfig
	DefaultEnv     *EnvNsConfig
	Exported       bool
	Modules        []KmdoModule
}

KmdoEnvironment defines the directory structure for the application

type KmdoModule

type KmdoModule struct {
	Name        string
	Description string
	Initer      func() error
}

type TemplateData

type TemplateData struct {
	Configs []TemplateNsConfig `json:"configs"`
}

TemplateData is the top-level data structure passed to the Go template

type TemplateEnvConfig

type TemplateEnvConfig struct {
	EnvConfig
	EscapedValue string // Pre-escaped value (handles Shell special characters)
}

TemplateEnvConfig is the adapted structure for template rendering Includes original EnvConfig and pre-escaped value for Shell compatibility

type TemplateNsConfig

type TemplateNsConfig struct {
	Namespace string                       `json:"namespace"`
	Envs      map[string]TemplateEnvConfig `json:"envs"`
	Exports   []string                     `json:"exports"`
}

TemplateNsConfig is the namespace-level adapted structure for template rendering

Jump to

Keyboard shortcuts

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