config

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config defines the structure of zedpm configuration and defines the functions for leading that configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoalAndTaskNames

func GoalAndTaskNames(taskPath string) (string, []string)

GoalAndTaskNames splits a string of the form /goal/task/subtask and returns it as "goal" and []string{"task", "subtask"}.

Types

type Config

type Config struct {
	// Properties are the global properties that are used as the value if not
	// overridden by any other configuration section.
	Properties storage.KV

	// Goals is the configuration to apply to each goal.
	Goals []GoalConfig

	// Plugins is the configuration to apply to each plugin.
	Plugins []PluginConfig
}

Config is the master configuration as we use it in the application. The configuration format is in HCL. The actual HCL definition are with the Raw* structures, which are converted into these structures to handle the conversion of generic JSON-style objects used for Properties into storage.KV objects as working with JSON-style objects in HCL is ugly without some conversion like this.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is the ultimate fallback configuration, used when no other configuration can be found.

func Load

func Load(filename string, in io.Reader) (*Config, error)

Load will load the HCL configuration from the given io.Reader, using the given filename as the one passed to the HCL library, which it uses to help generate useful error messages.

func LocateAndLoad

func LocateAndLoad() (*Config, error)

LocateAndLoad will attempt to load the configuration from the project directory. If that fails, it will look for a global home directory configuration. If that fails, it will fall back onto the ultimate default configuration.

func LocateAndLoadHome

func LocateAndLoadHome() (*Config, error)

LocateAndLoadHome will load the user-global configuration file from

~/.zedpm.conf

This file is only used for goals outside of an existing project (such as init).

func LocateAndLoadProject

func LocateAndLoadProject() (*Config, error)

LocateAndLoadProject will load the local project configuration file. This file is loaded from the current working directory if possible. If not, this function will try to find the file in one of the next three folders outside the current directory and will stop if it appears to encounter a project root, which is detected by looking for a .git directory or go.mod file.

func (*Config) GetGoal

func (c *Config) GetGoal(goalName string) *GoalConfig

GetGoal returns the GoalConfig for the given goal name.

func (*Config) GetGoalAndTasks

func (c *Config) GetGoalAndTasks(taskPath string) (*GoalConfig, []*TaskConfig)

GetGoalAndTasks returns the goal and configuration of applicable sub-tasks for the given task path.

func (*Config) GetGoalFromPath

func (c *Config) GetGoalFromPath(taskPath string) *GoalConfig

GetGoalFromPath returns the goal configuration for the given task path.

func (*Config) GetPlugin

func (c *Config) GetPlugin(pluginName string) *PluginConfig

GetPlugin returns the PluginConfig for the given plugin name.

func (*Config) ToKV

func (c *Config) ToKV(
	properties storage.KV,
	taskPath,
	targetName,
	pluginName string,
) *storage.KVLayer

ToKV builds and returns a storage.KVLayer containing the configuration layers matching the given taskPath, targetName, and pluginName in proper order (i.e., so that scope overrides happen correctly). The given properties store will be the top-most layer.

The scopes override each other in the following order, with the first mentioned item overriding everything below it:

1. Property Settings (from the given properties argument)

2. Target Settings on Task

3. Task Settings

4. Target Settings on Goal

5. Goal Settings

6. Plugin Settings

7. Global Settings

type GoalConfig

type GoalConfig struct {
	// Name is the name of the goal being configured.
	Name string

	// EnabledPlugins creates an allow list of plugins to use when executing
	// this goal. If an enable list is provided, then only plugins on this list
	// will be executed.
	//
	// TODO Implement EnabledPlugins functionality for goals.
	EnabledPlugins []string

	// DisabledPlugins creates a block list of plugins to disable when executing
	// this goal. If a disabled list is provided, then the listed plugins will
	// not be executed when running this goal, even if they are listed in the
	// EnabledPlugins list.
	//
	// TODO Implement DisabledPlugins functionality for goals.
	DisabledPlugins []string

	// Properties provides settings that override globals when executing this
	// goal or one of its sub-tasks.
	Properties storage.KV

	// Tasks provides configuration of sub-tasks of this goal.
	Tasks []TaskConfig

	// Targets provides configuration of targets as applies ot this goal.
	Targets []TargetConfig
}

func (*GoalConfig) GetTarget

func (g *GoalConfig) GetTarget(targetName string) *TargetConfig

GetTarget returns the TargetConfig for the given target name.

type PluginConfig

type PluginConfig struct {
	// Name is the name to give the plugin.
	Name string

	// Command is the command to execute to run the plugin.
	Command string

	// Properties provides settings that overwrite globals when executing this
	// plugin.
	Properties storage.KV
}

