meta

package
v0.0.0-...-a80d97c Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package meta contains intermediate types and utilities used to parse a Go AST and generate code to implement a cliche CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgSpec

type ArgSpec struct {
	// Start index, inclusive.
	Start int
	// End index, exclusive. A negative value indicates that all remaining
	// arguments beginning with Start should be consumed.
	End int
}

ArgSpec describes parsed positional arguments as defined in a facile struct tag.

func (*ArgSpec) String

func (spec *ArgSpec) String() string

String representation of the arg spec. Will be equivalent to the parsed tag, but may not be identical.

type Command

type Command struct {
	// Name of the command to be generated. This defaults to the name of the
	// package, unless overridden.
	Name string

	// Package name from which the  Command is sourced.
	Package string

	// Type name of the  Command implementation.
	Type string

	// Help output for the  Command. This will be displayed along with usage
	// information on the command line. By default, sourced from doc comment for
	// the package in which the wrapped Command will live.
	Help string

	// Description of the command. Should be short and human readable. By
	// default, sourced from the doc comment on the wrapped  Command type.
	Description string

	// Inputs describe the handling of struct fields on the wrapped Command
	// implementation as inputs on the command line. The inputs are derived from
	// struct tags, when set.
	Inputs []CommandInput
	// contains filtered or unexported fields
}

Command compiles details about how a type should be wrapped for cliche from the AST describing it. This type is used to execute a Go template, to generate the resulting Go source file.

func FromFile

func FromFile(from namedReader, typeName string) *Command

FromFile parses a Go AST from a file-like object and generates a Command for a type matching typeName. If errors are encountered, nil is returned.

func (*Command) Compile

func (meta *Command) Compile(n ast.Node) bool

Compile the AST of a Go file into command metadata. Designed to be used as an argument to ast.Inspect.

type CommandInput

type CommandInput struct {
	FieldName string
	Tag       Tag
	Doc       string
	Type      string
}

CommandInput contains details about how a Command's inputs should be mapped to the struct members of the implementing type.

type FlagSpec

type FlagSpec struct {
	Long  string
	Short string
}

FlagSpec describes parsed flags as defined in a facile struct tag.

func (*FlagSpec) Posixy

func (spec *FlagSpec) Posixy() bool

Posixy is true when the flag spec represents a flag which has both long and short flag forms.

func (*FlagSpec) String

func (spec *FlagSpec) String() string

String representation of the flag spec. Will be equivalent to the parsed tag, but may not be identical.

type Tag

type Tag string

Tag as on members of a struct which will be used to define cliche command inputs.

func (Tag) Arg

func (tag Tag) Arg() (*ArgSpec, bool)

Arg returns the argument specification from a Tag, if any.

func (Tag) Default

func (tag Tag) Default() (string, bool)

Default returns the string representation of the default value as specified in the struct tag.

func (Tag) Flag

func (tag Tag) Flag() (*FlagSpec, bool)

Flag returns the flag specifications from a Tag, if any.

Jump to

Keyboard shortcuts

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