config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultConfig

func CreateDefaultConfig(path string) (err error)

Creates a default config file based on the contents of `defaultconfig.go` located at `path`. Can return an error.

func FindExecutablePath

func FindExecutablePath(executableName string, toolPlatform []string) (path string, ok bool)

Searches for an executable with the `executableName` that supports `toolPlatform` in the user's PATH. If the executable wasn't found, this falls back into searching the directory compacty is running in.

Returns the path of the executable and `true` if the executable is found. If not, this returns an empty string and `false`.

func GetDefaultConfigStr

func GetDefaultConfigStr() string

func GetOrCreateUserConfigFile

func GetOrCreateUserConfigFile() (path string, isCreated bool, err error)

Retrives the user config file located at `os.UserConfigDir()`. If the file does not exist, this creates a default config file based on the contents of `defaultconfig.go`.

Returns the path of the config file, a bool indicating if the file is created (`true` if it is, `false` otherwise) and an error if one occurs.

func QueryPreset

func QueryPreset(presets map[string]Preset, name string) (preset string, isShorthand bool)

Searches the matching preset at `name` at the `presets` list that can contain the preset's full names and shorthands. Returns the preset's full name and a boolean `true` if `name` is a shorthand to a preset, `false` otherwise. If the matching preset is not found, returns an empty string and `false`. Meant to resolve shorthands.

func QueryWrapper

func QueryWrapper(wrappers map[string]string, toolPlatform []string, currentPlatform string) (wrapper string)

Searches the matching wrapper for `currentPlatform` at the `wrappers` list. If no such wrapper exists for `currentPlatform` or `toolPlatform` does not contain `currentPlatform`, returns an empty string instead.

Types

type CompressionTool

type CompressionTool struct {
	Command          string     `yaml:"command"`
	SupportedFormats []string   `yaml:"supported-formats"`
	Platform         []string   `yaml:"platform"`
	OutputMode       OutputMode `yaml:"output-mode"`
}

func (*CompressionTool) CanBatchCompress

func (ct *CompressionTool) CanBatchCompress() bool

Returns `true` if the tool can compress multiple files at once. Returns `false` otherwise.

func (*CompressionTool) Overwrites

func (ct *CompressionTool) Overwrites() bool

Returns `true` if the tool overwrites files in-place. Returns `false` otherwise.

type Config

type Config struct {
	DefaultPreset string `yaml:"default-preset"`

	MimeExtensions map[string][]string `yaml:"mime-extensions"`

	Wrappers map[string]map[string]string `yaml:"wrappers"`
	Presets  map[string]Preset            `yaml:"presets"`
	Tools    map[string]*ToolConfig       `yaml:"tools"`
	// contains filtered or unexported fields
}

func DecodeConfigFile

func DecodeConfigFile(path string) (cfg *Config, err error)

Decodes the config file at `path` and returns a Config object. Can also returns an error.

func (*Config) Cache

func (cfg *Config) Cache()

Caches supported file formats and tool availability.

func (*Config) GetSupportedFileExtensions

func (cfg *Config) GetSupportedFileExtensions() (fileExtMap map[string][]string)

Returns all the file extensions that could be compressed. Includes the file formats defined in mime-extensionsmand file formats that the config's tools could compress.

func (*Config) GetSupportedFileFormats

func (cfg *Config) GetSupportedFileFormats() (fileFormatsMime []string)

Returns all the file formats that could be compressed. Includes the file formats defined in mime-extensions and file formats that the config's tools could compress.

func (*Config) GetToolConfigFromNames

func (cfg *Config) GetToolConfigFromNames(toolNames []string) (toolCfgMap map[string]*ToolConfig)

Returns a map of tools from `toolNames`.

func (*Config) HasAvailableTools

func (cfg *Config) HasAvailableTools() bool

Returns `true` if the current config has at least one tool available to be run on the user's OS. Returns `false` otherwise.

func (*Config) IsToolAvailable

func (cfg *Config) IsToolAvailable(toolName string) bool

Returns `true` if the tool with the given `toolName` is available to be run at the current platform. Returns `false` otherwise.

func (*Config) QueryToolWrapper

func (cfg *Config) QueryToolWrapper(tool *ToolConfig, platform string) string

Searches the matching wrapper for `tool` while running at `platform`. If no such wrapper exists for `platform` or `tool` does not support `platform`, returns an empty string instead.

func (*Config) Validate

func (cfg *Config) Validate() []error

Checks the config for any errors and inconsistencies. Returns a slice of errors in the config.

type OutputMode

type OutputMode int
const (
	Unknown OutputMode = iota
	BatchOverwrite
	InputOutput
	Stdout
)

func (OutputMode) MarshalYAML

func (o OutputMode) MarshalYAML() (any, error)

func (*OutputMode) UnmarshalYAML

func (o *OutputMode) UnmarshalYAML(value *yaml.Node) error

type Preset

type Preset struct {
	Description string   `yaml:"description"`
	Shorthands  []string `yaml:"shorthands"`

	DefaultTools map[string][]string `yaml:"default-tools"`
}

type ToolConfig

type ToolConfig struct {
	CompressionTool `yaml:",inline"`
	Description     string              `yaml:"description"`
	Arguments       map[string][]string `yaml:"arguments"`
}

Jump to

Keyboard shortcuts

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