cli

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: Apache-2.0 Imports: 13 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 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

Types

type CommonOptions

type CommonOptions struct {
	Columns   string
	NoHeaders bool
}

func (*CommonOptions) AddColumnsFlag

func (c *CommonOptions) AddColumnsFlag(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 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) Config

func (s *Session) Config() Config

Config returns the config loaded for the current session.

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.

type Table

type Table struct {
	*output.Table
	// contains filtered or unexported fields
}

func NewTable

func NewTable(ctx context.Context, sess Session, options ...TableOption) (*Table, error)

NewTable returns a Table object which is used to format tabular output from the requested data for a particular cli command.

func (*Table) Close

func (t *Table) Close() error

Close flushes the output stream and releases any resources in use.

func (*Table) WriteHeaders

func (t *Table) WriteHeaders() error

WriteHeaders writes the table column headers when noHeaders is false.

type TableOption

type TableOption func(*Table) error

func TableColumns

func TableColumns(columns string) TableOption

TableColumns selects the columns to be written by the table.

func TableName

func TableName(name string) TableOption

TableName selects the name of the table file to reference for this table instance.

func TableNoHeaders

func TableNoHeaders(noHeaders bool) TableOption

TableNoHeaders toggles whether this table will print headers.

func TableWriter

func TableWriter(writer io.Writer) TableOption

TableWriter sets the writer instance where output will be written.

Jump to

Keyboard shortcuts

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