config

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 7 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 ErrNoConfiguration = errors.New("no configuration file")

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

Functions

func DefaultConfigDir added in v0.1.12

func DefaultConfigDir() (string, error)

DefaultConfigDir returns the preferred config directory for the current platform

func Delete added in v0.1.12

func Delete(ctx context.Context) error

Delete will remove the config file if one exists at the path set in the context

func MigrateDefaultConfig added in v0.1.12

func MigrateDefaultConfig(newConfigDir string) error

MigrateDefaultConfig has been implemented in response to: https://github.com/jetstack/jsctl/issues/52 We were using UserConfigDir from the os package, however, users did not expect this. So we have moved to ~/.jsctl or something equivalent instead.

func ReadConfigFile added in v0.1.12

func ReadConfigFile(ctx context.Context, path string) ([]byte, error)

ReadConfigFile reads a file from the config directory specified in the provided context

func Save

func Save(ctx context.Context, cfg *Config) error

Save the provided configuration, updating an existing file if it already exists.

func ToContext

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

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

func WriteConfigFile added in v0.1.12

func WriteConfigFile(ctx context.Context, path string, data []byte) error

WriteConfigFile writes a file with the correct permissions to the config directory specified in the provided context

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(ctx context.Context) (*Config, error)

Load the configuration file from the config directory specified in the provided context.Context. Returns ErrNoConfiguration if the config file cannot be found.

type ContextKey added in v0.1.12

type ContextKey struct{}

ContextKey is a type used as a key for the config path in the context

Jump to

Keyboard shortcuts

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