Skip to main content

Validate

Check every local group against the rules of a definition, and the output of every group.

It prints each problem with its group, method, rule and message, then the fix of each rule, and exits 1 when a rule fails. osapi dsl command spec get describes each part of a group.

The rules:

  • name: The group, each word of Under, each method and each Sub have a name of lowercase letters and digits, starting with a letter. Fix: Name the group for what its commands are about, such as token, and each method for what it does, such as generate.
  • methods: The group has at least one method. Fix: Add a method with command.Method, with its input and output types and its name.
  • unique: No two methods of a group have one name. Fix: Give each method its own name.
  • verb: The last word of each command is a verb (list, get, create, update, delete) or an action in command.Actions, as TestCommandShape holds each command to. Fix: Name the method for a verb, and put a noun before it with .Sub, such as key fingerprint. Add a word to command.Actions only for a real action, never for a noun.
  • root: A command goes where it runs and what it touches. Its first word is one of command.RootGroups: controller, agent or nats for the process or the files of that component on this host, config for the config that each component reads, dsl for the definitions of osapi, skill for the skills in the binary, sdk for the Go SDK in the binary, and client for a call to the API. A local group calls no API, so it is never under client. Only start and version are commands of the root itself. Fix: Put the group Under the command.Parent of the component whose process or files it works on, or of dsl for a command for authors. Add a word to command.RootGroups only as a decision of the owner, recorded in the specs cli.md.
  • help: Each method has a Short, and a method with input has an Example. Each flag that an Example names is a flag of the command: a field of its input, a key that its Flag names, or --json, --debug or --osapi-file. Fix: Add .Short("<what it does>") and .Example("--flag value") to the method, and spell each flag of an example as the command has it.
  • flag: Each value is a flag: the input is a struct, each field has a json name that is its flag with _ as -, no flag or in tag, and a type a flag holds (string, bool, int, []string, map[string]string, []byte, secret.Value, map[string]secret.Value, or a named string type of a closed set, such as command.Parent). A command takes no positional argument. Fix: Make the input a struct, tag each field json:"name", drop the flag and in tags, and use one of the flag types.
  • secret: No secret.Value input field is tagged telemetry:"attr": a span is no place for a secret. A secret flag takes a reference, secret://<vault>/<key>, or - to read the value from standard input, and the command resolves a reference itself. Fix: Remove telemetry:"attr" from the secret field.
  • doc: Each input field has a doc tag: the help of its flag. Fix: Add doc:"..." to the field: a capital letter first and no period at the end.
  • validate: Each input field has a validate tag: its rules, or omitempty for an optional field with none. Run checks the value against it before the handler runs, and a value that breaks it is a usage error. Fix: Add validate:"..." to the field, such as validate:"required,min=1,max=255", or validate:"omitempty" for an optional field with no other rule.
  • fails: Each rule of an input field has a .Fails input that breaks it, which the command refuses with a usage error, required included. A min of 1 on a string that is required or optional needs none: its only bad value is empty. Fix: Add .Fails("<what is wrong>", <Input>{...}) to the method, with the other fields valid and the field's value breaking the rule that the message names, such as a name of 256 characters for max=255.
  • subdoc: Each Sub segment that makes a command of its own, such as method in osapi dsl behavior method get, has a SubDoc: the one line of help of that command. Fix: Add command.SubDoc("segment", "...") to Define, with what the segment's commands do, such as Show one method of a behavior in full.
  • handler: The group Uses a type, and each method has a handler, func(context.Context, D, In) (Out, error), with D that type and In and Out the method's types. Fix: Add command.Uses[Deps]() to Define, and .Handle(fn) to each method, with the signature that the message names.
  • tag: Each tag key of an output field is one of command.KnownTags. Each render tag is one the output knows: -, bytes, age, time, duration, duration=ms, status or short=N with N above 0. An empty tag is on a list, and a title tag is on the blank field _ of the output type. Fix: Use a render value that osapi dsl command spec get lists, put empty on a list field, and put title on a field _ struct{} of the output type.
  • says: A method that answers with no body says what occurred: its name has a past tense, such as admitted for admit, or .Says gives the text. Fix: Add .Says("<state>") to the method, such as .Says("draining") for drain.
  • prints: Each method that prints a body, and is not a process, has an Example that Prints gives its output: a value of the method's output type, which its docs page shows as the CLI prints it. Each process has an Example that Logs gives the lines it writes when it starts, which its docs page shows as its log handler writes them. Prints and Logs follow the Example that they show. Fix: Add .Prints(sample) after the Example that it shows, with sample a value of the method's output type, in samples.go of the group. For a process, add .Logs(lines...) after its Example, with the lines in samples.go of the group.
osapi dsl command validate

Examples​

osapi dsl command validate
osapi dsl command validate --json

Result​

The command prints:

$ osapi dsl command validate
Validation:
  Local groups:  17
  Groups:        57
  Valid:         yes

With --json, the command prints:

{
"local": 17,
"groups": 57,
"valid": true
}

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml

Output tells how the result is printed, and what --json gives.