cli

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package session wraps ocm session parameters to be accessed during cli commands. For example both the active connection and logger can be retrieved from the current session.

Index

Constants

View Source
const (
	LogLevelError = iota
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
)

Variables

View Source
var ErrNoConfigurationLoaded = errors.New("no configuration loaded")

Functions

func LogLevel

func LogLevel(verbosity int) log.Level

LogLevel converts an integer value to the appropriate log Level.

func Normalize added in v0.6.0

func Normalize(s string) string

func ParseOrder

func ParseOrder(maybeOrder string) ocm.Order

func ParseTime

func ParseTime(maybeTime string) (time.Time, error)

func PromptYesOrNo added in v0.2.0

func PromptYesOrNo(out io.Writer, in io.Reader, msg string) bool

func UpperSnake added in v0.6.0

func UpperSnake(header string) string

Types

type CommonOptions

type CommonOptions struct {
	Columns   string
	NoHeaders bool
	NoColor   bool
}

func (*CommonOptions) AddColumnsFlag

func (c *CommonOptions) AddColumnsFlag(flags *pflag.FlagSet)

func (*CommonOptions) AddNoColorFlag added in v0.2.2

func (c *CommonOptions) AddNoColorFlag(flags *pflag.FlagSet)

func (*CommonOptions) AddNoHeadersFlag

func (c *CommonOptions) AddNoHeadersFlag(flags *pflag.FlagSet)

func (*CommonOptions) DefaultColumns

func (c *CommonOptions) DefaultColumns(cols string)

type Config

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

Config wraps an 'ocm-cli' config object and it's fields/methods.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig loads an existing 'ocm.json' file and returns a Config object if possible.

func (Config) ClientID

func (c Config) ClientID() string

ClientID returns the user's client id as configured.

func (Config) IsEmpty

func (c Config) IsEmpty() bool

IsEmpty returns true if there is no configuration file or if no credentials are present with which to start a session.

func (Config) Pager

func (c Config) Pager() string

Pager returns the configured paging application to pipe output to.

func (Config) URL

func (c Config) URL() string

URL returns the configured OCM URL.

type FilterOptions

type FilterOptions struct {
	Order ocm.Order

	Before time.Time

	After time.Time
	// contains filtered or unexported fields
}

func (*FilterOptions) AddAfterFlag

func (f *FilterOptions) AddAfterFlag(flags *pflag.FlagSet)

func (*FilterOptions) AddBeforeFlag

func (f *FilterOptions) AddBeforeFlag(flags *pflag.FlagSet)

func (*FilterOptions) AddOrderFlag

func (f *FilterOptions) AddOrderFlag(flags *pflag.FlagSet)

func (*FilterOptions) AfterUsage

func (f *FilterOptions) AfterUsage(usg string)

func (*FilterOptions) BeforeUsage

func (f *FilterOptions) BeforeUsage(usg string)

func (*FilterOptions) OrderDefault

func (f *FilterOptions) OrderDefault(ord string)

func (*FilterOptions) OrderUsage

func (f *FilterOptions) OrderUsage(usg string)

func (*FilterOptions) ParseFilterOptions

func (f *FilterOptions) ParseFilterOptions() error

type HeaderFormatter added in v0.6.0

type HeaderFormatter func(string) string

type LatestPluginBinaryGetter added in v0.4.0

type LatestPluginBinaryGetter interface {
	GetLatestPluginBinary(context.Context) ([]byte, error)
}

type LatestVersionGetter added in v0.4.0

type LatestVersionGetter interface {
	GetLatestVersion(context.Context) (string, error)
}

type Pager added in v0.6.0

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

func NewPager added in v0.6.0

func NewPager(bin string, out io.Writer) (*Pager, error)

func (*Pager) Close added in v0.6.0

func (p *Pager) Close() error

func (*Pager) Write added in v0.6.0

func (p *Pager) Write(b []byte) (n int, err error)

type Row added in v0.6.0

type Row map[string]interface{}

