commanddsl

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: 9 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 commanddsl is the command group under osapi cli: the commands that list, describe, scaffold, teach and check the local groups of the command DSL. The package is not named for the DSL's own package, command, which the generated code imports.

Index

Constants

View Source
const (
	LayerCommand     = "command"
	LayerEndpoint    = "endpoint"
	LayerBehavior    = "behavior"
	LayerHandWritten = "hand-written"
)

The layers that make a command.

Variables

View Source
var Group = command.Register(command.Define(
	"command",
	"List, describe and validate the local commands, and print their DSL",
	command.Under(command.ParentDSL),
	command.Long("A local command runs in the CLI process and calls no API, such as\n"+
		"`osapi controller token generate`. Its group is a definition in\n"+
		"`internal/cli/commands/<group>`, and its commands, flags, help and pages\n"+
		"come from it. A command that calls the API is an endpoint\n"+
		"(`osapi dsl endpoint`) or a behavior (`osapi dsl behavior`). These\n"+
		"commands read the definitions in the binary. Thus they need no config file\n"+
		"and no running controller."),
	command.Uses[Deps](),
	command.SubDoc(
		"spec",
		"Print the command DSL: each option, method, refinement, field tag and check",
	),
	command.SubDoc("method", "Show one method of a local group in full"),
	command.Method[ListInput, ListOutput]("list").
		Short("List each command of this binary, and the layer that made it").
		Long("The layer is `command` for a command of a local group, `endpoint` for a\n"+
			"command of an endpoint group, `behavior` for a command of a behavior, and\n"+
			"`hand-written` for a command in `cmd/` that no definition makes yet.").
		Example("").
		Prints(sampleList).
		Example("--json").
		Handle(List),
	command.Method[GetInput, GetOutput]("get").
		Short("Describe one group: its commands, and the flags and refusals of a local group").
		Long("`--name` is the command path of the group, such as `controller token` or `agent`: a\n"+
			"local group, or the group of an endpoint or a behavior. A command of a\n"+
			"local group also has its flags, each with the validate tag of its field,\n"+
			"and the inputs that its `.Fails` declares, which `TestRefusals` runs.").
		Example(`--name "controller token"`).
		Prints(sampleGet).
		Example("--name agent --json").
		Fails("no name", GetInput{}).
		Handle(Get),
	command.Method[MethodInput, MethodOutput]("get").
		Sub("method").
		Short("Show one method of a local group: its command, flags, output, examples and refusals").
		Long("Each flag has the validate tag of its field. `--json` has the JSON Schema of\n"+
			"the output. `osapi dsl behavior method get` and `osapi dsl endpoint\n"+
			"method get` show a method of a behavior and of an endpoint group the same\n"+
			"way.").
		Example(`--name "controller token" --method generate`).
		Prints(sampleMethod).
		Example(`--name "controller token" --method generate --json`).
		Fails("no name", MethodInput{Method: "list"}).
		Fails("no method", MethodInput{Name: "controller token"}).
		Handle(MethodGet),
	command.Method[CreateInput, CreateOutput]("create").
		Short("Write a new local group that builds and passes its tests").
		Long("It writes `internal/cli/commands/<name>/` in the osapi checkout in the\n"+
			"current directory, under the word of the root that `--under` names, and adds\n"+
			"its import to `internal/cli/commands/all`. A local group goes where it runs:\n"+
			"`controller`, `agent` or `nats` for the process or the files of that\n"+
			"component, or `dsl` for a command for authors. The\n"+
			"group has a list and a get, an empty `Deps` and the tests of its methods.\n"+
			"Then run the steps that it prints. While its `Deps` is empty, the CLI\n"+
			"needs no wiring. `osapi dsl command spec get` lists each part of the DSL.").
		Example(`--name widget --description "The widgets of this host" --under controller`).
		Prints(sampleCreate).
		Fails("no name", CreateInput{Description: "x", Under: command.ParentDSL}).
		Fails("no description", CreateInput{Name: "x", Under: command.ParentDSL}).
		Fails("no under", CreateInput{Name: "x", Description: "x"}).
		Fails("an under that is not a parent", CreateInput{
			Name: "x", Description: "x", Under: notAParent,
		}).
		Handle(Create),
	command.Method[SpecInput, SpecOutput]("get").
		Sub("spec").
		Short("Print the command DSL: each option, method, refinement, field tag and check").
		Long("Print each part of the command DSL, what it makes osapi do and when to use\n"+
			"it. The list comes from this binary. Thus it agrees with the build that\n"+
			"you run. Read it before you write a local group, then check the result\n"+
			"with `osapi dsl command validate`.").
		Example("").
		Prints(sampleSpec).
		Example("--json").
		Handle(Spec),
	command.Method[ValidateInput, ValidateOutput]("validate").
		Short("Check every local group against the rules of a definition, and the output of every group").
		Long("It prints each problem with its group, method, rule and message, then the\n"+
			"fix of each rule, and exits 1 when a rule fails. `osapi dsl command spec\n"+
			"get` describes each part of a group.\n\n"+
			"The rules:\n\n"+command.Checks.Help()).
		Example("").
		Prints(sampleValidate).
		Example("--json").
		Handle(Validate),
))

