Skip to content

Commit

Permalink
Merge pull request #1790 from rsteube/user-filterargs
Browse files Browse the repository at this point in the history
use `Action.FilterArgs`
  • Loading branch information
rsteube authored Aug 5, 2023
2 parents 91690e5 + 7a048e5 commit 1b5ebce
Show file tree
Hide file tree
Showing 184 changed files with 229 additions and 480 deletions.
2 changes: 1 addition & 1 deletion completers/ant_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func init() {
if flag := rootCmd.Flag("f"); flag.Changed {
path = flag.Value.String()
}
return action.ActionTargets(path).Invoke(c).Filter(c.Args).ToA()
return action.ActionTargets(path).FilterArgs()
}),
)
}
4 changes: 1 addition & 3 deletions completers/apt-get_completer/cmd/buildDep.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(buildDepCmd)

carapace.Gen(buildDepCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return apt.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA()
}),
apt.ActionPackageSearch().FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/apt-get_completer/cmd/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(changelogCmd)

carapace.Gen(changelogCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return apt.ActionPackages().Invoke(c).Filter(c.Args).ToA()
}),
apt.ActionPackages().FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/apt-get_completer/cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(downloadCmd)

carapace.Gen(downloadCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return apt.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA()
}),
apt.ActionPackageSearch().FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/apt-get_completer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(installCmd)

carapace.Gen(installCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return apt.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA()
}),
apt.ActionPackageSearch().FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/apt-get_completer/cmd/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(purgeCmd)

carapace.Gen(purgeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return apt.ActionPackages().Invoke(c).Filter(c.Args).ToA()
}),
apt.ActionPackages().FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/apt-get_completer/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(removeCmd)

carapace.Gen(removeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return apt.ActionPackages().Invoke(c).Filter(c.Args).ToA()
}),
apt.ActionPackages().FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/apt-get_completer/cmd/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(sourceCmd)

carapace.Gen(sourceCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return apt.ActionPackageSearch().Invoke(c).Filter(c.Args).ToA()
}),
apt.ActionPackageSearch().FilterArgs(),
)
}
2 changes: 1 addition & 1 deletion completers/ar_completer/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {

carapace.Gen(deleteCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return fs.ActionArFileContents(c.Args[0]).Invoke(c).Filter(c.Args[1:]).ToA()
return fs.ActionArFileContents(c.Args[0]).Invoke(c).Filter(c.Args[1:]...).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/ar_completer/cmd/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {

carapace.Gen(extractCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return fs.ActionArFileContents(c.Args[0]).Invoke(c).Filter(c.Args[1:]).ToA()
return fs.ActionArFileContents(c.Args[0]).Invoke(c).Filter(c.Args[1:]...).ToA()
}),
)
}
4 changes: 2 additions & 2 deletions completers/ar_completer/cmd/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func init() {
return carapace.ActionFiles()

default:
return fs.ActionArFileContents(c.Args[1]).Invoke(c).Filter(c.Args[1:]).ToA()
return fs.ActionArFileContents(c.Args[1]).Invoke(c).Filter(c.Args[1:]...).ToA()
}
}

if len(c.Args) == 0 {
return carapace.ActionFiles()
}
return fs.ActionArFileContents(c.Args[0]).Invoke(c).Filter(c.Args[1:]).ToA()
return fs.ActionArFileContents(c.Args[0]).Invoke(c).Filter(c.Args[1:]...).ToA()
}),
)
}
2 changes: 1 addition & 1 deletion completers/ar_completer/cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {

carapace.Gen(printCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return fs.ActionArFileContents(c.Args[0]).Invoke(c).Filter(c.Args[1:]).ToA()
return fs.ActionArFileContents(c.Args[0]).Filter(c.Args[1:]...)
}),
)
}
4 changes: 1 addition & 3 deletions completers/brew_completer/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func init() {
rootCmd.AddCommand(listCmd)

carapace.Gen(listCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionList(listCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionList(listCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/brew_completer/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ func init() {
rootCmd.AddCommand(uninstallCmd)

carapace.Gen(uninstallCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionList(uninstallCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionList(uninstallCmd).FilterArgs(),
)
}
2 changes: 1 addition & 1 deletion completers/cargo-rm_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {
return cargo.ActionDependencies(cargo.DependencyOpts{
Path: rootCmd.Flag("manifest-path").Value.String(),
IncludeVersion: false,
}).Invoke(c).Filter(c.Args).ToA()
}).FilterArgs()
}),
)
}
2 changes: 1 addition & 1 deletion completers/cargo-upgrade_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
return cargo.ActionDependencies(cargo.DependencyOpts{
Path: rootCmd.Flag("manifest-path").Value.String(),
IncludeVersion: false,
}).Invoke(c).Filter(c.Args).ToA()
}).FilterArgs()
}),
)
}
2 changes: 1 addition & 1 deletion completers/cargo_completer/cmd/action/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ActionGithubPackageSearch() carapace.Action {
if len(c.Args) < 2 {
batch = append(batch, actionGithubPackageIndex("2"))
batch = append(batch, carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return actionGithubPackageIndex("").Invoke(c).Filter([]string{"1", "2", "3", "config.json"}).ToA()
return actionGithubPackageIndex("").Filter("1", "2", "3", "config.json")
}))
}

Expand Down
4 changes: 1 addition & 3 deletions completers/cargo_completer/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ func init() {
})

