Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 15, 2024
1 parent 8493419 commit 1af77f4
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 0 deletions.
6 changes: 6 additions & 0 deletions completers/fury_completer/cmd/beta_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
12 changes: 12 additions & 0 deletions completers/fury_completer/cmd/beta_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/fury"
"github.com/spf13/cobra"
)

Expand All @@ -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])
}
}),
)
}
4 changes: 4 additions & 0 deletions completers/fury_completer/cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ func init() {
carapace.Gen(helpCmd).Standalone()

rootCmd.AddCommand(helpCmd)

carapace.Gen(helpCmd).PositionalAnyCompletion(
carapace.ActionCommands(helpCmd),
)
}
5 changes: 5 additions & 0 deletions completers/fury_completer/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/fury"
"github.com/spf13/cobra"
)

Expand All @@ -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(),
)
}
5 changes: 5 additions & 0 deletions completers/fury_completer/cmd/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/fury"
"github.com/spf13/cobra"
)

Expand All @@ -15,4 +16,8 @@ func init() {
carapace.Gen(versionsCmd).Standalone()

rootCmd.AddCommand(versionsCmd)

carapace.Gen(versionsCmd).PositionalCompletion(
fury.ActionPackages().MultiParts(":"),
)
}
12 changes: 12 additions & 0 deletions completers/fury_completer/cmd/yank.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/fury"
"github.com/spf13/cobra"
)

Expand All @@ -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])
}
}),
)
}
47 changes: 47 additions & 0 deletions pkg/actions/tools/fury/package.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 1af77f4

Please sign in to comment.