Documentation ¶
Overview ¶
Package cli provides libraries for building CLI commands and plugins.
Index ¶
- Constants
- Variables
- func AppendClientMetadata(ctx context.Context) context.Context
- func ApplyDefaultConfig(p *cliv1alpha1.PluginDescriptor)
- func AskForConfirmation(message string) error
- func BinFromPluginName(name string) string
- func BinTestFromPluginName(name string) string
- func Clean() error
- func CleanCatalogCache() error
- func DeletePlugin(name string) error
- func DeprecateCommand(cmd *cobra.Command, removalVersion string)
- func DeprecateCommandWithAlternative(cmd *cobra.Command, removalVersion, alternative string)
- func DeprecateFlag(cmd *cobra.Command, flag, removalVersion string)
- func DeprecateFlagWithAlternative(cmd *cobra.Command, flag, removalVersion, alternative string)
- func DescribePlugin(name string) (desc *cliv1alpha1.PluginDescriptor, err error)
- func DescribeTestPlugin(pluginName string) (desc *cliv1alpha1.PluginDescriptor, err error)
- func EnsureDistro(repos *MultiRepo) error
- func EnsureTest(plugin *cliv1alpha1.PluginDescriptor, repos *MultiRepo) error
- func EnsureTests(repos *MultiRepo, exclude ...string) error
- func FilterVersions(versions []string) (results []string)
- func GetCmd(p *cliv1alpha1.PluginDescriptor) *cobra.Command
- func HasPluginUpdate(repo Repository, versionSelector VersionSelector, ...) (update bool, version string, err error)
- func HasUpdate(repo Repository) (update bool, version string, err error)
- func InitializePlugin(name string) error
- func InstallAllMulti(repos *MultiRepo) error
- func InstallAllPlugins(repo Repository) error
- func InstallPlugin(name, version string, repo Repository) error
- func InstallTest(pluginName, version string, repo Repository) error
- func IsDistributionSatisfied(desc []*cliv1alpha1.PluginDescriptor) bool
- func ListPlugins(exclude ...string) (list []*cliv1alpha1.PluginDescriptor, err error)
- func ListTestPlugins() (list []*cliv1alpha1.PluginDescriptor, err error)
- func MakeArtifactName(pluginName string, arch Arch) string
- func MakeTestArtifactName(pluginName string, arch Arch) string
- func NewCatalog() (*cliv1alpha1.Catalog, error)
- func NewTestFor(pluginName string) *cliv1alpha1.PluginDescriptor
- func ParsePluginDescriptor(path string) (desc cliv1alpha1.PluginDescriptor, err error)
- 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 TestCmd(p *cliv1alpha1.PluginDescriptor) *cobra.Command
- func Update(repo Repository) error
- func UpgradePlugin(name, version string, repo Repository) error
- func ValidatePlugin(p *cliv1alpha1.PluginDescriptor) (err error)
- func WithClientMetadata() func(ctx context.Context) context.Context
- type Arch
- type CmdMap
- type GCPBucketRepository
- func (g *GCPBucketRepository) Describe(name string) (plugin Plugin, err error)
- func (g *GCPBucketRepository) Fetch(name, version string, arch Arch) ([]byte, error)
- func (g *GCPBucketRepository) FetchTest(name, version string, arch Arch) ([]byte, error)
- func (g *GCPBucketRepository) List() (plugins []Plugin, err error)
- func (g *GCPBucketRepository) Manifest() (manifest Manifest, err error)
- func (g *GCPBucketRepository) Name() string
- func (g *GCPBucketRepository) VersionSelector() VersionSelector
- type LocalRepository
- func (l *LocalRepository) Describe(name string) (plugin Plugin, err error)
- func (l *LocalRepository) Fetch(name, version string, arch Arch) ([]byte, error)
- func (l *LocalRepository) FetchTest(name, version string, arch Arch) ([]byte, error)
- func (l *LocalRepository) List() (plugins []Plugin, err error)
- func (l *LocalRepository) Manifest() (manifest Manifest, err error)
- func (l *LocalRepository) Name() string
- func (l *LocalRepository) VersionSelector() VersionSelector
- type MainUsage
- type Manifest
- type MultiRepo
- func (m *MultiRepo) AddRepository(repo Repository)
- func (m *MultiRepo) Find(name string) (r Repository, err error)
- func (m *MultiRepo) GetRepository(name string) (Repository, error)
- func (m *MultiRepo) ListPlugins() (mp map[string][]Plugin, err error)
- func (m *MultiRepo) RemoveRepository(name string)
- type Option
- type Plugin
- type PluginState
- type Repository
- func HasPluginUpdateIn(repos *MultiRepo, p *cliv1alpha1.PluginDescriptor) (update bool, repo Repository, version string, err error)
- func LoadRepositories(c *configv1alpha1.ClientConfig) []Repository
- func NewDefaultRepository() Repository
- func NewGCPBucketRepository(options ...Option) Repository
- func NewLocalRepository(name, localPath string, options ...Option) Repository
- 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 ( // Name of the CLI. Name = "tanzu" // ClientName of the CLI. ClientName = "tanzu-cli" )
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" // ManifestFileName is the file name for the manifest. ManifestFileName = "manifest.yaml" // PluginFileName is the file name for the plugin descriptor. PluginFileName = "plugin.yaml" // DefaultArtifactsDirectory is the root artifacts directory DefaultArtifactsDirectory = "artifacts" // AllPlugins is the keyword for all plugins. AllPlugins = "all" // DefaultManifestQueryTimeout is max time to wait for querying for a plugin manifest DefaultManifestQueryTimeout = 5 * time.Second )
const CoreName = "core"
CoreName is the name of the core binary.
const ( // EnvPluginStateKey is the environment key that contains the path to the // plugin state file. EnvPluginStateKey = "TANZU_STATE" )
const SubCmdTemplate = `` /* 988-byte string literal not displayed */
SubCmdTemplate is the template for plugin commands.
Variables ¶
var ( // BuildDate is the date the CLI was built. // Deprecated: use github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo.Date BuildDate = buildinfo.Date // BuildSHA is the git sha the CLI was built with. // Deprecated: use github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo.SHA BuildSHA = buildinfo.SHA // BuildVersion is the version the CLI was built with. // Deprecated: use github.com/vmware-tanzu/tanzu-framework/pkg/v1/buildinfo.Version BuildVersion = buildinfo.Version )
var CoreDescriptor = cliv1alpha1.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 DefaultDistro = []string{"login", "pinniped-auth", "cluster", "management-cluster", "kubernetes-release", "package", "secret"}
DefaultDistro is the core set of plugins that should be included with the CLI.
var DefaultLocalRepository = &LocalRepository{ path: fmt.Sprintf("./%s", DefaultArtifactsDirectory), }
DefaultLocalRepository is the default local repository.
var ( // DefaultPluginRoot is the default plugin root. DefaultPluginRoot = filepath.Join(xdg.DataHome, "tanzu-cli") )
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": rpad,
"bold": bold,
"underline": underline,
"trimTrailingWhitespaces": trimRightSpace,
"beginsWith": beginsWith,
}
TemplateFuncs are the template usage funcs.
var VersionLatest = "latest"
VersionLatest is the latest version.
Functions ¶
func AppendClientMetadata ¶
AppendClientMetadata adds client metadata.
func ApplyDefaultConfig ¶
func ApplyDefaultConfig(p *cliv1alpha1.PluginDescriptor)
ApplyDefaultConfig applies default configurations to plugin descriptor.
func AskForConfirmation ¶
AskForConfirmation is used to prompt the user to confirm or deny a choice
func BinFromPluginName ¶
BinFromPluginName return a plugin binary name from its name.
func BinTestFromPluginName ¶
BinTestFromPluginName return a plugin binary name from its name.
func DeprecateCommand ¶
DeprecateCommand marks the command as deprecated and adds deprecation message.
func DeprecateCommandWithAlternative ¶
DeprecateCommandWithAlternative marks the commands as deprecated and adds deprecation message with an alternative.
func DeprecateFlag ¶
DeprecateFlag marks the flag as deprecated and hidden with a deprecation message.
func DeprecateFlagWithAlternative ¶
DeprecateFlagWithAlternative marks the flag as deprecated and hidden with deprecation message recommending an alternative flag to use.
func DescribePlugin ¶
func DescribePlugin(name string) (desc *cliv1alpha1.PluginDescriptor, err error)
DescribePlugin describes a plugin.
func DescribeTestPlugin ¶
func DescribeTestPlugin(pluginName string) (desc *cliv1alpha1.PluginDescriptor, err error)
DescribeTestPlugin describes a test plugin.
func EnsureDistro ¶
EnsureDistro ensures that all the distro plugins are installed.
func EnsureTest ¶
func EnsureTest(plugin *cliv1alpha1.PluginDescriptor, repos *MultiRepo) error
EnsureTest ensures the right version of the test is present for the plugin.
func EnsureTests ¶
EnsureTests ensures the plugin tests are installed.
func FilterVersions ¶
FilterVersions returns the list of valid versions depending on whether unstable versions are requested or not.
func GetCmd ¶
func GetCmd(p *cliv1alpha1.PluginDescriptor) *cobra.Command
GetCmd returns a cobra command for the plugin.
func HasPluginUpdate ¶
func HasPluginUpdate(repo Repository, versionSelector VersionSelector, p *cliv1alpha1.PluginDescriptor) (update bool, version string, err error)
HasPluginUpdate tells whether the plugin descriptor has an update available in the given repository.
func HasUpdate ¶
func HasUpdate(repo Repository) (update bool, version string, err error)
HasUpdate tells whether the core plugin has an update.
func InitializePlugin ¶
InitializePlugin initializes the plugin configuration
func InstallAllMulti ¶
InstallAllMulti installs all the plugins at the latest version in all the given repositories.
func InstallAllPlugins ¶
func InstallAllPlugins(repo Repository) error
InstallAllPlugins plugins with the given version finder.
func InstallPlugin ¶
func InstallPlugin(name, version string, repo Repository) error
InstallPlugin installs a plugin from the given repository.
func InstallTest ¶
func InstallTest(pluginName, version string, repo Repository) error
InstallTest installs the test for the given plugin name
func IsDistributionSatisfied ¶
func IsDistributionSatisfied(desc []*cliv1alpha1.PluginDescriptor) bool
IsDistributionSatisfied tells if a distribution is satisfied by the plugin list.
func ListPlugins ¶
func ListPlugins(exclude ...string) (list []*cliv1alpha1.PluginDescriptor, err error)
ListPlugins returns the available plugins.
func ListTestPlugins ¶
func ListTestPlugins() (list []*cliv1alpha1.PluginDescriptor, err error)
ListTestPlugins returns the available test plugins.
func MakeArtifactName ¶
MakeArtifactName returns an artifact name for a plugin name.
func MakeTestArtifactName ¶
MakeTestArtifactName returns a test artifact name for a plugin name.
func NewCatalog ¶
func NewCatalog() (*cliv1alpha1.Catalog, error)
NewCatalog creates an instance of Catalog.
func NewTestFor ¶
func NewTestFor(pluginName string) *cliv1alpha1.PluginDescriptor
NewTestFor creates a plugin descriptor for a test plugin.
func ParsePluginDescriptor ¶
func ParsePluginDescriptor(path string) (desc cliv1alpha1.PluginDescriptor, err error)
ParsePluginDescriptor parses a plugin descriptor in yaml.
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.
func TestCmd ¶
func TestCmd(p *cliv1alpha1.PluginDescriptor) *cobra.Command
TestCmd returns a cobra command for the plugin.
func UpgradePlugin ¶
func UpgradePlugin(name, version string, repo Repository) error
UpgradePlugin upgrades a plugin from the given repository.
func ValidatePlugin ¶
func ValidatePlugin(p *cliv1alpha1.PluginDescriptor) (err error)
ValidatePlugin validates the plugin descriptor.
Types ¶
type GCPBucketRepository ¶
type GCPBucketRepository struct {
// contains filtered or unexported fields
}
GCPBucketRepository is a artifact repository utilizing a GCP bucket.
func (*GCPBucketRepository) Describe ¶
func (g *GCPBucketRepository) Describe(name string) (plugin Plugin, err error)
Describe a plugin.
func (*GCPBucketRepository) Fetch ¶
func (g *GCPBucketRepository) Fetch(name, version string, arch Arch) ([]byte, error)
Fetch an artifact.
func (*GCPBucketRepository) FetchTest ¶
func (g *GCPBucketRepository) FetchTest(name, version string, arch Arch) ([]byte, error)
FetchTest fetches a test artifact.
func (*GCPBucketRepository) List ¶
func (g *GCPBucketRepository) List() (plugins []Plugin, err error)
List available plugins.
func (*GCPBucketRepository) Manifest ¶
func (g *GCPBucketRepository) Manifest() (manifest Manifest, err error)
Manifest retrieves the manifest for a repository.
func (*GCPBucketRepository) Name ¶
func (g *GCPBucketRepository) Name() string
Name of the repository.
func (*GCPBucketRepository) VersionSelector ¶
func (g *GCPBucketRepository) VersionSelector() VersionSelector
VersionSelector returns the current default version finder.
type LocalRepository ¶
type LocalRepository struct {
// contains filtered or unexported fields
}
LocalRepository is a artifact repository utilizing a local host os.
func (*LocalRepository) Describe ¶
func (l *LocalRepository) Describe(name string) (plugin Plugin, err error)
Describe a plugin.
func (*LocalRepository) Fetch ¶
func (l *LocalRepository) Fetch(name, version string, arch Arch) ([]byte, error)
Fetch an artifact.
func (*LocalRepository) FetchTest ¶
func (l *LocalRepository) FetchTest(name, version string, arch Arch) ([]byte, error)
FetchTest fetches an artifact test.
func (*LocalRepository) List ¶
func (l *LocalRepository) List() (plugins []Plugin, err error)
List available plugins.
func (*LocalRepository) Manifest ¶
func (l *LocalRepository) Manifest() (manifest Manifest, err error)
Manifest returns the manifest for a local repository.
func (*LocalRepository) VersionSelector ¶
func (l *LocalRepository) VersionSelector() VersionSelector
VersionSelector returns the current default version finder.
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.
func (*Manifest) GetCoreVersion ¶
GetCoreVersion returns the core version in a backwards compatible manner.
type MultiRepo ¶
type MultiRepo struct {
// contains filtered or unexported fields
}
MultiRepo is a multiple
func NewMultiRepo ¶
func NewMultiRepo(repositories ...Repository) *MultiRepo
NewMultiRepo returns a new multirepo.
func (*MultiRepo) AddRepository ¶
func (m *MultiRepo) AddRepository(repo Repository)
AddRepository to known.
func (*MultiRepo) Find ¶
func (m *MultiRepo) Find(name string) (r Repository, err error)
Find a repository for the given plugin name.
func (*MultiRepo) GetRepository ¶
func (m *MultiRepo) GetRepository(name string) (Repository, error)
GetRepository returns a repository.
func (*MultiRepo) ListPlugins ¶
ListPlugins across the repositories.
func (*MultiRepo) RemoveRepository ¶
RemoveRepository removes a repo.
type Option ¶
type Option func(o *optionsConfig)
Option is a filesystem store option.
func WithDistro ¶
func WithDistro(distro cliv1alpha1.Distro) Option
WithDistro sets the distro that should be installed with the CLI
func WithGCPBucket ¶
WithGCPBucket sets the gcp bucket to use for the artifact repository.
func WithGCPRootPath ¶
WithGCPRootPath sets the gcp bucket root path to use for the artifact repository.
func WithPluginRoot ¶
WithPluginRoot sets the root which directory plugins live in.
func WithVersionSelector ¶
func WithVersionSelector(finder VersionSelector) Option
WithVersionSelector sets the version finder.
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.
func (*Plugin) FindVersion ¶
func (p *Plugin) FindVersion(selector VersionSelector) string
FindVersion finds the version using the version selector.
type PluginState ¶
type PluginState struct {
Auth string `json:"auth" yaml:"auth"`
}
PluginState is state that will be passed to plugins.
func ReadPluginStateFromPath ¶
func ReadPluginStateFromPath(p string) (*PluginState, error)
ReadPluginStateFromPath read states from a path on disk.
type Repository ¶
type Repository interface { // List available plugins. List() ([]Plugin, error) // Describe a plugin. Describe(name string) (Plugin, error) // Fetch an artifact. Fetch(name, version string, arch Arch) ([]byte, error) // Fetch an artifact test. FetchTest(pluginName, version string, arch Arch) ([]byte, error) // Name of the repository. Name() string // Manifest retrieves the manifest for the repo. Manifest() (Manifest, error) // VersionSelector returns the version finder. VersionSelector() VersionSelector }
Repository is a remote repository containing plugin artifacts.
func HasPluginUpdateIn ¶
func HasPluginUpdateIn(repos *MultiRepo, p *cliv1alpha1.PluginDescriptor) (update bool, repo Repository, version string, err error)
HasPluginUpdateIn checks if the plugin has an update in any of the given repositories.
func LoadRepositories ¶
func LoadRepositories(c *configv1alpha1.ClientConfig) []Repository
LoadRepositories loads the repositories from the config file along with the known repositories.
func NewDefaultRepository ¶
func NewDefaultRepository() Repository
NewDefaultRepository returns the default repository.
func NewGCPBucketRepository ¶
func NewGCPBucketRepository(options ...Option) Repository
NewGCPBucketRepository returns a new GCP bucket repository.
func NewLocalRepository ¶
func NewLocalRepository(name, localPath string, options ...Option) Repository
NewLocalRepository returns a new local repository.
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.
func LoadVersionSelector ¶
func LoadVersionSelector(selectorType configv1alpha1.VersionSelectorLevel) (versionSelector VersionSelector)
LoadVersionSelector will return the correct VersionSelector for a VersionSelectorLevel
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package artifact implements interface to fetch the binary artifacts from different sources
|
Package artifact implements interface to fetch the binary artifacts from different sources |
Package carvelhelpers implements wrapper functions to use carvel tooling
|
Package carvelhelpers implements wrapper functions to use carvel tooling |
Package catalog implements catalog management functions
|
Package catalog implements catalog management functions |
Package clientconfighelpers implements helper function related to client configurations
|
Package clientconfighelpers implements helper function related to client configurations |
command
|
|
core
Package core creates and initializes the tanzu CLI.
|
Package core creates and initializes the tanzu CLI. |
core/templates
Package plugintemplates provides templates for CLI doc generation
|
Package plugintemplates provides templates for CLI doc generation |
plugin
Package plugin provides functions to create new CLI plugins.
|
Package plugin provides functions to create new CLI plugins. |
plugin/lint
Package lint provides linters to run against CLI plugins.
|
Package lint provides linters to run against CLI plugins. |
Package common defines generic constants and structs Package common defines generic constants and structs
|
Package common defines generic constants and structs Package common defines generic constants and structs |
Package component defines components that can be made use of in plugins.
|
Package component defines components that can be made use of in plugins. |
Package discovery is implements discovery interface for plugin discovery Discovery is the interface to fetch the list of available plugins, their supported versions and how to download them either stand-alone or scoped to a server.
|
Package discovery is implements discovery interface for plugin discovery Discovery is the interface to fetch the list of available plugins, their supported versions and how to download them either stand-alone or scoped to a server. |
Package distribution implements plugin distribution interface Distribution is the interface to download a plugin version binary for a given OS and architecture combination.
|
Package distribution implements plugin distribution interface Distribution is the interface to download a plugin version binary for a given OS and architecture combination. |
Package plugin ...
|
Package plugin ... |
Package pluginmanager is resposible for plugin discovery and installation
|
Package pluginmanager is resposible for plugin discovery and installation |