carapace.Gen(removeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionDependencies(removeCmd, false).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionDependencies(removeCmd, false).FilterArgs(),
)
}
2 changes: 1 addition & 1 deletion completers/cargo_completer/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {

carapace.Gen(uninstallCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionInstalledPackages(uninstallCmd.Flag("root").Value.String()).Invoke(c).Filter(c.Args).ToA()
return action.ActionInstalledPackages(uninstallCmd.Flag("root").Value.String()).FilterArgs()
}),
)
}
2 changes: 1 addition & 1 deletion completers/conda_completer/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {

carapace.Gen(initCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionValues("bash", "fish", "powershell", "tcsh", "xonsh", "zsh").Invoke(c).Filter(c.Args).ToA()
return carapace.ActionValues("bash", "fish", "powershell", "tcsh", "xonsh", "zsh").FilterArgs()
}),
)
}
4 changes: 1 addition & 3 deletions completers/conda_completer/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func init() {
})

carapace.Gen(removeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionPackages(removeCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionPackages(removeCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/conda_completer/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func init() {
})

carapace.Gen(updateCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionPackages(updateCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionPackages(updateCmd).FilterArgs(),
)
}
2 changes: 1 addition & 1 deletion completers/consul_completer/cmd/rtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
carapace.Gen(rttCmd).PositionalCompletion(
action.ActionNodes(rttCmd),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionNodes(rttCmd).Invoke(c).Filter(c.Args[:1]).ToA()
return action.ActionNodes(rttCmd).Invoke(c).Filter(c.Args[:1]...).ToA() // TODO should work with FilterArgs
}),
)
}
4 changes: 1 addition & 3 deletions completers/dart_completer/cmd/pub_downgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ func init() {
pubCmd.AddCommand(pub_downgradeCmd)

carapace.Gen(pub_downgradeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return pub.ActionDependencies().Invoke(c).Filter(c.Args).ToA()
}),
pub.ActionDependencies().FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/dart_completer/cmd/pub_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func init() {
pubCmd.AddCommand(pub_upgradeCmd)

carapace.Gen(pub_upgradeCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return pub.ActionDependencies().Invoke(c).Filter(c.Args).ToA()
}),
pub.ActionDependencies().FilterArgs(),
)
}
12 changes: 3 additions & 9 deletions completers/dbt_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ func addModelsFlag(cmd *cobra.Command) {
cmd.Flag("models").Nargs = -1

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"models": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return dbt.ActionResources(dbt.ResourceOpts{Model: true}).Invoke(c).Filter(c.Parts).ToA()
}),
"models": dbt.ActionResources(dbt.ResourceOpts{Model: true}).FilterParts(), // TODO test this
})
}

Expand All @@ -95,11 +93,7 @@ func addSelectionFlags(cmd *cobra.Command) {
cmd.Flag("select").Nargs = -1

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"exclude": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return dbt.ActionResources(dbt.ResourceOpts{}.Default()).Invoke(c).Filter(c.Parts).ToA()
}),
"select": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return dbt.ActionResources(dbt.ResourceOpts{}.Default()).Invoke(c).Filter(c.Parts).ToA()
}),
"exclude": dbt.ActionResources(dbt.ResourceOpts{}.Default()).FilterParts(),
"select": dbt.ActionResources(dbt.ResourceOpts{}.Default()).FilterParts(),
})
}
2 changes: 1 addition & 1 deletion completers/dd_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
"seek", "skip N obs-sized blocks at start of output",
"skip", "skip N ibs-sized blocks at start of input",
"status", "The LEVEL of information to print to stderr",
).Invoke(c).Filter(keys).Suffix("=").ToA()
).Invoke(c).Filter(keys...).Suffix("=").ToA()
case 1:
switch c.Parts[0] {
case "conv":
Expand Down
8 changes: 4 additions & 4 deletions completers/devbox_completer/cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/devbox"
"github.com/rsteube/carapace/pkg/traverse"
"github.com/spf13/cobra"
)

Expand All @@ -22,9 +23,8 @@ func init() {
})

carapace.Gen(rmCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
dir := rmCmd.Flag("config").Value.String()
return devbox.ActionInstalledPackages().Chdir(dir).Invoke(c).Filter(c.Args).ToA()
}),
devbox.ActionInstalledPackages().
ChdirF(traverse.Flag(rmCmd.Flag("config"))).
FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func init() {
})

carapace.Gen(buildCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(buildCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(buildCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func init() {
})

carapace.Gen(configCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(configCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(configCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ func init() {
})

carapace.Gen(createCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(createCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(createCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ func init() {
rootCmd.AddCommand(eventsCmd)

carapace.Gen(eventsCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(eventsCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(eventsCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func init() {
})

carapace.Gen(imagesCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(imagesCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(imagesCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func init() {
})

carapace.Gen(killCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(killCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(killCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func init() {
rootCmd.AddCommand(logsCmd)

carapace.Gen(logsCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(logsCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(logsCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func init() {
rootCmd.AddCommand(pauseCmd)

carapace.Gen(pauseCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(pauseCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(pauseCmd).FilterArgs(),
)
}
4 changes: 1 addition & 3 deletions completers/docker-compose_completer/cmd/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ func init() {
})

carapace.Gen(psCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionServices(psCmd).Invoke(c).Filter(c.Args).ToA()
}),
action.ActionServices(psCmd).FilterArgs(),
)
}
Loading

0 comments on commit 1b5ebce

Please sign in to comment.