clicontext

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Server is the configuration to talk to a Waypoint server.
	Server serverconfig.Client `hcl:"server,block"`

	// Workspace represents the current workspace for this context. This value
	// can be set instead of using the -workspace CLI flag. If empty, the
	// default value is "default"
	Workspace string `hcl:"workspace,optional"`
}

Config is the structure of the context configuration file. This structure can be decoded with hclsimple.DecodeFile.

func LoadPath

func LoadPath(path string) (*Config, error)

LoadPath loads a context configuration from a filepath.

func (*Config) FromURL added in v0.5.0

func (c *Config) FromURL(v string) error

FromURL parses a URL to a Waypoint server and populates as much of the context configuration as possible. This makes a number of assumptions:

  • assumes TLS
  • assumes TLS skip verify

The skip verify bit is a bad default but it is the most common UX getting started and this URL is most commonly used with `waypoint login` so we want to provide the smoothest experience there at the expense of a slight risk.

func (*Config) WriteTo

func (c *Config) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo and encodes this config as HCL.

type Option

type Option func(*Storage) error

func WithDir

func WithDir(d string) Option

WithDir specifies the directory where context configuration will be stored. This doesn't have to exist already but we must have permission to create it.

func WithNoSymlink() Option

WithNoSymlink disables all symlink usage in the Storage. If symlinks were used previously then they'll still work.

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage is the primary struct for interacting with stored CLI contexts. Contexts are always stored directly on disk with one set as the default.

func NewStorage

func NewStorage(opts ...Option) (*Storage, error)

NewStorage initializes context storage.

func TestStorage

func TestStorage(t testing.T) *Storage

TestStorage returns a *Storage pointed at a temporary directory. This will cleanup automatically by using t.Cleanup.

func (*Storage) Default

func (m *Storage) Default() (string, error)

Default returns the name of the default context.

func (*Storage) Delete

func (m *Storage) Delete(n string) error

Delete deletes the context with the given name.

func (*Storage) List

func (m *Storage) List() ([]string, error)

List lists the contexts that are available.

func (*Storage) Load

func (m *Storage) Load(n string) (*Config, error)

Load loads a context with the given name.

func (*Storage) Rename

func (m *Storage) Rename(from, to string) error

Rename renames a context. This will error if the "from" context does not exist. If "from" is the default context then the default will be switched to "to". If "to" already exists, this will overwrite it.

func (*Storage) Set

func (m *Storage) Set(n string, c *Config) error

Set will set a new configuration with the given name. This will overwrite any existing context of this name.

func (*Storage) SetDefault

func (m *Storage) SetDefault(n string) error

SetDefault sets the default context to use. If the given context doesn't exist, an os.IsNotExist error will be returned.

func (*Storage) UnsetDefault

func (m *Storage) UnsetDefault() error

UnsetDefault unsets the default context.

Jump to

Keyboard shortcuts

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