{"modulePath":"github.com/osapi-io/osapi","version":"v0.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package command\n\nPackage 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/\\\u003cname\u003e/gen/cli.go.\n\n## Constants\n\n```go\nconst InternalFolder = \"internal\"\n```\nInternalFolder is the folder of the reference pages of the internal behaviors, which have no area, after the folders of the areas.\n\n```go\nconst InternalLabel = \"Internal\"\n```\nInternalLabel is the label of InternalFolder in the sidebar and the navbar.\n\n## Functions\n\n```go\nfunc Annotations(\n\tb *behavior.Behavior,\n\tm *behavior.Method,\n) map[string]string\n```\nAnnotations 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.\n\n```go\nfunc Args(\n\tinput any,\n) []string\n```\nArgs 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.\n\n```go\nfunc Columns(\n\tout reflect.Type,\n) []clicommand.Column\n```\nColumns 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.\n\n```go\nfunc ExampleFlags(\n\tinput any,\n) string\n```\nExampleFlags is the flags of an example's command line: --target and the flags of input, as the help and the pages write them.\n\n```go\nfunc GroupAnnotations(\n\tb *behavior.Behavior,\n) map[string]string\n```\nGroupAnnotations are the docs annotations of a behavior's own command: a note that links to the page of the behavior.\n\n```go\nfunc Output(\n\tb *behavior.Behavior,\n\tm *behavior.Method,\n) string\n```\nOutput 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.\n\n```go\nfunc Print(\n\tb *behavior.Behavior,\n\tmethod string,\n\tout any,\n\ttraceID string,\n)\n```\nPrint 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.\n\n```go\nfunc ReferenceFolder(\n\tb *behavior.Behavior,\n) string\n```\nReferenceFolder 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.\n\n```go\nfunc ReferencePage(\n\tb *behavior.Behavior,\n) string\n```\nReferencePage 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.\n\n```go\nfunc ReferenceUp(\n\tb *behavior.Behavior,\n) string\n```\nReferenceUp is the path from the folder of b's reference page up to reference/behaviors, such as ../../ for hardware/disk/disk.md.\n\n```go\nfunc Screen(\n\targs []string,\n) string\n```\nScreen 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.\n\n```go\nfunc SettingFlags(\n\tfs *pflag.FlagSet,\n\tv *viper.Viper,\n)\n```\nSettingFlags 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.\n\n```go\nfunc Stdin(\n\tinput any,\n) string\n```\nStdin 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.\n\n```go\nfunc Table(\n\tm *behavior.Method,\n\tr Result,\n) cli.Section\n```\nTable 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.\n\n## Types\n\n```go\ntype Flag struct {\n\t// Name is the flag name: the field's JSON name with _ written as -.\n\tName string\n\t// JSON is the field's JSON name, the key the input is sent under.\n\tJSON string\n\t// Kind is the field's kind: string, bool, int, float, or map for a\n\t// map[string]string, which takes key=value.\n\tKind reflect.Kind\n\t// Usage is the field's doc tag.\n\tUsage string\n\t// Required is set when the field's validate tag has required.\n\tRequired bool\n\t// Index is the field's index in the input type.\n\tIndex int\n}\n```\nFlag is one CLI flag derived from an input field.\n\n```go\nfunc Flags(\n\tin reflect.Type,\n) []Flag\n```\nFlags 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.\n\n```go\ntype Result struct {\n\tJobID   string           `json:\"job_id\"`\n\tResults []map[string]any `json:\"results\"`\n}\n```\nResult is what every behavior method answers: the job and one row per host, or per element when the method returns a list.\n\n","path":"github.com/osapi-io/osapi/internal/behavior/command","name":"command","synopsis":"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.","isRedistributable":true}
