Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add zarf package remove/inspect completion for cluster sources #2151

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading