cli

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: BSD-3-Clause-Clear Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// top level actions
	ActionGet          = "get"
	ActionList         = "list"
	ActionCreate       = "create"
	ActionUpdate       = "update"
	ActionUpdateUnsafe = "unsafely update"
	ActionDeactivate   = "deactivate"
	ActionReactivate   = "reactivate"
	ActionDelete       = "delete"

	// text input names
	InputNameFQN        = "fully qualified name (FQN)"
	InputNameFQNUpdated = "deprecated fully qualified name (FQN) being altered"
)
View Source
const (
	ExitCodeSuccess = 0
	ExitCodeError   = 1
)
View Source
const (
	FlexColumnWidthOne   = 1
	FlexColumnWidthTwo   = 2
	FlexColumnWidthThree = 3
	FlexColumnWidthFour  = 4
	FlexColumnWidthFive  = 5
)

Variables

View Source
var ErrPrinterExpectsCommand = errors.New("printer expects a command")

Functions

func AggregateClientIDs

func AggregateClientIDs(reqCtx []*policy.RequestContext) []string

func AskForInput

func AskForInput(message string) string

func AskForSecret

func AskForSecret(message string) string

func CommaSeparated

func CommaSeparated(values []string) string

func ConfirmAction

func ConfirmAction(action, resource, id string, force bool)

func ConfirmActionSubtext

func ConfirmActionSubtext(action, resource, id, subtext string, force bool)

func ConfirmTextInput

func ConfirmTextInput(action, resource, inputName, shouldMatchValue string)

func ConstructMetadata

func ConstructMetadata(m *common.Metadata) map[string]string

func DebugJSON

func DebugJSON(msg string) interface{}

func DebugMessage

func DebugMessage(msg string) string

func ErrorJSON

func ErrorJSON(msg string, err error) interface{}

func ErrorMessage

func ErrorMessage(msg string, err error) string

func ExitWithError

func ExitWithError(errMsg string, err error)

func ExitWithNotFoundError

func ExitWithNotFoundError(errMsg string, err error)

func ExitWithWarning

func ExitWithWarning(warnMsg string)

func FooterMessage

func FooterMessage(msg string) string

func GetJSONInput

func GetJSONInput(data string) (string, error)

Gets JSON from either a file path or a JSON string

func GetSimpleObligationValues

func GetSimpleObligationValues(v []*policy.ObligationValue) []string

func GetSimpleRegisteredResourceActionAttributeValues

func GetSimpleRegisteredResourceActionAttributeValues(v []*policy.RegisteredResourceValue_ActionAttributeValue) []string

func GetSimpleRegisteredResourceValues

func GetSimpleRegisteredResourceValues(v []*policy.RegisteredResourceValue) []string

func GetState

func GetState(cmd *cobra.Command) common.ActiveStateEnum

Transforms into enum value and defaults to active state

func KeyAlgToEnum

func KeyAlgToEnum(alg string) (policy.Algorithm, error)

func KeyEnumToAlg

func KeyEnumToAlg(enum policy.Algorithm) (string, error)

func MessageJSON

func MessageJSON(status string, msg string) interface{}

func NewTable

func NewTable(cols ...table.Column) table.Model

func NewTabular

func NewTabular(rows ...[]string) table.Model

func NewUUIDColumn

func NewUUIDColumn() table.Column

func PrettyList

func PrettyList(values []string) string

func PrintSuccessTable

func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model)

func ReadFromArgsOrPipe

func ReadFromArgsOrPipe(args []string, pipe *os.File) []byte

func ReadFromFile

func ReadFromFile(filePath string) []byte

func ReadFromPipe

func ReadFromPipe(in *os.File) []byte

func SuccessJSON

func SuccessJSON(msg string) interface{}

func SuccessMessage

func SuccessMessage(msg string) string

func TermWidth

func TermWidth() int

Returns the terminal width (overridden by env var for testing)

func WarningJSON

func WarningJSON(msg string) interface{}

func WarningMessage

func WarningMessage(msg string) string

func WithListPaginationFooter

func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model

Adds the page information to the table footer

func WithPrintJSON

func WithPrintJSON() cliVariadicOption

WithPrintJSON is a variadic option that enforces JSON output for the printer

Types

type Cli

type Cli struct {

	// Helpers
	Flags      *flagHelper
	FlagHelper *flagHelper
	// contains filtered or unexported fields
}

func New

func New(cmd *cobra.Command, args []string, options ...cliVariadicOption) *Cli

New creates a new Cli object

func (*Cli) Cmd

func (c *Cli) Cmd() *cobra.Command

func (*Cli) Context

func (c *Cli) Context() context.Context

func (*Cli) ExitWith

func (c *Cli) ExitWith(styledMsg string, jsonMsg interface{}, code int, w io.Writer)

exitWith is the core exit function that handles both JSON and styled output It writes to the appropriate stream (stdout for success, stderr for errors/warnings)

func (*Cli) ExitWithError

func (c *Cli) ExitWithError(errMsg string, err error)

ExitWithError prints an error message and exits with a non-zero status code.

func (*Cli) ExitWithJSON

func (c *Cli) ExitWithJSON(v interface{}, code int)

func (*Cli) ExitWithMessage

func (c *Cli) ExitWithMessage(msg string, code int)

func (*Cli) ExitWithNotFoundError

func (c *Cli) ExitWithNotFoundError(errMsg string, err error)

ExitWithNotFoundError prints an error message and exits with a non-zero status code if the error is a NotFound error.

func (*Cli) ExitWithSuccess

func (c *Cli) ExitWithSuccess(msg string)

func (*Cli) ExitWithWarning

func (c *Cli) ExitWithWarning(warnMsg string)

func (*Cli) SetJSONOutput

func (c *Cli) SetJSONOutput(enabled bool)

type Color

type Color struct {
	Foreground lipgloss.CompleteAdaptiveColor
	Background lipgloss.CompleteAdaptiveColor
}

func ColorYellow

func ColorYellow() Color

type FlagsStringSliceOptions

type FlagsStringSliceOptions struct {
	Min int
	Max int
}

type Printer

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

type SimpleAttribute

type SimpleAttribute struct {
	ID             string
	Name           string
	Rule           string
	Values         []string
	Namespace      string
	Active         string
	AllowTraversal string
	Metadata       map[string]string
}

func GetSimpleAttribute

func GetSimpleAttribute(a *policy.Attribute) SimpleAttribute

type SimpleAttributeValue

type SimpleAttributeValue struct {
	ID       string
	FQN      string
	Active   string
	Metadata map[string]string
}

func GetSimpleAttributeValue

func GetSimpleAttributeValue(v *policy.Value) SimpleAttributeValue

Jump to

Keyboard shortcuts

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