command

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package command holds what the generated behavior commands share: flags derived from an input type's tags, and the one table layout every behavior's output renders in, driven by its output type's tags. The commands themselves are generated into internal/behaviors/<name>/gen/cli.go.

Index

Constants

View Source
const InternalFolder = "internal"

InternalFolder is the folder of the reference pages of the internal behaviors, which have no area, after the folders of the areas.

View Source
const InternalLabel = "Internal"

InternalLabel is the label of InternalFolder in the sidebar and the navbar.

Variables

This section is empty.

Functions

func Annotations

func Annotations(
	b *behavior.Behavior,
	m *behavior.Method,
) map[string]string

Annotations are the docs annotations of a method's command: the permission that it needs, and its result, which is what each example does on the host and the calls that it refuses.

func Args

func Args(
	input any,
) []string

Args are the flags that set input's non-zero fields, as a command line takes them. A secret is its reference, or - for a literal value, which the command reads from standard input: Stdin is what it reads.

func Columns

func Columns(
	out reflect.Type,
) []clicommand.Column

Columns are the output fields that a behavior's result table shows, in field order: the command layer's columns of the output type, except changed, which the table renders as the row's status.

func ExampleFlags

func ExampleFlags(
	input any,
) string

ExampleFlags is the flags of an example's command line: --target and the flags of input, as the help and the pages write them.

func GroupAnnotations

func GroupAnnotations(
	b *behavior.Behavior,
) map[string]string

GroupAnnotations are the docs annotations of a behavior's own command: a note that links to the page of the behavior.

func Output

func Output(
	b *behavior.Behavior,
	m *behavior.Method,
) string

Output is what each example of m prints, as the CLI prints it, colors included: the command and its table for one host, the same command for the fleet, where one host skips, and the API's response with --json. Each screen is a fenced ansi block, which the docs site shows as a terminal. An example whose output is not an object, or a list of them, has none.

func Print

func Print(
	b *behavior.Behavior,
	method string,
	out any,
	traceID string,
)

Print writes the answer of method of b, out, the method's response type: the job ID, the trace ID of the call, and the table every behavior renders. The command runtime calls it through printResults.

func ReferenceFolder

func ReferenceFolder(
	b *behavior.Behavior,
) string

ReferenceFolder is the folder of b's reference page under reference/behaviors: the folder of its area, such as hardware, or InternalFolder for an internal behavior, which has no area.

func ReferencePage

func ReferencePage(
	b *behavior.Behavior,
) string

ReferencePage is b's reference page from reference/behaviors, such as hardware/disk/disk.md: each behavior's page is in a folder of its own, in the folder of its area. A behavior that Of nests has its folder in the folder of its parent, as its command is under the parent's, such as security/user/sshkey/sshkey.md.

func ReferenceUp

func ReferenceUp(
	b *behavior.Behavior,
) string

ReferenceUp is the path from the folder of b's reference page up to reference/behaviors, such as ../../ for hardware/disk/disk.md.

func Screen

func Screen(
	args []string,
) string

Screen is the screen of the first example of a behavior's method, as the CLI prints it, for a page that a person wrote: the osapi:output marker gives its arguments. They are the behavior, the method, then each host, as host, host:skipped or host:failed. One host is --target host; more are --target _all, and each answers in the order given. With --json last, it is the API's response, which the CLI prints with no table and no color.

func SettingFlags

func SettingFlags(
	fs *pflag.FlagSet,
	v *viper.Viper,
)

SettingFlags adds a flag to fs for every behavior setting, named by Key.Flag, such as --sysctl-dir, and binds it to the setting's key in v the way agent.go binds its own flags. Behaviors register in package init, before this runs, so every setting is here; v resolves the flag, then the environment, then the file, then the default when the config is read.

func Stdin

func Stdin(
	input any,
) string

Stdin is what the command line of Args reads from standard input: the literal value of input's secret field, or "" when it has none. A command reads one value from standard input, so a second literal is not read.

func Table

func Table(
	m *behavior.Method,
	r Result,
) cli.Section

Table renders a result the one way every behavior command prints: one row per result, the output fields as columns, and changed folded into the row's status for a write. A host that failed or was skipped is listed under the table with its reason. Each value prints as the command layer prints it, by its field's tags.

Types

type Flag

type Flag struct {
	// Name is the flag name: the field's JSON name with _ written as -.
	Name string
	// JSON is the field's JSON name, the key the input is sent under.
	JSON string
	// Kind is the field's kind: string, bool, int, float, or map for a
	// map[string]string, which takes key=value.
	Kind reflect.Kind
	// Usage is the field's doc tag.
	Usage string
	// Required is set when the field's validate tag has required.
	Required bool
	// Index is the field's index in the input type.
	Index int
}

Flag is one CLI flag derived from an input field.

func Flags

func Flags(
	in reflect.Type,
) []Flag

Flags derives one flag per exported field of the input type, in order. A field without a JSON name, or of a kind a flag cannot hold, is skipped.

type Result

type Result struct {
	JobID   string           `json:"job_id"`
	Results []map[string]any `json:"results"`
}

Result is what every behavior method answers: the job and one row per host, or per element when the method returns a list.

Directories

Path Synopsis
Package commandtest runs a behavior's generated commands for the gen/cli_public_test.go each one gets, with the SDK call faked.
Package commandtest runs a behavior's generated commands for the gen/cli_public_test.go each one gets, with the SDK call faked.

Jump to

Keyboard shortcuts

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