Documentation
¶
Overview ¶
Package cli provides libraries for building CLI commands and plugins.
Index ¶
- Constants
- Variables
- func BinFromPluginName(name string) string
- func BinTestFromPluginName(name string) string
- func FilterVersions(versions []string) (results []string)
- func GetCmdForPlugin(p *PluginInfo) *cobra.Command
- func GetTestCmdForPlugin(p *PluginInfo) *cobra.Command
- func GetUnmappedCmdForPlugin(p *PluginInfo) *cobra.Command
- func MakeArtifactName(pluginName string, arch Arch) string
- func MakeTestArtifactName(pluginName string, arch Arch) string
- func PluginNameFromBin(binName string) string
- func PluginNameFromTestBin(binName string) string
- func SelectVersionAlpha(versions []string) (v string)
- func SelectVersionAny(versions []string) (v string)
- func SelectVersionExperimental(versions []string) (v string)
- func SelectVersionStable(versions []string) (v string)
- func SetArch(a Arch)
- func TestPluginPathFromPluginPath(pluginPath string) string
- type Arch
- type CmdMap
- type CommandMapProcessor
- type MainUsage
- type Manifest
- type Plugin
- type PluginGroupManifest
- type PluginInfo
- type PluginInfoSorter
- type PluginNameTargetScope
- type PluginNameTargetScopeVersion
- type PluginScopeMetadata
- type Runner
- type VersionSelector
Constants ¶
const ( // BinNamePrefix is the prefix for tanzu plugin binary names. BinNamePrefix = "tanzu-plugin-" // TestBinNamePrefix is the prefix for tanzu plugin binary names. TestBinNamePrefix = "tanzu-plugin-test-" // ArtifactNamePrefix is the prefix for tanzu artifact names. ArtifactNamePrefix = "tanzu" )
const ( // ManifestFileName is the file name for the manifest. ManifestFileName = "manifest.yaml" // PluginManifestFileName is the file name for the plugin manifest. PluginManifestFileName = "plugin_manifest.yaml" // PluginGroupManifestFileName is the file name for the plugin manifest. PluginGroupManifestFileName = "plugin_group_manifest.yaml" // PluginDescriptorFileName is the file name for the plugin descriptor. PluginDescriptorFileName = "plugin.yaml" // AllPlugins is the keyword for all plugins. AllPlugins = "all" )
const CoreName = "core"
CoreName is the name of the core binary.
const SubCmdTemplate = `` /* 990-byte string literal not displayed */
SubCmdTemplate is the template for all core sub-commands.
Variables ¶
var ( // MinOSArch defines the minimum OS/ARCH combinations for which plugins need to be built MinOSArch = []Arch{LinuxAMD64, DarwinAMD64, WinAMD64} // AllOSArch defines all OS/ARCH combinations for which plugins can be built AllOSArch = []Arch{LinuxAMD64, DarwinAMD64, WinAMD64, LinuxARM64, DarwinARM64, WinARM64} // GOOS is the current go os. Defaults to runtime.GOOS but could be overridden. // The CLI code should always this variable instead of runtime.GOOS. GOOS = runtime.GOOS // GOARCH is the current go architecture. Defaults to runtime.GOARCH but is overridden // for scenarios like installing AMD64 plugins on an ARM64 machine using emulation. // The CLI code should always this variable instead of runtime.GOARCH. GOARCH = runtime.GOARCH )
var CoreDescriptor = plugin.PluginDescriptor{ Name: CoreName, Description: coreDescription, Version: buildinfo.Version, BuildSHA: buildinfo.SHA, }
CoreDescriptor is the core descriptor.
var CorePlugin = Plugin{ Name: CoreName, Description: coreDescription, }
CorePlugin is the core plugin.
var DefaultVersionSelector = SelectVersionStable
DefaultVersionSelector is the default version selector.
var SubCmdUsageFunc = func(c *cobra.Command) error { t, err := template.New("usage").Funcs(TemplateFuncs).Parse(SubCmdTemplate) if err != nil { return err } return t.Execute(os.Stdout, c) }
SubCmdUsageFunc is the usage func for all core sub-commands.
var TemplateFuncs = template.FuncMap{ "rpad": component.Rpad, "bold": component.Bold, "underline": component.Underline, "trimTrailingWhitespaces": component.TrimRightSpace, "beginsWith": component.BeginsWith, }
TemplateFuncs are the template usage funcs.
var VersionLatest = "latest"
VersionLatest is the latest version.
Functions ¶
func BinFromPluginName ¶
BinFromPluginName return a plugin binary name from its name.
func BinTestFromPluginName ¶
BinTestFromPluginName return a plugin binary name from its name.
func FilterVersions ¶
FilterVersions returns the list of valid versions depending on whether unstable versions are requested or not.
func GetCmdForPlugin ¶
func GetCmdForPlugin(p *PluginInfo) *cobra.Command
GetCmdForPlugin returns a cobra command for the plugin.
func GetTestCmdForPlugin ¶
func GetTestCmdForPlugin(p *PluginInfo) *cobra.Command
GetTestCmdForPlugin returns a cobra command for the test plugin.
func GetUnmappedCmdForPlugin ¶ added in v1.3.0
func GetUnmappedCmdForPlugin(p *PluginInfo) *cobra.Command
GetUnmappedCmdForPlugin returns a cobra command for the plugin unless there are remapping directives in the plugin info, in which case it will return nil instead.
func MakeArtifactName ¶
MakeArtifactName returns an artifact name for a plugin name.
func MakeTestArtifactName ¶
MakeTestArtifactName returns a test artifact name for a plugin name.
func PluginNameFromBin ¶
PluginNameFromBin returns a plugin name from the binary name.
func PluginNameFromTestBin ¶
PluginNameFromTestBin returns a plugin name from the test binary name.
func SelectVersionAlpha ¶
SelectVersionAlpha specifically returns only -alpha tagged releases
func SelectVersionAny ¶
SelectVersionAny returns the latest version from a list of versions including prereleases.
func SelectVersionExperimental ¶
SelectVersionExperimental includes all prerelease tagged plugin versions, minus +build versions
func SelectVersionStable ¶
SelectVersionStable returns the latest stable version from a list of versions. If there are no stable versions it will return an empty string.
Types ¶
type Arch ¶
type Arch string
Arch represents a system architecture.
const ( // Linux386 arch. Linux386 Arch = "linux_386" // LinuxAMD64 arch. LinuxAMD64 Arch = "linux_amd64" // LinuxARM64 arch. LinuxARM64 Arch = "linux_arm64" // DarwinAMD64 arch. DarwinAMD64 Arch = "darwin_amd64" // DarwinARM64 arch. DarwinARM64 Arch = "darwin_arm64" // Win386 arch. Win386 Arch = "windows_386" // WinAMD64 arch. WinAMD64 Arch = "windows_amd64" // WinARM64 arch. WinARM64 Arch = "windows_arm64" )
type CommandMapProcessor ¶ added in v1.4.0
type CommandMapProcessor interface {
// GetCommandMapForPlugin returns how the plugin's commands should be mapped
GetCommandMapForPlugin(p *PluginInfo) map[string]*cobra.Command
}
CommandMapProcessor process the plugin's command map to determine how commands should be mapped in the CLI command tree.
func NewCommandMapProcessor ¶ added in v1.4.0
func NewCommandMapProcessor(contextMap map[configtypes.ContextType]*configtypes.Context) CommandMapProcessor
NewCommandMapProcessor returns a CommandMapProcessor capable of processing command mapping directives from plugins
type MainUsage ¶
type MainUsage struct{}
MainUsage create the main usage display for tanzu cli.
func (*MainUsage) GenerateDescriptor ¶
GenerateDescriptor generates a descriptor
type Manifest ¶
type Manifest struct {
// Created is the time the manifest was created.
CreatedTime time.Time `json:"created,omitempty" yaml:"created,omitempty"`
// Plugins is a list of plugin artifacts available.
Plugins []Plugin `json:"plugins" yaml:"plugins"`
}
Manifest is stored in the repository which gives an inventory of the artifacts.
type Plugin ¶
type Plugin struct {
// Name is the name of the plugin.
Name string `json:"name" yaml:"name"`
// Target is the name of the plugin.
Target string `json:"target" yaml:"target"`
// Description is the plugin's description.
Description string `json:"description" yaml:"description"`
// Versions available for plugin.
Versions []string `json:"versions" yaml:"versions"`
}
Plugin is an installable CLI plugin.
type PluginGroupManifest ¶ added in v0.0.11
type PluginGroupManifest struct {
// Created is the time the manifest was created.
CreatedTime time.Time `json:"created,omitempty" yaml:"created,omitempty"`
// Plugins is a list of plugin artifacts including scope and version
Plugins []PluginNameTargetScopeVersion `json:"plugins" yaml:"plugins"`
}
PluginGroupManifest is used to parse metadata about Plugin Groups
type PluginInfo ¶
type PluginInfo struct {
// Name is the name of the plugin.
Name string `json:"name" yaml:"name"`
// Description is the plugin's description.
Description string `json:"description" yaml:"description"`
// Version of the plugin. Must be a valid semantic version https://semver.org/
Version string `json:"version" yaml:"version"`
// BuildSHA is the git commit hash the plugin was built with.
BuildSHA string `json:"buildSHA" yaml:"buildSHA"`
// Digest is the SHA256 hash of the plugin binary.
Digest string `json:"digest" yaml:"digest"`
// Command group for the plugin.
Group plugin.CmdGroup `json:"group" yaml:"group"`
// DocURL for the plugin.
DocURL string `json:"docURL" yaml:"docURL"`
// Hidden tells whether the plugin should be hidden from the help command.
Hidden bool `json:"hidden,omitempty" yaml:"hidden,omitempty"`
// CompletionType determines how command line completion will be determined.
CompletionType plugin.PluginCompletionType `json:"completionType" yaml:"completionType"`
// CompletionArgs contains the valid command line completion values if `CompletionType`
// is set to `StaticPluginCompletion`.
CompletionArgs []string `json:"completionArgs,omitempty" yaml:"completionArgs,omitempty"`
// CompletionCommand is the command to call from the plugin to retrieve a list of
// valid completion nouns when `CompletionType` is set to `DynamicPluginCompletion`.
CompletionCommand string `json:"completionCmd,omitempty" yaml:"completionCmd,omitempty"`
// Aliases are other text strings used to call this command
Aliases []string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
// InstallationPath is a relative installation path for a plugin binary.
// E.g., cluster/v0.3.2@sha256:...
InstallationPath string `json:"installationPath" yaml:"installationPath"`
// Discovery is the name of the discovery from where
// this plugin is discovered.
Discovery string `json:"discovery" yaml:"discovery"`
// Scope is the scope of the plugin. Stand-Alone or Context
Scope string `json:"scope" yaml:"scope"`
// Status is the current plugin installation status
Status string `json:"status" yaml:"status"`
// DiscoveredRecommendedVersion specifies the recommended version of the plugin that was discovered
DiscoveredRecommendedVersion string `json:"discoveredRecommendedVersion" yaml:"discoveredRecommendedVersion"`
// Target specifies the target of the plugin
Target configtypes.Target `json:"target" yaml:"target"`
// PostInstallHook is function to be run post install of a plugin.
PostInstallHook plugin.Hook `json:"-" yaml:"-"`
// DefaultFeatureFlags is default featureflags to be configured if missing when invoking plugin
DefaultFeatureFlags map[string]bool `json:"defaultFeatureFlags" yaml:"defaultFeatureFlags"`
// InvokedAs provides a specific mapping to how any command provided by this plugin should be invoked as.
// OBSOLETE: will be removed prior to the next official minor release
InvokedAs []string `json:"invokedAs,omitempty" yaml:"invokedAs,omitempty"`
// SupportedContextType specifies one of more ContextType that this plugin will specifically apply to.
// EXPERIMENTAL: subject to change prior to the next official minor release
SupportedContextType []configtypes.ContextType `json:"supportedContextType,omitempty" yaml:"supportedContextType,omitempty"`
// CommandMap specifies one or more CommandMapEntry's and describes how one
// or more parts of the plugin's command tree will be remapped in the Tanzu CLI
// EXPERIMENTAL: subject to change prior to the next official minor release
CommandMap []plugin.CommandMapEntry `json:"commandMap,omitempty" yaml:"commandMap,omitempty"`
}
PluginInfo contains information about a plugin binary
type PluginInfoSorter ¶
type PluginInfoSorter []PluginInfo
PluginInfoSorter sorts PluginInfo objects.
func (PluginInfoSorter) Len ¶
func (p PluginInfoSorter) Len() int
func (PluginInfoSorter) Less ¶
func (p PluginInfoSorter) Less(i, j int) bool
func (PluginInfoSorter) Swap ¶
func (p PluginInfoSorter) Swap(i, j int)
type PluginNameTargetScope ¶ added in v0.0.11
type PluginNameTargetScope struct {
// Name is the name of the plugin.
Name string `json:"name" yaml:"name"`
// Target is the name of the plugin.
Target string `json:"target" yaml:"target"`
// IsContextScoped determines if the plugin is context-scoped or standalone
IsContextScoped bool `json:"isContextScoped" yaml:"isContextScoped"`
}
PluginNameTargetScope defines the name, target and scope of a plugin
type PluginNameTargetScopeVersion ¶ added in v0.0.11
type PluginNameTargetScopeVersion struct {
// PluginNameTargetScope
PluginNameTargetScope `json:",inline" yaml:",inline"`
// Version is the version of the plugin.
Version string `json:"version" yaml:"version"`
}
PluginNameTargetScopeVersion defines the name, target, scope and version of a plugin
type PluginScopeMetadata ¶ added in v0.0.11
type PluginScopeMetadata struct {
// Plugins is a list of plugin artifacts including scope and version
Plugins []PluginNameTargetScope `json:"plugins" yaml:"plugins"`
}
PluginScopeMetadata is used to parse metadata about plugin and it's scope
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner is a plugin runner.
type VersionSelector ¶
VersionSelector returns a version from a set of versions.