config

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package config contains types and functions for managing the user's local configuration for the command-line interface.

Index

Constants

This section is empty.

Variables

View Source
var ErrConfigExists = errors.New("config exists")

ErrConfigExists is the error given when a configuration file is already present in the config directory.

View Source
var ErrNoConfiguration = errors.New("no configuration file")

ErrNoConfiguration is the error given when a configuration file cannot be found in the config directory.

Functions

func Create

func Create(config *Config) error

Create a new configuration file in the config directory containing the contents of the given Config type. The location of the configuration file changes based on the host operating system. See the documentation for os.UserConfigDir for specifics on where the config file is written to. Returns ErrConfigExists if a config file already exists.

func Save

func Save(config *Config) error

Save the provided configuration, updating an existing file if it already exists. The location of the configuration file changes based on the host operating system. See the documentation for os.UserConfigDir for specifics on where the config file is written to.

func ToContext

func ToContext(ctx context.Context, config *Config) context.Context

ToContext returns a context.Context that contains the provided Config instance.

Types

type Config

type Config struct {
	// Organization denotes the user's selected organization.
	Organization string `json:"organization"`
}

The Config type describes the structure of the user's local configuration file. These values are used for performing operations against the control-plane API.

func FromContext

func FromContext(ctx context.Context) (*Config, bool)

FromContext attempts to obtain a Config type contained within the provided context.Context. The boolean return value is used to indicate if the context contains a Config.

func Load

func Load() (*Config, error)

Load the configuration file from the config directory, decoding it into a Config type. The location of the configuration file changes based on the host operating system. See the documentation for os.UserConfigDir for specifics on where the config file is loaded from. Returns ErrNoConfiguration if the config file cannot be found.

Jump to

Keyboard shortcuts

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