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

go: added missing build flags #1549

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions completers/go_completer/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/rsteube/carapace-bin/pkg/actions/tools/golang"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

var buildCmd = &cobra.Command{
Expand All @@ -26,12 +27,15 @@ func init() {
}

func addBuildFlags(cmd *cobra.Command) {
cmd.Flags().StringS("C", "C", "", "Change to dir before running the command")
cmd.Flags().BoolS("a", "a", false, "force rebuilding of packages that are already up-to-date")
cmd.Flags().BoolS("asan", "asan", false, "enable interoperation with address sanitizer")
cmd.Flags().StringS("asmflags", "asmflags", "", "arguments to pass on each go tool asm invocation")
cmd.Flags().StringS("buildmode", "buildmode", "", "build mode to use")
cmd.Flags().StringS("buildvcs", "buildvcs", "", "whether to stamp binaries with version control information")
cmd.Flags().StringS("compiler", "compiler", "", "name of compiler to use")
cmd.Flags().BoolS("cover", "cover", false, "enable code coverage instrumentation")
cmd.Flags().StringS("coverpkg", "coverpkg", "", "apply coverage analysis to each package matching the patterns")
cmd.Flags().StringS("gccgoflags", "gccgoflags", "", "arguments to pass on each gccgo compiler/linker invocation")
cmd.Flags().StringS("gcflags", "gcflags", "", "arguments to pass on each go tool compile invocation")
cmd.Flags().StringS("installsuffix", "installsuffix", "", "a suffix to use in the name of the package installation directory")
Expand All @@ -44,6 +48,7 @@ func addBuildFlags(cmd *cobra.Command) {
cmd.Flags().BoolS("n", "n", false, "print the commands but do not run them")
cmd.Flags().StringS("overlay", "overlay", "", "read a JSON config file that provides an overlay for build operations")
cmd.Flags().StringS("p", "p", "", "the number of programs to run in parallel")
cmd.Flags().StringS("pgo", "pgo", "", "specify the file path of a profile for profile-guided optimization")
cmd.Flags().StringS("pkgdir", "pkgdir", "", "install and load all packages from dir")
cmd.Flags().BoolS("race", "race", false, "enable data race detection")
cmd.Flags().StringS("tags", "tags", "", "a comma-separated list of build tags to consider satisfied during the")
Expand All @@ -56,14 +61,21 @@ func addBuildFlags(cmd *cobra.Command) {
cmd.Flag("buildvcs").NoOptDefVal = "auto"

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"C": carapace.ActionDirectories(),
"buildmode": carapace.ActionValues("archive", "c-archive", "c-shared", "default", "shared", "exe", "pie", "plugin"),
"buildvcs": carapace.ActionValues("true", "false", "auto").StyleF(style.ForKeyword),
"compiler": carapace.ActionValues("gccgo", "gc"),
"coverpkg": golang.ActionPackages().UniqueList(","),
"mod": carapace.ActionValues("readonly", "vendor", "mod"),
"modfile": carapace.ActionFiles(".mod"),
"n": carapace.ActionValues("1", "2", "3", "4", "5", "6", "7", "8"),
"overlay": carapace.ActionFiles(".json"),
"pgo": carapace.ActionFiles(".pgo"),
"pkgdir": carapace.ActionDirectories(),
"tags": golang.ActionBuildTags().UniqueList(","),
})

carapace.Gen(cmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action {
return action.Chdir(cmd.Flag("C").Value.String())
})
}
4 changes: 2 additions & 2 deletions completers/go_completer/cmd/env.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/go_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/golang"
"github.com/spf13/cobra"
)

Expand All @@ -22,7 +22,7 @@ func init() {

carapace.Gen(envCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionEnvironmentVariables().Invoke(c).Filter(c.Args).ToA()
return golang.ActionEnvironmentVariables().Invoke(c).Filter(c.Args).ToA()
}),
)
}
3 changes: 1 addition & 2 deletions completers/go_completer/cmd/mod_why.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/go_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/golang"
"github.com/spf13/cobra"
)
Expand All @@ -23,7 +22,7 @@ func init() {
carapace.Gen(mod_whyCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
action.ActionPackages(),
golang.ActionPackages(),
golang.ActionModules(golang.ModuleOpts{Direct: true, Indirect: true}),
).Invoke(c).Merge().ToA()
}),
Expand Down
6 changes: 3 additions & 3 deletions completers/go_completer/cmd/test.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/go_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/golang"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -40,11 +40,11 @@ func init() {

carapace.Gen(testCmd).FlagCompletion(carapace.ActionMap{
"bench": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionTests(c.Args, action.TestOpts{Benchmark: true}).UniqueList("|")
return golang.ActionTests(golang.TestOpts{Packages: c.Args, Benchmark: true}).UniqueList("|")
}),
"covermode": carapace.ActionValues("set", "count,atomic"),
"run": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionTests(c.Args, action.TestOpts{Example: true, Test: true}).UniqueList("|")
return golang.ActionTests(golang.TestOpts{Packages: c.Args, Example: true, Test: true}).UniqueList("|")
}),
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package action
package golang

import (
"encoding/json"

"github.com/rsteube/carapace"
)

// ActionEnvironmentVariables completes go environment variables.
//
// GOHOSTARCH (amd64)
// GOHOSTOS (linux)
func ActionEnvironmentVariables() carapace.Action {
return carapace.ActionExecCommand("go", "env", "--json")(func(output []byte) carapace.Action {
var env map[string]string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package action
package golang

import (
"strings"

"github.com/rsteube/carapace"
)

// ActionPackages completes packages.
//
// encoding/json
// github.com/rsteube/carapace-bin/completers/go_completer
func ActionPackages() carapace.Action {
return carapace.ActionExecCommand("go", "list", "-f", "{{.ImportPath}}\n{{.Doc}} ", "all")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package action
package golang

import (
"strings"
Expand All @@ -8,13 +8,24 @@ import (
)

type TestOpts struct {
Packages []string
Benchmark bool
Example bool
Test bool
}

func ActionTests(packages []string, opts TestOpts) carapace.Action {
return carapace.ActionExecCommand("go", append([]string{"test", "-list=.*"}, packages...)...)(func(output []byte) carapace.Action {
func (o *TestOpts) Default() {
o.Benchmark = true
o.Example = true
o.Test = true
}

// ActionTests completes tests
//
// TestActionFiles
// TestActionFilesChdir
func ActionTests(opts TestOpts) carapace.Action {
return carapace.ActionExecCommand("go", append([]string{"test", "-list=.*"}, opts.Packages...)...)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)
for _, line := range lines {
Expand Down