Skip to content

Commit

Permalink
Merge pull request #2060 from rsteube/fix-pamac-package-search
Browse files Browse the repository at this point in the history
pamac: fix package search
  • Loading branch information
rsteube authored Dec 8, 2023
2 parents 3a7d95f + 891c7a9 commit 2c846de
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions completers/pamac_completer/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/pamac_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pamac"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +20,6 @@ func init() {
rootCmd.AddCommand(infoCmd)

carapace.Gen(infoCmd).PositionalAnyCompletion(
action.ActionPackageSearch().FilterArgs(), // TODO aur flag
pamac.ActionPackageSearch().FilterArgs(), // TODO aur flag
)
}
8 changes: 4 additions & 4 deletions completers/pamac_completer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/pamac_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pamac"
"github.com/rsteube/carapace/pkg/util"
"github.com/spf13/cobra"
)
Expand All @@ -28,7 +28,7 @@ func init() {
rootCmd.AddCommand(installCmd)

carapace.Gen(installCmd).FlagCompletion(carapace.ActionMap{
"ignore": action.ActionPackageSearch().UniqueList(","),
"ignore": pamac.ActionPackageSearch().UniqueList(","),
})

carapace.Gen(installCmd).PositionalAnyCompletion(
Expand All @@ -38,8 +38,8 @@ func init() {
}

return carapace.Batch(
action.ActionPackageGroups(),
action.ActionPackageSearch(),
pamac.ActionPackageGroups(),
pamac.ActionPackageSearch(),
).ToA()
}),
)
Expand Down
4 changes: 2 additions & 2 deletions completers/pamac_completer/cmd/reinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/pamac_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pamac"
"github.com/spf13/cobra"
)

Expand All @@ -23,6 +23,6 @@ func init() {
rootCmd.AddCommand(reinstallCmd)

carapace.Gen(reinstallCmd).PositionalAnyCompletion(
action.ActionInstalledPackages(false).FilterArgs(), // TODO groups as well
pamac.ActionInstalledPackages(false).FilterArgs(), // TODO groups as well
)
}
4 changes: 2 additions & 2 deletions completers/pamac_completer/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/pamac_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pamac"
"github.com/spf13/cobra"
)

Expand All @@ -24,6 +24,6 @@ func init() {
rootCmd.AddCommand(removeCmd)

carapace.Gen(removeCmd).PositionalAnyCompletion(
action.ActionInstalledPackages(true).FilterArgs(),
pamac.ActionInstalledPackages(true).FilterArgs(),
)
}
4 changes: 2 additions & 2 deletions completers/pamac_completer/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/pamac_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pamac"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -32,6 +32,6 @@ func init() {

carapace.Gen(updateCmd).FlagCompletion(carapace.ActionMap{
"builddir": carapace.ActionDirectories(),
"ignore": action.ActionInstalledPackages(false).UniqueList(","),
"ignore": pamac.ActionInstalledPackages(false).UniqueList(","),
})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package action
package pamac

import (
"fmt"
Expand All @@ -8,6 +8,10 @@ import (
"github.com/rsteube/carapace"
)

// ActionPackageGroups completes package groups
//
// archlinux-tools ([group])
// arduino ([group])
func ActionPackageGroups() carapace.Action {
return carapace.ActionExecCommand("pamac", "list", "--groups")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
Expand All @@ -20,14 +24,18 @@ func ActionPackageGroups() carapace.Action {
})
}

// ActionPackageSearch completes installable packages
//
// git ([extra] the fast distributed version control system)
// git-absorb ([extra] git commit --fixup, but automatic)
func ActionPackageSearch() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Value) == 0 {
return carapace.ActionValues()
}
return carapace.ActionExecCommand("pamac", "search", "--aur", c.Value)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^(?P<name>[^ ]+) +(?P<installed>\[Installed\])? +(?P<version>[^ ]+) +(?P<repo>[^ ]+) $`)
r := regexp.MustCompile(`^(?P<name>[^ ]+) +(?P<version>[^ ]+) +(?P<installed>\[Installed\])? +(?P<repo>[^ ]+)$`)

current := ""
packages := make(map[string][]string)
Expand All @@ -50,6 +58,10 @@ func ActionPackageSearch() carapace.Action {
})
}

// ActionInstalledPackages completes installed packages
//
// a52dec (0.8.0-2)
// aalib (1.4rc5-17)
func ActionInstalledPackages(explicit bool) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
arg := "-i"
Expand Down

0 comments on commit 2c846de

Please sign in to comment.