func NewRow added in v0.6.0

func NewRow(data map[string]interface{}) Row

func (Row) AddField added in v0.6.0

func (r Row) AddField(name string, val interface{})

func (Row) ValueString added in v0.6.0

func (r Row) ValueString(name string) string

type RowDataProvider added in v0.6.0

type RowDataProvider interface {
	ProvideRowData() map[string]interface{}
}

type RowModifier added in v0.6.0

type RowModifier func(Row) Row

func WithAdditionalFields added in v0.6.0

func WithAdditionalFields(fields map[string]interface{}) RowModifier

type SearchOptions

type SearchOptions struct {
	Search string
	// contains filtered or unexported fields
}

func (*SearchOptions) AddSearchFlag

func (s *SearchOptions) AddSearchFlag(flags *pflag.FlagSet)

func (*SearchOptions) SearchUsage

func (s *SearchOptions) SearchUsage(usg string)

type Session

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

Session provides access to the session-bound parameters for an invocation of this plug-in.

func NewSession

func NewSession() (Session, error)

NewSession loads an ocm configuration created after the user runs 'ocm login' and starts a connection to ocm. A logger with session context is also made available to callers of NewSession. An error is returned if a configuration cannot be loaded or if a connection cannot be made to OCM. Otherwise a pointer to a session object is returned.

func (*Session) Conn

func (s *Session) Conn() *sdk.Connection

Conn returns the OCM connection for the current session.

func (*Session) End

func (s *Session) End()

End releases any open session resources and logs any errors that may occur during this process.

func (*Session) Logger

func (s *Session) Logger() log.Interface

Logger returns a log instance with session context added.

func (*Session) Pager added in v0.2.2

func (s *Session) Pager() string

Pager returns the pager binary loaded for the current session.

type Table

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

func NewTable

func NewTable(opts ...TableOption) (*Table, error)

func (*Table) Flush added in v0.6.0

func (t *Table) Flush() error

func (*Table) Write added in v0.6.0

func (t *Table) Write(r RowDataProvider, mods ...RowModifier) error

type TableConfig added in v0.6.0

type TableConfig struct {
	Out        io.Writer
	Columns    []string
	HFormatter HeaderFormatter
	NoColor    bool
	NoHeaders  bool
	PagerBin   string
}

func (*TableConfig) Default added in v0.6.0

func (c *TableConfig) Default()

func (*TableConfig) Option added in v0.6.0

func (c *TableConfig) Option(opts ...TableOption)

type TableOption

type TableOption interface {
	ConfigureTable(*TableConfig)
}

type VersionUpdater added in v0.4.0

type VersionUpdater interface {
	LatestVersionGetter
	LatestPluginBinaryGetter
}

type WithColumns added in v0.6.0

type WithColumns string

func (WithColumns) ConfigureTable added in v0.6.0

func (wc WithColumns) ConfigureTable(c *TableConfig)

type WithHeaderFormatter added in v0.6.0

type WithHeaderFormatter HeaderFormatter

func (WithHeaderFormatter) ConfigureTable added in v0.6.0

func (wh WithHeaderFormatter) ConfigureTable(c *TableConfig)

type WithNoColor added in v0.6.0

type WithNoColor bool

func (WithNoColor) ConfigureTable added in v0.6.0

func (wn WithNoColor) ConfigureTable(c *TableConfig)

type WithNoHeaders added in v0.6.0

type WithNoHeaders bool

func (WithNoHeaders) ConfigureTable added in v0.6.0

func (wn WithNoHeaders) ConfigureTable(c *TableConfig)

type WithOutput added in v0.6.0

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

func (WithOutput) ConfigureTable added in v0.6.0

func (wo WithOutput) ConfigureTable(c *TableConfig)

type WithPager added in v0.6.0

type WithPager string

func (WithPager) ConfigureTable added in v0.6.0

func (wp WithPager) ConfigureTable(c *TableConfig)

Jump to

Keyboard shortcuts

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