diff --git a/completers/fury_completer/cmd/beta_backup.go b/completers/fury_completer/cmd/beta_backup.go index cc00e5d7c1..29f1413e9d 100644 --- a/completers/fury_completer/cmd/beta_backup.go +++ b/completers/fury_completer/cmd/beta_backup.go @@ -16,4 +16,10 @@ func init() { beta_backupCmd.Flags().String("kind", "", "Filter to one kind of package") betaCmd.AddCommand(beta_backupCmd) + + // TODO kind + + carapace.Gen(betaCmd).PositionalCompletion( + carapace.ActionDirectories(), + ) } diff --git a/completers/fury_completer/cmd/beta_download.go b/completers/fury_completer/cmd/beta_download.go index 7f4764fbff..98381f552d 100644 --- a/completers/fury_completer/cmd/beta_download.go +++ b/completers/fury_completer/cmd/beta_download.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/fury" "github.com/spf13/cobra" ) @@ -15,4 +16,15 @@ func init() { carapace.Gen(beta_downloadCmd).Standalone() betaCmd.AddCommand(beta_downloadCmd) + + carapace.Gen(betaCmd).PositionalCompletion( + carapace.ActionMultiPartsN("@", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return fury.ActionPackages().Suffix("@").MultiParts(":") + default: + return fury.ActionPackageVersions(c.Parts[0]) + } + }), + ) } diff --git a/completers/fury_completer/cmd/help.go b/completers/fury_completer/cmd/help.go index c742c862b0..8502c7e3c4 100644 --- a/completers/fury_completer/cmd/help.go +++ b/completers/fury_completer/cmd/help.go @@ -15,4 +15,8 @@ func init() { carapace.Gen(helpCmd).Standalone() rootCmd.AddCommand(helpCmd) + + carapace.Gen(helpCmd).PositionalAnyCompletion( + carapace.ActionCommands(helpCmd), + ) } diff --git a/completers/fury_completer/cmd/push.go b/completers/fury_completer/cmd/push.go index fac66a1bdf..737288aa6a 100644 --- a/completers/fury_completer/cmd/push.go +++ b/completers/fury_completer/cmd/push.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/fury" "github.com/spf13/cobra" ) @@ -17,4 +18,8 @@ func init() { pushCmd.Flags().Bool("public", false, "Create as public package") pushCmd.Flags().Bool("quiet", false, "Do not show progress bar") rootCmd.AddCommand(pushCmd) + + carapace.Gen(pushCmd).PositionalCompletion( + fury.ActionPackages(), + ) } diff --git a/completers/fury_completer/cmd/versions.go b/completers/fury_completer/cmd/versions.go index 8a15eb8c5f..ec83b86e7d 100644 --- a/completers/fury_completer/cmd/versions.go +++ b/completers/fury_completer/cmd/versions.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/fury" "github.com/spf13/cobra" ) @@ -15,4 +16,8 @@ func init() { carapace.Gen(versionsCmd).Standalone() rootCmd.AddCommand(versionsCmd) + + carapace.Gen(versionsCmd).PositionalCompletion( + fury.ActionPackages().MultiParts(":"), + ) } diff --git a/completers/fury_completer/cmd/yank.go b/completers/fury_completer/cmd/yank.go index e53d344154..94f2d307e2 100644 --- a/completers/fury_completer/cmd/yank.go +++ b/completers/fury_completer/cmd/yank.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/fury" "github.com/spf13/cobra" ) @@ -16,4 +17,15 @@ func init() { yankCmd.Flags().StringP("version", "v", "", "Version") rootCmd.AddCommand(yankCmd) + + carapace.Gen(yankCmd).PositionalCompletion( + carapace.ActionMultiPartsN("@", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return fury.ActionPackages().Suffix("@").MultiParts(":") + default: + return fury.ActionPackageVersions(c.Parts[0]) + } + }), + ) } diff --git a/pkg/actions/tools/fury/package.go b/pkg/actions/tools/fury/package.go new file mode 100644 index 0000000000..f3ec57310e --- /dev/null +++ b/pkg/actions/tools/fury/package.go @@ -0,0 +1,47 @@ +package fury + +import ( + "fmt" + "strings" + + "github.com/rsteube/carapace" + "github.com/rsteube/carapace/pkg/style" +) + +func ActionPackages() carapace.Action { + return carapace.ActionExecCommand("fury", "packages")(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + + vals := make([]string, 0) + for _, line := range lines[4:] { + if fields := strings.Fields(line); len(fields) == 4 { + switch fields[3] { + case "public": + vals = append(vals, fmt.Sprintf("%v:%v", fields[1], fields[0]), style.Green) + default: + vals = append(vals, fmt.Sprintf("%v:%v", fields[1], fields[0]), style.Red) + } + } + } + return carapace.ActionStyledValues(vals...) + }).Tag("packages") +} + +func ActionPackageVersions(pkg string) carapace.Action { + return carapace.ActionExecCommand("fury", "versions", pkg)(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + + unique := make(map[string]string) + for _, line := range lines[4:] { + if fields := strings.Fields(line); len(fields) == 5 { + unique[fields[0]] = fields[2] + " " + fields[3] + } + } + + vals := make([]string, 0) + for k, v := range unique { + vals = append(vals, k, v) + } + return carapace.ActionValuesDescribed(vals...) + }).Tag("package versions") +}