Skip to content

Commit

Permalink
feat: add zarf package remove/inspect completion for cluster sources (
Browse files Browse the repository at this point in the history
#2151)

## Description

- Added `zarf package remove` shell completion ability
- Added `zarf package inspect` shell completion ability
- Added `zarf package list` alias "ls" (since ls is so commonly used)
- Added `zarf package remove` alias "rm" (since rm is so commonly used)

## Related Issue

Fixes #2150 
Partial: #2154 (inspect only)

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [X] Test, docs, adr added or updated as needed
- [X] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

---------

Co-authored-by: Wayne Starr <[email protected]>
  • Loading branch information
WeaponX314 and Racer159 authored Nov 28, 2023
1 parent ee1416a commit fb9872c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ var packageInspectCmd = &cobra.Command{
message.Fatalf(err, lang.CmdPackageInspectErr, err.Error())
}
},
ValidArgsFunction: getPackageCompletionArgs,
}

var packageListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"l"},
Aliases: []string{"l", "ls"},
Short: lang.CmdPackageListShort,
Run: func(cmd *cobra.Command, args []string) {
// Get all the deployed packages
Expand Down Expand Up @@ -188,7 +189,7 @@ var packageListCmd = &cobra.Command{

var packageRemoveCmd = &cobra.Command{
Use: "remove { PACKAGE_SOURCE | PACKAGE_NAME } --confirm",
Aliases: []string{"u"},
Aliases: []string{"u", "rm"},
Args: cobra.MaximumNArgs(1),
Short: lang.CmdPackageRemoveShort,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -203,6 +204,7 @@ var packageRemoveCmd = &cobra.Command{
message.Fatalf(err, lang.CmdPackageRemoveErr, err.Error())
}
},
ValidArgsFunction: getPackageCompletionArgs,
}

var packagePublishCmd = &cobra.Command{
Expand Down Expand Up @@ -300,6 +302,24 @@ func identifyAndFallbackToClusterSource() (src sources.PackageSource) {
return src
}

func getPackageCompletionArgs(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
var pkgCandidates []string

c, err := cluster.NewCluster()
if err != nil {
return pkgCandidates, cobra.ShellCompDirectiveDefault
}

// Get all the deployed packages
deployedZarfPackages, _ := c.GetDeployedZarfPackages()
// Populate list of package names
for _, pkg := range deployedZarfPackages {
pkgCandidates = append(pkgCandidates, pkg.Name)
}

return pkgCandidates, cobra.ShellCompDirectiveDefault
}

func init() {
v := common.InitViper()

Expand Down

0 comments on commit fb9872c

Please sign in to comment.