config

package
v0.0.0-...-439fd0a Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config provides a common base struct to be used for Juju's various config commands (config, model-config, controller-config, model-defaults). Using this struct (ConfigCommandBase) ensures that these commands share a similar interface/syntax, reducing user confusion.

ConfigCommandBase defines a generic [Init] function which parses command-line arguments according to this shared interface. This creates a slice Actions []Action which the child command should use in its Run method. The [validateActions] method encapsulates the rules regarding which actions can be done simultaneously.

This package also defines a helper method [ReadFile], which child commands can use to process yaml config files into an Attrs object.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action represents the action we want to perform here. The action will be set in Init, and then accessed by the child command's Run method to decide what to do.

const (
	GetOne  Action = "get value"
	GetAll  Action = "get all values"
	SetArgs Action = "set key=value pairs"
	SetFile Action = "use --file flag"
	Reset   Action = "use --reset flag"
)

The strings here are descriptions which will be used in the error message: "cannot X and Y simultaneously"

type Attrs

type Attrs map[string]interface{}

Attrs represents configuration attributes from either the command-line (key=value arguments) or a yaml file.

type ConfigCommandBase

type ConfigCommandBase struct {
	// Fields to be set by child
	Resettable bool     // does this command allow resetting config values?
	CantReset  []string // keys which can't be reset

	// Flag values
	ConfigFile cmd.FileVar

	Color   bool
	NoColor bool

	// Fields to be set during initialisation
	Actions     []Action // The action which we want to handle, set in Init.
	KeysToGet   []string
	KeysToReset []string // Holds keys to be reset after parsing.
	ValsToSet   Attrs
	// contains filtered or unexported fields
}

ConfigCommandBase provides a common interface/functionality for configuration commands (such as config and model-config). It defines SetFlags and Init methods, while the individual command needs to define its own Run and Info methods.

func (*ConfigCommandBase) Init

func (c *ConfigCommandBase) Init(args []string) error

Init provides a basic implementation of cmd.Command.Init. This only parses the actual key/value arguments in the command. Some child commands will also need to specify what is being configured (e.g. the app name in the case of `juju config`). In this case, the child should define its own Init command, where it strips the required arguments and passes the rest to the parent.

func (*ConfigCommandBase) ReadFile

func (c *ConfigCommandBase) ReadFile(ctx *cmd.Context) (Attrs, error)

ReadFile reads the yaml file at c.ConfigFile.Path, and parses it into an Attrs object.

func (*ConfigCommandBase) SetFlags

func (c *ConfigCommandBase) SetFlags(f *gnuflag.FlagSet)

SetFlags implements cmd.Command.SetFlags.

Jump to

Keyboard shortcuts

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