Skip to content

Commit

Permalink
Merge pull request #1318 from rsteube/go-fix-buildflags
Browse files Browse the repository at this point in the history
go: fix build flags
  • Loading branch information
rsteube authored Sep 26, 2022
2 parents 412805e + 8d98921 commit edfb6a3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 63 deletions.
64 changes: 39 additions & 25 deletions completers/go_completer/cmd/build.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/golang"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

Expand All @@ -15,43 +16,56 @@ var buildCmd = &cobra.Command{
func init() {
carapace.Gen(buildCmd).Standalone()

buildCmd.Flags().BoolS("a", "a", false, "force rebuilding of packages that are already up-to-date.")
buildCmd.Flags().StringS("asmflags", "asmflags", "", "arguments to pass on each go tool asm invocation")
buildCmd.Flags().StringS("buildmode", "buildmode", "", "build mode to use")
buildCmd.Flags().StringS("compiler", "compiler", "", "name of compiler to use")
buildCmd.Flags().StringS("gccgoflags", "gccgoflags", "", "arguments to pass on each gccgo compiler/linker invocation")
buildCmd.Flags().StringS("gcflags", "gcflags", "", "arguments to pass on each go tool compile invocation.")
buildCmd.Flags().BoolS("i", "i", false, "install the packages that are dependencies of the target")
buildCmd.Flags().StringS("installsuffix", "installsuffix", "", "a suffix to use in the name of the package installation directory")
buildCmd.Flags().StringS("ldflags", "ldflags", "", "arguments to pass on each go tool link invocation")
buildCmd.Flags().BoolS("linkshared", "linkshared", false, "build code that will be linked against shared libraries")
buildCmd.Flags().StringS("mod", "mod", "", "module download mode to use")
buildCmd.Flags().BoolS("modcacherw", "modcacherw", false, "leave newly-created directories in the module cache read-write")
buildCmd.Flags().StringS("modfile", "modfile", "", "read and possibly write an alternate go.mod file")
buildCmd.Flags().BoolS("msan", "msan", false, "enable interoperation with memory sanitizer")
buildCmd.Flags().BoolS("n", "n", false, "print the commands but do not run them.")
buildCmd.Flags().StringS("o", "o", "", "set output file or directory")
buildCmd.Flags().StringS("p", "p", "", "the number of programs to run in parallel")
buildCmd.Flags().StringS("pkgdir", "pkgdir", "", "install and load all packages from dir")
buildCmd.Flags().BoolS("race", "race", false, "enable data race detection")
buildCmd.Flags().StringS("tags", "tags", "", "a comma-separated list of build tags to consider satisfied during the")
buildCmd.Flags().StringS("toolexec", "toolexec", "", "a program to use to invoke toolchain programs like vet and asm")
buildCmd.Flags().BoolS("trimpath", "trimpath", false, "remove all file system paths from the resulting executable")
buildCmd.Flags().BoolS("v", "v", false, "print the names of packages as they are compiled")
buildCmd.Flags().BoolS("work", "work", false, "print the name of the temporary work directory")
buildCmd.Flags().BoolS("x", "x", false, "print the commands.")
addBuildFlags(buildCmd)
rootCmd.AddCommand(buildCmd)

carapace.Gen(buildCmd).FlagCompletion(carapace.ActionMap{
"o": carapace.ActionFiles(),
})
}

func addBuildFlags(cmd *cobra.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().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")
cmd.Flags().StringS("ldflags", "ldflags", "", "arguments to pass on each go tool link invocation")
cmd.Flags().BoolS("linkshared", "linkshared", false, "build code that will be linked against shared libraries")
cmd.Flags().StringS("mod", "mod", "", "module download mode to use")
cmd.Flags().BoolS("modcacherw", "modcacherw", false, "leave newly-created directories in the module cache read-write")
cmd.Flags().StringS("modfile", "modfile", "", "read and possibly write an alternate go.mod file")
cmd.Flags().BoolS("msan", "msan", false, "enable interoperation with memory sanitizer")
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("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")
cmd.Flags().StringS("toolexec", "toolexec", "", "a program to use to invoke toolchain programs like vet and asm")
cmd.Flags().BoolS("trimpath", "trimpath", false, "remove all file system paths from the resulting executable")
cmd.Flags().BoolS("v", "v", false, "print the names of packages as they are compiled")
cmd.Flags().BoolS("work", "work", false, "print the name of the temporary work directory")
cmd.Flags().BoolS("x", "x", false, "print the commands")

cmd.Flag("buildvcs").NoOptDefVal = "auto"

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"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"),
"mod": carapace.ActionValues("readonly", "vendor", "mod"),
"modfile": carapace.ActionFiles(".mod"),
"n": carapace.ActionValues("1", "2", "3", "4", "5", "6", "7", "8"),
"o": carapace.ActionFiles(),
"pkgdir": carapace.ActionDirectories(),
"tags": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
return golang.ActionBuildTags().Invoke(c).Filter(c.Parts).ToA()
}),
})

}
3 changes: 1 addition & 2 deletions completers/go_completer/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ func init() {
cleanCmd.Flags().BoolS("cache", "cache", false, "remove the entire go build cache")
cleanCmd.Flags().BoolS("i", "i", false, "remove the corresponding installed archive or binary")
cleanCmd.Flags().BoolS("modcache", "modcache", false, "remove the entire module download cache")
cleanCmd.Flags().BoolS("n", "n", false, "only print the remove commands that would be executed")
cleanCmd.Flags().BoolS("r", "r", false, "apply recursively to all the dependencies")
cleanCmd.Flags().BoolS("testcache", "testcache", false, "expire all test results in the go build cache")
cleanCmd.Flags().BoolS("x", "x", false, "print remove commands as being executed")
addBuildFlags(cleanCmd)
rootCmd.AddCommand(cleanCmd)
}
2 changes: 1 addition & 1 deletion completers/go_completer/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func init() {
getCmd.Flags().BoolS("insecure", "insecure", false, "permit using insecure schemes such as HTTP")
getCmd.Flags().BoolS("t", "t", false, "consider modules needed to build tests")
getCmd.Flags().BoolS("u", "u", false, "update modules providing dependencies")
getCmd.Flags().BoolS("v", "v", false, "verbose output")
addBuildFlags(getCmd)
rootCmd.AddCommand(getCmd)
}
36 changes: 2 additions & 34 deletions completers/go_completer/cmd/install.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/pkg/actions/tools/golang"
"github.com/spf13/cobra"
)

