cmd

package
v4.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package cmd provides subcommands for the vervet CLI.

Index

Constants

This section is empty.

Variables

View Source
var BuildCommand = cli.Command{
	Name:      "build",
	Usage:     "Build versioned resources into versioned OpenAPI specs",
	ArgsUsage: "[input resources root] [output api root]",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:    "config",
			Aliases: []string{"c", "conf"},
			Usage:   "Project configuration file",
		},
		&cli.BoolFlag{
			Name:  "lint",
			Usage: "Enable linting during build",
			Value: true,
		},
		&cli.StringFlag{
			Name:    "include",
			Aliases: []string{"I"},
			Usage:   "OpenAPI specification to include in build output",
		},
	},
	Action: Build,
}

BuildCommand is the `vervet build` subcommand.

View Source
var CLIApp = cli.App{
	Name:    "vervet",
	Usage:   "OpenAPI resource versioning tool",
	Version: "develop",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:  "debug",
			Usage: "Turn on debug logging",
		},
	},
	Commands: []*cli.Command{
		&BuildCommand,
		&GenerateCommand,
		&LintCommand,
		&LocalizeCommand,
		&ResourceCommand,
		&ResolveCommand,
	},
}
View Source
var GenerateCommand = cli.Command{
	Name:      "generate",
	Usage:     "Generate artifacts from resource versioned OpenAPI specs",
	ArgsUsage: "<generator> [<generator2>...]",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:    "config",
			Aliases: []string{"c", "conf"},
			Usage:   "Project configuration file",
		},
		&cli.BoolFlag{
			Name:    "dry-run",
			Aliases: []string{"n"},
			Usage:   "Dry-run, listing files that would be generated",
		},
		&cli.StringFlag{
			Name:    "generators",
			Aliases: []string{"g", "gen", "generator"},
			Usage:   "Generators definition file",
		},
	},
	Action: Generate,
}

GenerateCommand is the `vervet generate` subcommand.

View Source
var LintCommand = cli.Command{
	Name:      "lint",
	Usage:     "Lint  versioned resources",
	ArgsUsage: "[input resources root] [output api root]",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:    "config",
			Aliases: []string{"c", "conf"},
			Usage:   "Project configuration file",
		},
	},
	Action: Lint,
}

LintCommand is the `vervet lint` subcommand.

View Source
var LocalizeCommand = cli.Command{
	Name:      "localize",
	Aliases:   []string{"localise"},
	Usage:     "Localize references and validate a single OpenAPI spec file",
	ArgsUsage: "[spec.yaml file]",
	Action:    Localize,
}

LocalizeCommand is the `vervet localize` subcommand

View Source
var ResolveCommand = cli.Command{
	Name:      "resolve",
	Usage:     "Aggregate, render and validate resource specs at a particular version",
	ArgsUsage: "[resource root]",
	Flags: []cli.Flag{
		&cli.StringFlag{Name: "at"},
	},
	Action: Resolve,
}

ResolveCommand is the `vervet resolve` subcommand.

View Source
var ResourceCommand = cli.Command{
	Name:    "resource",
	Aliases: []string{"rc"},
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:    "config",
			Aliases: []string{"c", "conf"},
			Usage:   "Project configuration file",
		},
	},
	Subcommands: []*cli.Command{{
		Name:      "files",
		Usage:     "List OpenAPI files of versioned resources in a vervet project",
		ArgsUsage: "[api [resource]]",
		Action:    ResourceFiles,
	}, {
		Name:      "info",
		Usage:     "Information about versioned resources in a vervet project",
		ArgsUsage: "[api [resource]]",
		Action:    ResourceShow,
	}},
}

ResourceCommand is the `vervet resource` subcommand.

View Source
var Scaffold = cli.Command{
	Name: "scaffold",
	Subcommands: []*cli.Command{{
		Name:      "init",
		Usage:     "Initialize a new project from a scaffold",
		ArgsUsage: "[path to scaffold directory]",
		Flags: []cli.Flag{
			&cli.BoolFlag{
				Name:    "force",
				Aliases: []string{"f", "overwrite"},
				Usage:   "Overwrite existing files",
			},
		},
		Action: ScaffoldInit,
	}},
}

Scaffold is the `vervet scaffold` subcommand.

View Source
var Vervet = NewApp(&CLIApp, VervetParams{
	Stdin:  os.Stdin,
	Stdout: os.Stdout,
	Stderr: os.Stderr,
	Prompt: Prompt{},
})

Vervet is the vervet application with the CLI application.

Functions

func Build

func Build(ctx *cli.Context) error

Build compiles versioned resources into versioned API specs.

func Generate

func Generate(ctx *cli.Context) error

Generate executes code generators against OpenAPI specs.

func Lint

func Lint(ctx *cli.Context) error

Lint checks versioned resources against linting rules.

func Localize

func Localize(ctx *cli.Context) error

Localize references and validate a single OpenAPI spec file

func Resolve

func Resolve(ctx *cli.Context) error

Resolve aggregates, renders and validates resource specs at a particular version.

func ResourceFiles

func ResourceFiles(ctx *cli.Context) error

ResourceFiles is a command that lists all versioned OpenAPI spec files of matching resources. It takes optional arguments to filter the output: api resource

func ResourceShow

func ResourceShow(ctx *cli.Context) error

ResourceShow is a command that lists all the versions of matching resources. It takes optional arguments to filter the output: api resource

func ScaffoldInit

func ScaffoldInit(ctx *cli.Context) error

ScaffoldInit creates a new project configuration from a provided scaffold directory.

Types

type Prompt

type Prompt struct{}

Prompt is the default interactive prompt for vervet.

func (Prompt) Confirm

func (p Prompt) Confirm(label string) (bool, error)

Confirm implements VervetPrompt.Confirm

func (Prompt) Entry

func (p Prompt) Entry(label string) (string, error)

Entry implements VervetPrompt.Entry

func (Prompt) Select

func (p Prompt) Select(label string, items []string) (string, error)

Select implements VervetPrompt.Select

type VervetApp

type VervetApp struct {
	App    *cli.App
	Params VervetParams
}

VervetApp contains the cli Application.

func NewApp

func NewApp(app *cli.App, vp VervetParams) *VervetApp

NewApp returns a new VervetApp with the provided params.

func (*VervetApp) Run

func (v *VervetApp) Run(args []string) error

Run runs the cli.App with the Vervet config params.

type VervetParams

type VervetParams struct {
	Stdin  io.ReadCloser
	Stdout io.WriteCloser
	Stderr io.WriteCloser
	Prompt VervetPrompt
}

VervetParams contains configuration parameters for the Vervet CLI application.

type VervetPrompt

type VervetPrompt interface {
	Confirm(label string) (bool, error)                  // Confirm y/n an action
	Entry(label string) (string, error)                  // Gather a freeform entry in response to a question
	Select(label string, items []string) (string, error) // Select from a limited number of entries
}

VervetPrompt defines the interface for interactive prompts in vervet.

Jump to

Keyboard shortcuts

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