cmd

package
v7.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 21 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:     buildFlags,
	Action:    CombinedBuild,
}

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,
		&RetroBuildCommand,
		&SimpleBuildCommand,
		&FilterCommand,
		&GenerateCommand,
		&LocalizeCommand,
		&ResourceCommand,
		&ResolveCommand,
	},
}
View Source
var FilterCommand = cli.Command{
	Name:      "filter",
	Usage:     "Filter an OpenAPI document",
	ArgsUsage: "[spec.yaml file]",
	Flags: []cli.Flag{
		&cli.StringSliceFlag{Name: "include-paths", Aliases: []string{"I"}},
		&cli.StringSliceFlag{Name: "exclude-paths", Aliases: []string{"X"}},
	},
	Action: Filter,
}

FilterCommand is the `vervet filter` subcommand.

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 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 RetroBuildCommand = cli.Command{
	Name:      "retrobuild",
	Usage:     "Build versioned resources into versioned OpenAPI specs",
	ArgsUsage: "[input resources root] [output api root]",
	Flags:     buildFlags,
	Action:    RetroBuild,
}

RetroBuild is the `vervet build` 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 SimpleBuildCommand = cli.Command{
	Name:      "simplebuild",
	Usage:     "Build versioned resources into versioned OpenAPI specs",
	ArgsUsage: "[input resources root]",
	Flags:     buildFlags,
	Action:    SimpleBuild,
}
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 CheckCatalog

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 CombinedBuild added in v7.3.0

func CombinedBuild(ctx *cli.Context) error

CombinedBuild compiles versioned resources into versioned API specs invokes retorbuild and simplebuild based on the context.

func Filter

func Filter(ctx *cli.Context) error

Filter an OpenAPI spec file.

func Generate

func Generate(ctx *cli.Context) error

Generate executes code generators against OpenAPI specs.

func Localize

func Localize(ctx *cli.Context) error

Localize references and validate a single OpenAPI spec file.

func PreviewCatalog

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 RetroBuild added in v7.3.0

func RetroBuild(ctx *cli.Context) error

RetroBuild compiles versioned resources into versioned API specs using the older versioning strategy. This is used for regenerating old versioned API specs only.

func ScaffoldInit

func ScaffoldInit(ctx *cli.Context) error

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

func SimpleBuild added in v7.2.0

func SimpleBuild(ctx *cli.Context) error

SimpleBuild compiles versioned resources into versioned API specs using the rolled up versioning strategy.

func UpdateCatalog

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