Documentation
¶
Overview ¶
Package cli provides libraries for building CLI commands and plugins.
Index ¶
- Constants
- Variables
- func BinFromPluginName(name string) string
- func FilterVersions(versions []string) (results []string)
- func GetPluginCmd(p *PluginInfo) *cobra.Command
- func MakeArtifactName(pluginName string, arch Arch) string
- func PluginNameFromBin(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 TestPluginPathFromPluginPath(pluginPath string) string
- type Arch
- type CmdMap
- type MainUsage
- type Manifest
- type Plugin
- type PluginInfo
- type Runner
- type VersionSelector
Constants ¶
const ( // ManifestFileName is the file name for the manifest. ManifestFileName = "manifest.yaml" // PluginDescriptorFileName is the file name for the plugin descriptor. PluginDescriptorFileName = "plugin.yaml" // DefaultArtifactsDirectory is the root artifacts directory DefaultArtifactsDirectory = "artifacts" )
const ( // BinNamePrefix is the prefix for tanzu plugin binary names. BinNamePrefix = "tanzu-plugin-" // ArtifactNamePrefix is the prefix for tanzu artifact names. ArtifactNamePrefix = "tanzu" )
const CoreName = "core"
CoreName is the name of the core binary.
const (
// DefaultOSArch defines default OS/ARCH
DefaultOSArch = "darwin-amd64 linux-amd64 windows-amd64"
)
const SubCmdTemplate = `` /* 988-byte string literal not displayed */
SubCmdTemplate is the template for plugin commands.
Variables ¶
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 a plugin.
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 FilterVersions ¶
FilterVersions returns the list of valid versions depending on whether unstable versions are requested or not.
func GetPluginCmd ¶
func GetPluginCmd(p *PluginInfo) *cobra.Command
GetPluginCmd returns a cobra command for the plugin.
func MakeArtifactName ¶
MakeArtifactName returns an artifact name for a plugin name.
func PluginNameFromBin ¶
PluginNameFromBin returns a plugin name from the 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" )
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" yaml:"created"`
// Plugins is a list of plugin artifacts available.
Plugins []Plugin `json:"plugins" yaml:"plugins"`
// Deprecated: Version of the root CLI.
Version string `json:"version" yaml:"version"`
// CoreVersion of the root CLI.
CoreVersion string `json:"coreVersion" yaml:"coreVersion"`
}
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"`
// 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 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"`
// Discovery is the name of the discovery from where
// this plugin is discovered.
Discovery string `json:"discovery"`
// Scope is the scope of the plugin. Stand-Alone or Context
Scope string `json:"scope"`
// Status is the current plugin installation status
Status string `json:"status"`
// DiscoveredRecommendedVersion specifies the recommended version of the plugin that was discovered
DiscoveredRecommendedVersion string `json:"discoveredRecommendedVersion"`
// Target specifies the target of the plugin
Target cliv1alpha1.Target `json:"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"`
}
PluginInfo contains information about a plugin binary
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.