cmd

package
v0.0.0-...-16d3bdc Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: MIT Imports: 10 Imported by: 6

Documentation

Overview

Package cmd provides reusable cobra commands

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGroupedCommands

func AddGroupedCommands(root *cobra.Command, group *cobra.Group, cmds ...*cobra.Command)

AddGroupedCommands is a helper function for adding command groups All commands will be added to root and associated with group

func NewGendocsCmd

func NewGendocsCmd(docs *embedutil.Documentation) *cobra.Command

NewGendocsCmd creates a gendocs command group that allows tools to output embedded documentation in various formats

func NewGenschemaCmd

func NewGenschemaCmd(schemaDefs fs.FS, associations []SchemaAssociation) *cobra.Command

NewGenschemaCmd creates the genschema command, which generates JSON Schema definitions.

The JSON Schema definitions must be made available in the schemaDefs fs.FS by embedding them. The go-common/pkg/genschema package provides the functionality to generate the JSON Schema definitions from Go types at build time.

The associations list is used to create a snippet of VS Code settings to enable YAML/JSON file validation using the generated schema definitions.

Example:

//go:embed schemas/*
var schemaDefs embed.FS

associations := []SchemaAssociation{
	{
		Definition: "schemas/project-schema.json",
		FileMatch:  []string{".act3-pt.yaml"},
	},
	{
		Definition: "schemas/template-shema.json",
		FileMatch:  []string{".act3-template.yaml"},
	},
}

NewGenschemaCmd(schemaDefs, associations)

func NewInfoCmd

func NewInfoCmd(docs *embedutil.Documentation) *cobra.Command

NewInfoCmd creates an info command that allows the viewing of embedded documentation in the terminal, converted to Markdown

func NewVersionCmd

func NewVersionCmd(info version.Info) *cobra.Command

NewVersionCmd creates a new "version" subcommand

Types

type SchemaAssociation

type SchemaAssociation struct {
	Definition string   // Path to the schema definition
	FileMatch  []string // List of filenames to validate with the schema
}

SchemaAssociation associates a JSON Schema definition to the files it validates

Example:

associations := []SchemaAssociation{
	{
		Definition: "project-schema.json",
		FileMatch:  []string{".act3-pt.yaml"},
	},
	{
		Definition: "template-shema.json",
		FileMatch:  []string{".act3-template.yaml"},
	},
}

Jump to

Keyboard shortcuts

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