Documentation
¶
Index ¶
- Constants
- func CreateDefaultConfig(path string) (err error)
- func FindExecutablePath(executableName string, toolPlatform []string) (path string, ok bool)
- func GetDefaultConfigStr() string
- func GetOrCreateUserConfigFile() (path string, isCreated bool, err error)
- func QueryPreset(presets map[string]Preset, name string) (preset string, isShorthand bool)
- func QueryWrapper(wrappers map[string]string, toolPlatform []string, currentPlatform string) (wrapper string)
- type CompressionTool
- type Config
- func (cfg *Config) Cache()
- func (cfg *Config) GetSupportedFileExtensions() (fileExtMap map[string][]string)
- func (cfg *Config) GetSupportedFileFormats() (fileFormatsMime []string)
- func (cfg *Config) GetToolConfigFromNames(toolNames []string) (toolCfgMap map[string]*ToolConfig)
- func (cfg *Config) HasAvailableTools() bool
- func (cfg *Config) IsToolAvailable(toolName string) bool
- func (cfg *Config) QueryToolWrapper(tool *ToolConfig, platform string) string
- func (cfg *Config) Validate() []error
- type OutputMode
- type Preset
- type ToolConfig
Constants ¶
const IncludePrefix = "@"
Variables ¶
This section is empty.
Functions ¶
func CreateDefaultConfig ¶
Creates a default config file based on the contents of `defaultconfig.go` located at `path`. Can return an error.
func FindExecutablePath ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ToolConfig ¶
type ToolConfig struct {
CompressionTool `yaml:",inline"`
Description string `yaml:"description"`
Arguments map[string][]string `yaml:"arguments"`
}
func (*ToolConfig) ResolveIncludesForPreset ¶ added in v1.1.0
func (t *ToolConfig) ResolveIncludesForPreset(presetName, toolNameAs string) (args []string, errs []error)
Resolves preset includes starting at `presetName`. `toolNameAs` is what's being used as the tool's name for debugging purposes.
Returns the resolved argument list. Can also return an error (cyclic includes, includes pointing to non existing presets)