Documentation
¶
Index ¶
- Constants
- Variables
- func AggregateClientIDs(reqCtx []*policy.RequestContext) []string
- func AskForInput(message string) string
- func AskForSecret(message string) string
- func CommaSeparated(values []string) string
- func ConfirmAction(action, resource, id string, force bool)
- func ConfirmActionSubtext(action, resource, id, subtext string, force bool)
- func ConfirmTextInput(action, resource, inputName, shouldMatchValue string)
- func ConstructMetadata(m *common.Metadata) map[string]string
- func DebugJSON(msg string) interface{}
- func DebugMessage(msg string) string
- func EnforceSubcommandArgs(cmd *cobra.Command)
- func ErrorJSON(msg string, err error) interface{}
- func ErrorMessage(msg string, err error) string
- func ExitWithError(errMsg string, err error)
- func ExitWithNotFoundError(errMsg string, err error)
- func ExitWithWarning(warnMsg string)
- func FooterMessage(msg string) string
- func GetJSONInput(data string) (string, error)
- func GetSimpleObligationValues(v []*policy.ObligationValue) []string
- func GetSimpleRegisteredResourceActionAttributeValues(v []*policy.RegisteredResourceValue_ActionAttributeValue) []string
- func GetSimpleRegisteredResourceValues(v []*policy.RegisteredResourceValue) []string
- func GetState(cmd *cobra.Command) common.ActiveStateEnum
- func IsHelpOnly(cmd *cobra.Command) bool
- func KeyAlgToEnum(alg string) (policy.Algorithm, error)
- func KeyEnumToAlg(enum policy.Algorithm) (string, error)
- func MessageJSON(status string, msg string) interface{}
- func NewTable(cols ...table.Column) table.Model
- func NewTabular(rows ...[]string) table.Model
- func NewUUIDColumn() table.Column
- func PrettyList(values []string) string
- func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model)
- func ReadFromArgsOrPipe(args []string, pipe *os.File) []bytedeprecated
- func ReadFromFile(filePath string) []bytedeprecated
- func ReadFromPipe(in *os.File) []bytedeprecated
- func SuccessJSON(msg string) interface{}
- func SuccessMessage(msg string) string
- func TermWidth() int
- func WarningJSON(msg string) interface{}
- func WarningMessage(msg string) string
- func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model
- func WithPrintJSON() cliVariadicOption
- type Cli
- func (c *Cli) Cmd() *cobra.Command
- func (c *Cli) Context() context.Context
- func (c *Cli) ExitWith(styledMsg string, jsonMsg interface{}, code int, w io.Writer)
- func (c *Cli) ExitWithError(errMsg string, err error)
- func (c *Cli) ExitWithJSON(v interface{}, code int)
- func (c *Cli) ExitWithMessage(msg string, code int)
- func (c *Cli) ExitWithNotFoundError(errMsg string, err error)
- func (c *Cli) ExitWithSuccess(msg string)
- func (c *Cli) ExitWithWarning(warnMsg string)
- func (c *Cli) SetJSONOutput(enabled bool)
- func (c *Cli) StreamList(w io.Writer, headers []string, row func(any) []string, ...) error
- type Color
- type Flags
- func (f Flags) GetOptionalBool(flag string) bool
- func (f Flags) GetOptionalBoolWrapper(flag string) *wrapperspb.BoolValue
- func (f Flags) GetOptionalID(idFlag string) string
- func (f Flags) GetOptionalInt32(flag string) int32
- func (f Flags) GetOptionalString(flag string) string
- func (f Flags) GetRequiredBool(flag string) bool
- func (f Flags) GetRequiredID(idFlag string) string
- func (f Flags) GetRequiredInt32(flag string) int32
- func (f Flags) GetRequiredString(flag string) string
- func (f Flags) GetStringSlice(flag string, v []string, opts FlagsStringSliceOptions) []string
- type FlagsStringSliceOptions
- type Printer
- type SimpleAttribute
- type SimpleAttributeValue
Constants ¶
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" )
const ( ExitCodeSuccess = 0 ExitCodeError = 1 )
const ( FlexColumnWidthOne = 1 FlexColumnWidthTwo = 2 FlexColumnWidthThree = 3 FlexColumnWidthFour = 4 FlexColumnWidthFive = 5 )
const AnnotationHelpOnly = "help-only"
AnnotationHelpOnly marks a command whose Run only prints help.
Variables ¶
var ErrPrinterExpectsCommand = errors.New("printer expects a command")
Functions ¶
func AggregateClientIDs ¶
func AggregateClientIDs(reqCtx []*policy.RequestContext) []string
func AskForInput ¶
func AskForSecret ¶
func CommaSeparated ¶
func ConfirmAction ¶
func ConfirmActionSubtext ¶
func ConfirmTextInput ¶
func ConfirmTextInput(action, resource, inputName, shouldMatchValue string)
func DebugMessage ¶
func EnforceSubcommandArgs ¶ added in v0.38.0
EnforceSubcommandArgs makes unknown group subcommands fail validation.
func ErrorMessage ¶
func ExitWithError ¶
func ExitWithNotFoundError ¶
func ExitWithWarning ¶
func ExitWithWarning(warnMsg string)
func FooterMessage ¶
func GetJSONInput ¶
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 IsHelpOnly ¶ added in v0.38.0
IsHelpOnly reports whether cmd is a group whose Run only prints help.
func MessageJSON ¶
func NewTabular ¶
func NewUUIDColumn ¶
func PrettyList ¶
func ReadFromArgsOrPipe
deprecated
func ReadFromFile
deprecated
Deprecated: reads the entire file into memory with no size cap at all — not even the 10 GB one the tdf commands apply — and terminates the process on failure. Open the file and stream from it, or use utils.ReadBytesFromFile if a bounded in-memory read is genuinely wanted.
func ReadFromPipe
deprecated
func SuccessJSON ¶
func SuccessJSON(msg string) interface{}
func SuccessMessage ¶
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 WithListPaginationFooter ¶
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 *Flags
// contains filtered or unexported fields
}
func (*Cli) ExitWith ¶
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 ¶
ExitWithError prints an error message and exits with a non-zero status code.
func (*Cli) ExitWithJSON ¶
func (*Cli) ExitWithMessage ¶
func (*Cli) ExitWithNotFoundError ¶
ExitWithNotFoundError prints an error message and exits with a non-zero status code if the error is a NotFound error.
func (*Cli) ExitWithSuccess ¶
func (*Cli) ExitWithWarning ¶
func (*Cli) SetJSONOutput ¶
func (*Cli) StreamList ¶ added in v0.37.0
func (c *Cli) StreamList(w io.Writer, headers []string, row func(any) []string, items iter.Seq2[any, error]) error
StreamList renders a list of items incrementally to w.
In JSON mode (the printer configured for JSON output) it writes a JSON array, encoding one item at a time so the full result set is never held in memory. This is the memory-bounded path, suitable for very large lists.
In styled mode it renders a bordered, styled table with the given column headers, one row per item derived from row. Aligning and styling the table requires every cell, so the styled path buffers rows until the stream completes; use JSON mode when memory bounds matter for a large result set.
items is an iter.Seq2 yielding (item, err) so callers can feed a paged iterator without materializing it. A non-nil err (for example, a failed page fetch) aborts the stream and is returned, so a mid-iteration failure surfaces to the caller rather than looking like normal exhaustion. row maps an item to its table cells and is only invoked in styled mode.
type Color ¶
type Color struct {
Foreground lipgloss.CompleteAdaptiveColor
Background lipgloss.CompleteAdaptiveColor
}
func ColorYellow ¶
func ColorYellow() Color
type Flags ¶ added in v0.33.0
type Flags struct {
// contains filtered or unexported fields
}
func (Flags) GetOptionalBool ¶ added in v0.33.0
func (Flags) GetOptionalBoolWrapper ¶ added in v0.33.0
func (f Flags) GetOptionalBoolWrapper(flag string) *wrapperspb.BoolValue
Returns nil when the flag is not explicitly set.
func (Flags) GetOptionalID ¶ added in v0.33.0
func (Flags) GetOptionalInt32 ¶ added in v0.33.0
func (Flags) GetOptionalString ¶ added in v0.33.0
func (Flags) GetRequiredBool ¶ added in v0.33.0
func (Flags) GetRequiredID ¶ added in v0.33.0
func (Flags) GetRequiredInt32 ¶ added in v0.33.0
func (Flags) GetRequiredString ¶ added in v0.33.0
func (Flags) GetStringSlice ¶ added in v0.33.0
func (f Flags) GetStringSlice(flag string, v []string, opts FlagsStringSliceOptions) []string
type FlagsStringSliceOptions ¶
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 ¶
func GetSimpleAttributeValue ¶
func GetSimpleAttributeValue(v *policy.Value) SimpleAttributeValue