place

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Read a value from the config file
	//
	// This is a function pointer to decouple the config
	// implementation from the fs
	ConfigFileGet = func(section, key string) (string, bool) { return "", false }

	// Set a value into the config file and persist it
	//
	// This is a function pointer to decouple the config
	// implementation from the fs
	ConfigFileSet = func(section, key, value string) (err error) {
		return errors.New("no config file set handler")
	}
)

Global

View Source
var (
	// Registry Backend registry
	Registry []*RegInfo
)

Functions

func BackendNames

func BackendNames() []string

func ConfigMap

func ConfigMap(backendInfo *RegInfo, configName string) (config *configmap.Map)

func ConfigToEnv

func ConfigToEnv(section, name string) string

ConfigToEnv converts a config section and name, e.g. ("myremote", "ignore-size") into an environment name "HONEY_CONFIG_MYREMOTE_IGNORE_SIZE"

func OptionToEnv

func OptionToEnv(name string) string

OptionToEnv converts an option name, e.g. "ignore-size" into an environment name "HONEY_IGNORE_SIZE"

func Register

func Register(info *RegInfo)

Register backend

func ToMap

func ToMap(m interface{}) (map[string]interface{}, error)

Types

type Backend

type Backend interface {
	Name() string
	CacheKeyName(pattern string) string
	List(ctx context.Context, backendName string, pattern string) (Printable, error)
}

Backend _

type CommandHelp

type CommandHelp struct {
	Name  string            // Name of the command, e.g. "link"
	Short string            // Single line description
	Long  string            // Long multi-line description
	Opts  map[string]string // maps option name to a single line help
}

CommandHelp describes a single backend Command

These are automatically inserted in the docs

type Commander

type Commander interface {
	// Command the backend to run a named command
	//
	// The command run is name
	// args may be used to read arguments from
	// opts may be used to read optional arguments from
	//
	// The result should be capable of being JSON encoded
	// If it is a string or a []string it will be shown to the user
	// otherwise it will be JSON encoded and shown to the user like that
	Command(ctx context.Context, name string, arg []string, opt map[string]string) (interface{}, error)
}

Commander is an interface to wrap the Command function

type ConfigInfo

type ConfigInfo struct {
	NoCache        bool
	NoColor        bool
	OutFormat      string
	BackendsString string
	CacheTTL       time.Duration
}

ConfigInfo is honey config options

func AddConfig

func AddConfig(ctx context.Context) (context.Context, *ConfigInfo)

AddConfig returns a mutable config structure based on a shallow copy of that found in ctx and returns a new context with that added to it.

func GetConfig

func GetConfig(ctx context.Context) *ConfigInfo

GetConfig returns the global or context sensitive context

func NewConfig

func NewConfig() *ConfigInfo

func (*ConfigInfo) Backends added in v0.1.8

func (c *ConfigInfo) Backends() ([]string, error)

type FlattenData

type FlattenData struct {
	Len   int
	Bytes []byte
}

func (*FlattenData) Filter

func (d *FlattenData) Filter(keys []string) ([]map[string]interface{}, error)

func (*FlattenData) ToArrayMap added in v0.1.6

func (d *FlattenData) ToArrayMap() ([]map[string]interface{}, error)

type Instance

type Instance struct {
	Model `mapstructure:",squash"`
	Raw   interface{}
}

Instance _

type Model

type Model struct {
	ID          string `json:"id"`
	BackendName string `json:"backend_name" mapstructure:"backend_name"`
	Name        string `json:"name"`
	Type        string `json:"type"`
	Status      string `json:"status"`
	PrivateIP   string `json:"private_ip" mapstructure:"private_ip"`
	PublicIP    string `json:"public_ip" mapstructure:"public_ip"`
}

type Option

type Option struct {
	Name       string           // name of the option in snake_case
	Help       string           // Help, the first line only is used for the command line help
	Provider   string           // Set to filter on provider
	Default    interface{}      // default value, nil => ""
	Value      interface{}      // value to be set by flags
	Examples   OptionExamples   `json:",omitempty"` // config examples
	ShortOpt   string           // the short option for this if required
	Hide       OptionVisibility // set this to hide the config from the configurator or the command line
	Required   bool             // this option is required
	IsPassword bool             // set if the option is a passwords
	NoPrefix   bool             // set if the option for this should not use the backend prefix
	Advanced   bool             // set if this is an advanced config option
}

Option _

func (*Option) EnvVarName

func (o *Option) EnvVarName(prefix string) string

EnvVarName for the option

func (*Option) FlagName

func (o *Option) FlagName(prefix string) string

FlagName for the option

func (*Option) GetValue

func (o *Option) GetValue() interface{}

GetValue gets the current current value which is the default if not set

func (*Option) Set

func (o *Option) Set(s string) (err error)

Set an Option from a string

func (*Option) String

func (o *Option) String() string

String turns Option into a string

func (*Option) Type

func (o *Option) Type() string

Type of the value

type OptionExample

type OptionExample struct {
	Value    string
	Help     string
	Provider string
}

OptionExample describes an example for an Option

type OptionExamples

type OptionExamples []OptionExample

OptionExamples is a slice of examples

func (OptionExamples) Len

func (os OptionExamples) Len() int

Len is part of sort.Interface.

func (OptionExamples) Less

func (os OptionExamples) Less(i, j int) bool

Less is part of sort.Interface.

func (OptionExamples) Sort

func (os OptionExamples) Sort()

Sort sorts an OptionExamples

func (OptionExamples) Swap

func (os OptionExamples) Swap(i, j int)

Swap is part of sort.Interface.

type OptionVisibility

type OptionVisibility byte

OptionVisibility controls whether the options are visible in the configurator or the command line.

const (
	OptionHideCommandLine OptionVisibility = 1 << iota
	OptionHideConfigurator
	OptionHideBoth = OptionHideCommandLine | OptionHideConfigurator
)

Constants Option.Hide

type Options

type Options []Option

Options is a slice of configuration Option for a backend

func (Options) Get

func (os Options) Get(name string) *Option

Get the Option corresponding to name or return nil if not found

type Printable

type Printable []*Instance

func (Printable) FlattenData

func (p Printable) FlattenData() (*FlattenData, error)

func (Printable) Headers

func (p Printable) Headers() []string

func (Printable) Rows

func (p Printable) Rows() [][]string

type RegInfo

type RegInfo struct {
	// Name of this backend
	Name string
	// Description of this fs - defaults to Name
	Description string
	// Prefix for command line flags for this fs - defaults to Name if not set
	Prefix string

	NewBackend func(ctx context.Context, config configmap.Mapper) (Backend, error) `json:"-"`
	// Function to call to help with config
	Config func(ctx context.Context, name string, config configmap.Mapper) `json:"-"`
	// Options for the Backend configuration
	Options Options
	// The command help, if any
	CommandHelp []CommandHelp
}

RegInfo _

func Find

func Find(name string) (*RegInfo, error)

Find find backend

func MustFind added in v0.1.8

func MustFind(name string) *RegInfo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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