Group is the command group's definition.

Functions

This section is empty.

Types

type Command

type Command struct {
	Command string   `json:"command"`
	Method  string   `json:"method"`
	Short   string   `json:"short"           label:"Description"`
	Fails   []string `json:"fails,omitempty" label:"Refuses"`
	Flags   []Flag   `json:"flags,omitempty"`
}

Command is one command of a group: its flags and refusals, for a local group's.

type CreateInput

type CreateInput struct {
	Name        string         `json:"name"        validate:"required"      doc:"The group's name: its command under osapi"`
	Description string         `json:"description" validate:"required"      doc:"What the group is, in one line"`
	Under       command.Parent `` /* 143-byte string literal not displayed */
}

CreateInput is the name and the doc of the group to create.

type CreateOutput

type CreateOutput struct {
	Name  string `                    json:"name"`
	Files []File `                    json:"files"`
	Next  []Step `                    json:"next"`
	// contains filtered or unexported fields
}

CreateOutput is the files that create wrote, and the steps after it.

func Create

func Create(
	_ context.Context,
	d Deps,
	in CreateInput,
) (CreateOutput, error)

Create writes a new local group in the checkout, and is its files and the steps after it.

type Deps

type Deps struct {
	Root *cobra.Command
	Dir  string
	// IsBehavior is true for the name of a behavior, whose group made a
	// command of the behavior layer.
	IsBehavior func(name string) bool
}

Deps is what the methods use: the root command, whose tree list walks, the directory of the osapi checkout that create writes into, and which groups are behaviors.

type Example

type Example struct {
	Flags string `json:"flags" none:"(none)"`
	Doc   string `json:"doc"`
}

Example is one example of the command: its flags and what it shows.

type File

type File struct {
	Path string `json:"path"`
}

File is a file that create wrote.

type Flag

type Flag struct {
	Flag     string `json:"flag"`
	Short    string `json:"short,omitempty"`
	Type     string `json:"type"`
	Validate string `json:"validate"`
	Doc      string `json:"doc"             label:"Help"`
}

Flag is one flag of a local command, from a field of its input.

type GetInput

type GetInput struct {
	Name string `json:"name" validate:"required" doc:"The command path of the group, such as controller token or agent"`
}

GetInput names the group.

type GetOutput

type GetOutput struct {
	Name     string    `              json:"name"`
	Doc      string    `              json:"doc"      label:"Description"`
	Commands []Command `              json:"commands"                     table:"sections"`
	// contains filtered or unexported fields
}

GetOutput is a group and each of its commands.

func Get

func Get(
	_ context.Context,
	_ Deps,
	in GetInput,
) (GetOutput, error)

Get is the group with the command path, and each of its commands.

type ListInput

type ListInput struct{}

