core

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandPath added in v0.16.0

func ExpandPath(path string) string

ExpandPath expands environment variables and tilde in a path. - Environment variables: $VAR or %VAR% (cross-platform via os.ExpandEnv) - Tilde: ~ expands to user's home directory

func GetConfigFilePath added in v0.16.0

func GetConfigFilePath() string

GetConfigFilePath returns the path to the config file. If viper has a config file set, returns that. Otherwise returns default path.

func InitConfig added in v0.15.0

func InitConfig(configFile string) error

InitConfig initializes the global configuration. If the config file is not found, Cfg is initialized with defaults and ErrConfigNotFound is returned. The caller can check for this error type to decide whether to proceed without a config file.

func IsPathSafe added in v0.16.0

func IsPathSafe(basePath, targetPath string) bool

IsPathSafe checks if targetPath is safely contained within basePath. This prevents Zip Slip vulnerabilities by ensuring the target doesn't escape the base directory via ../ or similar path traversal.

func IsUnderGitRepo added in v0.16.0

func IsUnderGitRepo(path string) bool

IsUnderGitRepo checks if the given path is inside a git repository by traversing parent directories looking for .git directory.

func ResolveCacheDir added in v0.16.0

func ResolveCacheDir() string

ResolveCacheDir resolves the cache directory using fallback chain: 1. XDG_CACHE_HOME environment variable (all platforms) 2. Windows LOCALAPPDATA\cache (Windows only, when XDG not set) 3. Default XDG path (~/.cache)

func ResolveConfigDir added in v0.16.0

func ResolveConfigDir() string

ResolveConfigDir resolves the configuration directory using fallback chain: 1. XDG_CONFIG_HOME environment variable (all platforms) 2. Windows APPDATA (Windows only, when XDG not set) 3. Default XDG path (~/.config)

func ResolveDataDir added in v0.16.0

func ResolveDataDir() string

ResolveDataDir resolves the data directory using fallback chain: 1. XDG_DATA_HOME environment variable (all platforms) 2. Windows LOCALAPPDATA (Windows only, when XDG not set) 3. Default XDG path (~/.local/share)

func ResolvePath added in v0.16.0

func ResolvePath(path, baseDir string) string

ResolvePath resolves a path that may be relative to a base directory. - Absolute paths are returned as-is (after expansion) - Relative paths are resolved relative to baseDir - Environment variables and tilde are expanded first

func SafeOpen added in v0.16.0

func SafeOpen(basePath, filePath string) (*os.File, error)

SafeOpen opens a file after validating the path is within the allowed base directory. Returns an error if the path escapes the base directory.

func SafeOpenFile added in v0.16.0

func SafeOpenFile(basePath, filePath string, flag int, perm os.FileMode) (*os.File, error)

SafeOpenFile opens a file with flags after validating the path. Returns an error if the path escapes the base directory.

Types

type Config

type Config struct {
	LastUpdateCheckTimestamp time.Time     `mapstructure:"last_update_check_timestamp"`
	LastFormatTimestamp      time.Time     `mapstructure:"last_format_timestamp"`
	Project                  ConfigProject `mapstructure:"project"`
	Paths                    ConfigPaths   `mapstructure:"path"`
	// contains filtered or unexported fields
}
var Cfg *Config

func (*Config) GetCacheDir

func (c *Config) GetCacheDir() string

func (*Config) GetConfigDir

func (c *Config) GetConfigDir() string

func (*Config) GetDataDir

func (c *Config) GetDataDir() string

func (*Config) LoadConfig

func (c *Config) LoadConfig(filePath string) error

func (*Config) ResetLastUpdateCheckTimestamp added in v0.10.1

func (c *Config) ResetLastUpdateCheckTimestamp()

func (*Config) SaveConfig added in v0.10.0

func (c *Config) SaveConfig() error

type ConfigPaths added in v0.16.0

type ConfigPaths struct {
	DataDir  string `mapstructure:"data_dir"`
	CacheDir string `mapstructure:"cache_dir"`
}

type ConfigProject added in v0.14.0

type ConfigProject struct {
	Url           string `mapstructure:"url"`
	DriveFolderId string `mapstructure:"drive_folder_id"`
	SiteUrl       string `mapstructure:"site_url"`
	Branch        string `mapstructure:"branch"`
	TemplatePath  string `mapstructure:"template_path"`
	AssetPath     string `mapstructure:"asset_path"`
}

type Controller added in v0.3.2

type Controller interface {
	Exec(cmd *cobra.Command, args []string) (err error)
}

type ErrConfigNotFound added in v0.16.0

type ErrConfigNotFound struct {
	Path string
}

ErrConfigNotFound is returned when the configuration file does not exist. This indicates the user should run 'nippo init' first.

func (*ErrConfigNotFound) Error added in v0.16.0

func (e *ErrConfigNotFound) Error() string

type RunEFunc added in v0.3.2

type RunEFunc func(cmd *cobra.Command, args []string) (err error)

type TestEnv added in v0.16.1

type TestEnv struct {
	TmpDir    string
	ConfigDir string
	DataDir   string
	CacheDir  string
	// contains filtered or unexported fields
}

TestEnv holds the test environment configuration

func SetupTestEnv added in v0.16.1

func SetupTestEnv(t *testing.T) *TestEnv

SetupTestEnv creates an isolated test environment that prevents tests from reading or writing to the user's actual config files. It returns a TestEnv with paths to temporary directories and a cleanup function.

Usage:

func TestSomething(t *testing.T) {
    env := core.SetupTestEnv(t)
    defer env.Cleanup()
    // ... test code ...
}

func (*TestEnv) Cleanup added in v0.16.1

func (e *TestEnv) Cleanup()

Cleanup removes the temporary test environment. This should be called with defer after SetupTestEnv.

func (*TestEnv) CreateConfigFile added in v0.16.1

func (e *TestEnv) CreateConfigFile(t *testing.T, content string) string

CreateConfigFile creates a test config file with the given content.

func (*TestEnv) CreateCredentialsFile added in v0.16.1

func (e *TestEnv) CreateCredentialsFile(t *testing.T, content string) string

CreateCredentialsFile creates a test credentials.json file.

func (*TestEnv) CreateTokenFile added in v0.16.1

func (e *TestEnv) CreateTokenFile(t *testing.T, content string) string

CreateTokenFile creates a test token.json file.

type UseCase added in v0.14.4

type UseCase interface{}

type ViewModel added in v0.14.0

type ViewModel interface{}

Jump to

Keyboard shortcuts

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