cmd

package
v4.18.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package cmd provides subcommands for the vervet CLI.

Index

Constants

This section is empty.

Variables

View Source
var BackstageCommand = cli.Command{
	Name: "backstage",
	Subcommands: []*cli.Command{{
		Name:  "update-catalog",
		Usage: "Update Backstage catalog-info.yaml with Vervet API versions",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "config",
				Aliases: []string{"c", "conf"},
				Usage:   "Project configuration file",
			},
		},
		Action: UpdateCatalog,
	}, {
		Name:  "preview-catalog",
		Usage: "Preview changes to Backstage catalog-info.yaml",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "config",
				Aliases: []string{"c", "conf"},
				Usage:   "Project configuration file",
			},
		},
		Action: PreviewCatalog,
	}, {
		Name:  "check-catalog",
		Usage: "Check for uncommitted changes in Backstage catalog-info.yaml",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "config",
				Aliases: []string{"c", "conf"},
				Usage:   "Project configuration file",
			},
		},
		Action: CheckCatalog,
	}},
}

BackstageCommand is the `vervet backstage` subcommand.

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{
		&BackstageCommand,
		&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 CheckCatalog added in v4.11.0

func CheckCatalog(ctx *cli.Context) error

CheckCatalog checks whether the catalog-info.yaml or tracked compiled versions it references have uncommitted changes. This is primarily useful in CI checks to make sure everything is checked into git for Backstage.

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 PreviewCatalog added in v4.11.0

func PreviewCatalog(ctx *cli.Context) error

PreviewCatalog updates the catalog-info.yaml from Vervet versions.

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.

func UpdateCatalog added in v4.11.0

func UpdateCatalog(ctx *cli.Context) error

UpdateCatalog updates the catalog-info.yaml from Vervet versions.

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