definitions

package
v0.0.0-...-5abf1c0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2019 License: MIT Imports: 6 Imported by: 0

README

definitions

Definitions is the guts and description of all commands and subcommands that are used in cf.

Program Design

Auto-generated Code

It is important to understand the relationship between the definitions.toml file that resides in the definitions directory, and the autogenerated.go file that resides in the cmd directory.

definitions.toml -- Contains a hand-written definition of each command-line command, their arguments, and their sub-commands.

autogenerated.go -- Contains golang code that does two things. First, it creates all Variables passed to the program using the command-line. Second, it generates the command and subcommand structure of the CLI.

definitions.go - Generates the go code using a series of templates. It is not pretty at all, but it converts the toml to definitions of cobra, which provides a robust framework for CLI tools.

Where are the API calls made?

cmd/root.go has a large switch-statement where all API calls to cloudflare-go are made. When necessary, this switch statement does any massaging necessary to make the arguments from the command line fit in to the expected method signature.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFile

func GenerateFile(fname string, outfile string) error

func ToFuncSigs

func ToFuncSigs(cmds []*Command) string

func ToSwitch

func ToSwitch(cmds []*Command) (string, error)

Types

type Command

type Command struct {
	Name             string
	Description      string
	ShortDescription string
	V4APIName        string
	Option           []Option
	Subcommands      []string
	TopLevel         bool
}

Command is a toplevel or subcommand. They have a set of subcommands if they are toplevel and V4APIName will be set to the name of the Switch case that is associated with the subcommand name. For Example: list-zones will have a switch case named ListZones, and ListZones should call the cloudflare-go method api.ListZones.

func LoadDefinitions

func LoadDefinitions(fname string) ([]*Command, error)

func (*Command) ToArgList

func (c *Command) ToArgList() string

func (*Command) ToArgListWithTypes

func (c *Command) ToArgListWithTypes() string

func (*Command) ToGo

func (c *Command) ToGo() (string, error)

func (*Command) ToVariables

func (c *Command) ToVariables() (string, error)

type CommandTemplateValues

type CommandTemplateValues struct {
	Name             string
	VariableName     string
	V4APIName        string
	Description      string
	ShortDescription string
	Option           []OptionTemplateValue

	Subcommands []string
	TopLevel    bool
}

type FileTemplateValues

type FileTemplateValues struct {
	Commands   string
	Variables  string
	SwitchList string
}

type Option

type Option struct {
	Name        string
	Type        string
	Description string
	Required    bool
}

Option is a command line option that can be passed to the program. Commands "have a" set of Options.

func (Option) ToOptionTemplateValue

func (o Option) ToOptionTemplateValue() OptionTemplateValue

type OptionTemplateValue

type OptionTemplateValue struct {
	TypeCap     string
	ArgName     string
	Name        string
	Default     string
	Description string
	Required    bool
}

type SwitchTemplateEntry

type SwitchTemplateEntry struct {
	Name    string
	ArgList string
}

Jump to

Keyboard shortcuts

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