cli

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package cli is the prodmask command line. The free build's commands live here behind a small registry, so another build can add commands of its own and keep the same flags, output and exit statuses for the free ones.

Index

Constants

View Source
const (
	ExitOK       = 0
	ExitError    = 1
	ExitUsage    = 2
	ExitFindings = 3
	ExitLicence  = 4 // a command that needs a prodmask Pro licence found no valid one
)

Exit statuses. Every build shares them, so a status means the same thing whichever command returns it.

Variables

This section is empty.

Functions

func BuildVersion

func BuildVersion(stamped string) string

BuildVersion returns the version a build reports: stamped when the build set it with -ldflags "-X main.version=...", otherwise the module version Go recorded for go install or go build, otherwise "dev".

Types

type App

type App struct {
	Version string // shown by prodmask version and recorded in reports
	Edition string // the build's name after "prodmask", such as "Pro"; empty for the free build
	About   string // the paragraph above the command list
	Footer  string // the text below the command list
	// contains filtered or unexported fields
}

App is one build of prodmask: its version, the text around its command list, and its commands.

func New

func New(version string) *App

New returns the free build of prodmask.

func (*App) Commands

func (a *App) Commands() []*Command

Commands returns the registered commands in name order.

func (*App) Lookup

func (a *App) Lookup(word string) *Command

Lookup returns the command a word selects, or nil.

func (*App) Register

func (a *App) Register(cmds ...*Command)

Register adds commands. It panics if a command has no name or Run function, or if a name or alias is already taken, as these are mistakes in the program rather than in its input.

func (*App) Run

func (a *App) Run(ctx context.Context, args []string, stdout, stderr io.Writer) int

Run runs the command that args select and returns the exit status.

func (*App) Usage

func (a *App) Usage() string

Usage returns the help text: the about paragraph, the commands in name order, and the footer.

func (*App) VersionLine

func (a *App) VersionLine() string

VersionLine is what prodmask version prints, such as "prodmask 0.1.0".

type Command

type Command struct {
	Name    string   // the word that selects it: prodmask <Name>
	Aliases []string // other words that select it, such as --version; not listed
	Args    string   // what follows the name in the command list, such as "[flags]"
	Summary string   // its line in the command list

	// Run runs the command with the arguments after its name and returns
	// the exit status.
	Run func(ctx context.Context, env *Env, args []string) int
}

Command is one prodmask command, such as scan.

func FreeCommands

func FreeCommands() []*Command

FreeCommands returns new copies of the free build's commands, for builds that add their own.

type Env

type Env struct {
	App    *App
	Stdout io.Writer
	Stderr io.Writer
}

Env is what a command runs with.

Jump to

Keyboard shortcuts

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