PluginConfig holds the configuration to use for a particular plugin.

type RawConfig

type RawConfig struct {
	Properties cty.Value `hcl:"properties,optional"`

	Goals   []RawGoalConfig   `hcl:"goal,block"`
	Plugins []RawPluginConfig `hcl:"plugin,block"`
}

RawConfig is the configuration specification for HCL. See Config for details on what the fields represent.

type RawGoalConfig

type RawGoalConfig struct {
	Name string `hcl:"name,label"`

	EnabledPlugins  []string `hcl:"enabled,optional"`
	DisabledPlugins []string `hcl:"disabled,optional"`

	Properties cty.Value `hcl:"properties,optional"`

	Tasks   []RawTaskConfig   `hcl:"task,block"`
	Targets []RawTargetConfig `hcl:"target,block"`
}

RawGoalConfig is the configuration specification for HCL for goal configuration. See GoalConfig for details on what the fields represent.

type RawPluginConfig

type RawPluginConfig struct {
	Name    string `hcl:"name,label"`
	Command string `hcl:"command,label"`

	Properties cty.Value `hcl:"properties,optional"`
}

RawPluginConfig is the configuration specification for HCL for plugin configuration. See PluginConfig for details on what the fields represent.

type RawTargetConfig

type RawTargetConfig struct {
	Name string `hcl:"name,label"`

	EnabledPlugins  []string `hcl:"enabled,optional"`
	DisabledPlugins []string `hcl:"disabled,optional"`

	Properties cty.Value `hcl:"properties,optional"`
}

RawTargetConfig is the configuration specification for HCL for target configuration. See TargetConfig for details on what the fields represent.

type RawTaskConfig

type RawTaskConfig struct {
	Name    string `hcl:"name,label"`
	SubTask string `hcl:"subtask,label"`

	EnabledPlugins  []string `hcl:"enabled,optional"`
	DisabledPlugins []string `hcl:"disabled,optional"`

	Properties cty.Value `hcl:"properties,optional"`

	Targets []RawTargetConfig `hcl:"target,block"`
	Tasks   []RawTaskConfig   `hcl:"task,block"`
}

RawTaskConfig is the configuration specification for HCL for task configuration. See TaskConfig for details on what the fields represent.

type TargetConfig

type TargetConfig struct {
	// Name is the name to give the target.
	Name string

	// EnabledPlugins creates an allow list of plugins to use when executing
	// this target. If an enable list is provided, then only plugins on this
	// list will be executed.
	//
	// TODO Implement EnabledPlugins functionality for targets.
	EnabledPlugins []string

	// DisabledPlugins creates a block list of plugins to disable when executing
	// this target. If a disabled list is provided, then the listed plugins
	// will not be executed when running this sub-task, even if they are listed
	// in the EnabledPlugins list.
	//
	// TODO Implement DisabledPlugins functionality for targets.
	DisabledPlugins []string

	// Properties are the settings that will override those of the global
	// settings or the parent goal or task.
	Properties storage.KV
}

TargetConfig is the configuration of a target, which allows for multiple configurations for each goal in case you need a different configuration per environment or per output binary or whatever.

type TaskConfig

type TaskConfig struct {
	// Name is the name of the sub-task.
	Name string

	// SubTask is the name of the sub-sub-task (and may be empty).
	SubTask string

	// EnabledPlugins creates an allow list of plugins to use when executing
	// this sub-task. If an enable list is provided, then only plugins on this
	// list will be executed.
	//
	// TODO Implement EnabledPlugins functionality for tasks.
	EnabledPlugins []string

	// DisabledPlugins creates a block list of plugins to disable when executing
	// this sub-task. If a disabled list is provided, then the listed plugins
	// will not be executed when running this sub-task, even if they are listed
	// in the EnabledPlugins list.
	//
	// TODO Implement DisabledPlugins functionality for tasks.
	DisabledPlugins []string

	// Properties are the settings used to override globals and goal settings
	// when executing this sub-task.
	Properties storage.KV

	// Targets is configuration that should apply just to this sub-task.
	Targets []TargetConfig

	// Tasks is nested sub-tasks.
	Tasks []TaskConfig
}

TaskConfig is the configuration for a sub-task, which is always nested within a goal configuration. This configuration will be employed while running this sub-task regardless of how executed from the command-line.

TODO The sub-sub-task configuration here seems inconsistent and needs a look.

func (*TaskConfig) GetTarget

func (t *TaskConfig) GetTarget(targetName string) *TargetConfig

GetTarget returns the TargetConfig for the given target name.

Jump to

Keyboard shortcuts

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