ListInput is the input of list, which has none.

type ListOutput

type ListOutput struct {
	Items       []Summary `                 json:"items"`
	Command     int       `                 json:"command"`
	Endpoint    int       `                 json:"endpoint"`
	Behavior    int       `                 json:"behavior"`
	HandWritten int       `                 json:"hand_written"`
	// contains filtered or unexported fields
}

ListOutput is each command of the binary, and how many each layer made.

func List

func List(
	_ context.Context,
	d Deps,
	_ ListInput,
) (ListOutput, error)

List is each command of the binary that runs, and the layer that made it.

type MethodInput

type MethodInput struct {
	Name   string `json:"name"   validate:"required" doc:"The command path of the local group, such as controller token"`
	Method string `json:"method" validate:"required" doc:"The method, such as list or roles get, from osapi dsl command get"`
}

MethodInput is the local group and the method to show.

type MethodOutput

type MethodOutput struct {
	Command    string           `               json:"command"`
	Method     string           `               json:"method"`
	Doc        string           `               json:"doc"                   label:"Description"`
	Long       string           `               json:"long,omitempty"        label:"Detail"`
	Process    bool             `               json:"process"`
	Flags      []Flag           `               json:"flags"                                     empty:"The command has no flags of its own."`
	ConfigKeys []string         `               json:"config_keys,omitempty" label:"Config keys"`
	OutputType string           `` /* 138-byte string literal not displayed */
	Results    []Result         `               json:"results"               label:"Output"`
	Says       string           `               json:"says,omitempty"`
	Examples   []Example        `               json:"examples"                                  empty:"The method has no example."`
	Refuses    []string         `               json:"refuses,omitempty"`
	Output     *behavior.Schema `` /* 149-byte string literal not displayed */
	// contains filtered or unexported fields
}

MethodOutput is one method of a local group in full: its command, its flags with their checks, its output, its examples and what it refuses. It is the shape of osapi dsl behavior method get and osapi controller endpoint method get. --json has the JSON Schema of the output.

func MethodGet

func MethodGet(
	_ context.Context,
	_ Deps,
	in MethodInput,
) (MethodOutput, error)

MethodGet is one method of a local group in full: its command, flags, output, examples and refusals. The group of an endpoint or a behavior has its own method get.

type Result

type Result = behaviordsl.Result

Result is one field of the output.

type SpecInput

type SpecInput struct{}

SpecInput is the input of spec, which has none.

type SpecOutput

type SpecOutput struct {
	Kinds []guide.Section `json:"kinds" table:"sections"`
}

SpecOutput is each kind of term of the DSL, with its terms.

func Spec

func Spec(
	_ context.Context,
	_ Deps,
	_ SpecInput,
) (SpecOutput, error)

Spec is each part of the command DSL, by kind.

type Step

type Step struct {
	Command string `json:"command"`
}

Step is a command to run after create.

type Summary

type Summary struct {
	Command string `json:"command"`
	Layer   string `json:"layer"`
	Group   string `json:"group,omitempty" table:"-"`
	Doc     string `json:"doc"                       label:"Description"`
}

Summary is one command, and the layer and group that made it.

type ValidateInput

type ValidateInput struct{}

ValidateInput is the input of validate, which has none.

type ValidateOutput

type ValidateOutput struct {
	Local    int               `                   json:"local"              label:"Local groups"`
	Groups   int               `                   json:"groups"`
	Valid    bool              `                   json:"valid"`
	Problems []command.Problem `                   json:"problems,omitempty"`
	Fixes    map[string]any    `                   json:"fixes,omitempty"`
	// contains filtered or unexported fields
}

ValidateOutput is each problem of each local group, and of the output of each group, and the fix of each rule that one breaks.

func Validate

func Validate(
	_ context.Context,
	_ Deps,
	_ ValidateInput,
) (ValidateOutput, error)

Validate checks each local group, and the output of each group. When a rule fails, it is the report with command.Fail: the report prints, then the command exits 1.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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