cmd

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package cmd builds the sonar client CLI command tree on top of service.Service using spf13/cobra directly — no cmdx. Per-command flag / argument / validation wiring lives in this package next to the commands themselves via the closure pattern: a build func that configures the command and returns its run. Authorization (incl. admin-only commands) is enforced by the service layer, not here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultMessengersPreExec

func DefaultMessengersPreExec(root *cobra.Command)

DefaultMessengersPreExec adapts the command tree for messenger (chat) use: it renders commands in slash style (e.g. "/dns" instead of "sonar dns") and drops the auto-generated completion command, which is meaningless in chat. Pass it to New via PreExec.

Types

type Command

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

Command builds the client command tree against a service.Service.

func New

func New(svc service.Service, opts ...Option) *Command

New returns a Command backed by svc.

func (*Command) Exec

func (c *Command) Exec(ctx context.Context, args []string) (any, error)

Exec builds the tree, applies the PreExec hook, installs a result sink in ctx, and runs args. The result is either the typed service output from the invoked leaf or, when no leaf produced data (help/usage/completion), the raw text cobra wrote. Execution errors are returned separately.

func (*Command) ParseAndExec

func (c *Command) ParseAndExec(ctx context.Context, s string) (any, error)

ParseAndExec splits s into args (stripping a leading "/", as messengers send) and runs it.

func (*Command) Root

func (c *Command) Root() *cobra.Command

Root assembles the command tree. The whole tree lives here; each leaf references a build method (see the per-resource files) that wires its flags and returns its run closure.

type Option

type Option func(*options)

Option configures a Command.

func AllowFileAccess

func AllowFileAccess(b bool) Option

AllowFileAccess enables flags that read local files (e.g. http --file). For use in the CLI application only — must stay false for messengers, otherwise there is a local file read vulnerability.

func PreExec

func PreExec(f func(root *cobra.Command)) Option

PreExec runs against the cobra root after the tree is built. Use it to add subcommands/flags, set help/usage templates, or set PersistentPreRunE.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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