Expand All @@ -15,43 +14,12 @@ var installCmd = &cobra.Command{
func init() {
carapace.Gen(installCmd).Standalone()

installCmd.Flags().BoolS("a", "a", false, "force rebuilding of packages that are already up-to-date.")
installCmd.Flags().StringS("asmflags", "asmflags", "", "arguments to pass on each go tool asm invocation")
installCmd.Flags().StringS("buildmode", "buildmode", "", "build mode to use")
installCmd.Flags().StringS("compiler", "compiler", "", "name of compiler to use")
installCmd.Flags().StringS("gccgoflags", "gccgoflags", "", "arguments to pass on each gccgo compiler/linker invocation")
installCmd.Flags().StringS("gcflags", "gcflags", "", "arguments to pass on each go tool compile invocation.")
installCmd.Flags().BoolS("i", "i", false, "install the packages that are dependencies of the target")
installCmd.Flags().StringS("installsuffix", "installsuffix", "", "a suffix to use in the name of the package installation directory")
installCmd.Flags().StringS("ldflags", "ldflags", "", "arguments to pass on each go tool link invocation")
installCmd.Flags().BoolS("linkshared", "linkshared", false, "build code that will be linked against shared libraries")
installCmd.Flags().StringS("mod", "mod", "", "module download mode to use")
installCmd.Flags().BoolS("modcacherw", "modcacherw", false, "leave newly-created directories in the module cache read-write")
installCmd.Flags().StringS("modfile", "modfile", "", "read and possibly write an alternate go.mod file")
installCmd.Flags().BoolS("msan", "msan", false, "enable interoperation with memory sanitizer")
installCmd.Flags().BoolS("n", "n", false, "print the commands but do not run them.")
installCmd.Flags().StringS("o", "o", "", "set output file or directory")
installCmd.Flags().StringS("p", "p", "", "the number of programs to run in parallel")
installCmd.Flags().StringS("pkgdir", "pkgdir", "", "install and load all packages from dir")
installCmd.Flags().BoolS("race", "race", false, "enable data race detection")
installCmd.Flags().StringS("tags", "tags", "", "a comma-separated list of build tags to consider satisfied during the")
installCmd.Flags().StringS("toolexec", "toolexec", "", "a program to use to invoke toolchain programs like vet and asm")
installCmd.Flags().BoolS("trimpath", "trimpath", false, "remove all file system paths from the resulting executable")
installCmd.Flags().BoolS("v", "v", false, "print the names of packages as they are compiled")
installCmd.Flags().BoolS("work", "work", false, "print the name of the temporary work directory")
installCmd.Flags().BoolS("x", "x", false, "print the commands.")
addBuildFlags(installCmd)
rootCmd.AddCommand(installCmd)

carapace.Gen(installCmd).FlagCompletion(carapace.ActionMap{
"buildmode": carapace.ActionValues("archive", "c-archive", "c-shared", "default", "shared", "exe", "pie", "plugin"),
"compiler": carapace.ActionValues("gccgo", "gc"),
"mod": carapace.ActionValues("readonly", "vendor", "mod"),
"modfile": carapace.ActionFiles(".mod"),
"n": carapace.ActionValues("1", "2", "3", "4", "5", "6", "7", "8"),
"o": carapace.ActionFiles(),
"pkgdir": carapace.ActionDirectories(),
"tags": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
return golang.ActionBuildTags().Invoke(c).Filter(c.Parts).ToA()
}),
"o": carapace.ActionFiles(),
})
}
1 change: 1 addition & 0 deletions completers/go_completer/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ func init() {
listCmd.Flags().BoolS("test", "test", false, "report not only the named packages but also their test binaries")
listCmd.Flags().BoolS("u", "u", false, "add information about available upgrades")
listCmd.Flags().BoolS("versions", "versions", false, "set the Module's Versions field to list of all known versions")
addBuildFlags(listCmd)
rootCmd.AddCommand(listCmd)
}
1 change: 0 additions & 1 deletion completers/go_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ func Execute() error {
}
func init() {
carapace.Gen(rootCmd).Standalone()

}
1 change: 1 addition & 0 deletions completers/go_completer/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ func init() {
carapace.Gen(runCmd).Standalone()

runCmd.Flags().StringS("exec", "exec", "", "invoke the binary using xprog")
addBuildFlags(runCmd)
rootCmd.AddCommand(runCmd)
}

0 comments on commit edfb6a3

Please sign in to comment.