Skip to content

Commit

Permalink
updated carapace to v0.32.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 21, 2023
1 parent e46d166 commit dfea6a5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 62 deletions.
44 changes: 25 additions & 19 deletions completers/java_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"os"
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/java_completer/cmd/action"
Expand All @@ -17,24 +16,6 @@ var rootCmd = &cobra.Command{
}

func Execute() error {
for _, arg := range os.Args {
// yuck - these are flags that require an argument but don't allow space between name and value
// which essentially makes them new flags. To prevent unkown flag errors these are added as fake
// flags just as they are.
for _, flag := range []string{"-D", "-Xms", "-Xmx", "-Xss"} {
if strings.HasPrefix(arg, flag) && len(arg) > 2 {
fakeflag := strings.SplitN(arg[1:], "=", 2)[0]
if rootCmd.Flag(fakeflag) == nil {
rootCmd.Flags().String(fakeflag, "", "") // fake flag to prevent errors
rootCmd.Flag(fakeflag).NoOptDefVal = " "
}
}
}
}

carapace.Override(carapace.Opts{
OptArgDelimiter: ":",
})
return rootCmd.Execute()
}
func init() {
Expand Down Expand Up @@ -88,26 +69,47 @@ func init() {
rootCmd.Flags().StringS("Xss", "Xss", "", "set java thread stack size")

rootCmd.Flag("D").NoOptDefVal = " "
rootCmd.Flag("D").OptargDelimiter = ':'
rootCmd.Flag("agentlib").NoOptDefVal = " "
rootCmd.Flag("agentlib").OptargDelimiter = ':'
rootCmd.Flag("agentpath").NoOptDefVal = " "
rootCmd.Flag("agentpath").OptargDelimiter = ':'
rootCmd.Flag("da").NoOptDefVal = " "
rootCmd.Flag("da").OptargDelimiter = ':'
rootCmd.Flag("disableassertions").NoOptDefVal = " "
rootCmd.Flag("disableassertions").OptargDelimiter = ':'
rootCmd.Flag("ea").NoOptDefVal = " "
rootCmd.Flag("ea").OptargDelimiter = ':'
rootCmd.Flag("enableassertions").NoOptDefVal = " "
rootCmd.Flag("enableassertions").OptargDelimiter = ':'
rootCmd.Flag("javaagent").NoOptDefVal = " "
rootCmd.Flag("javaagent").OptargDelimiter = ':'
rootCmd.Flag("splash").NoOptDefVal = " "
rootCmd.Flag("splash").OptargDelimiter = ':'
rootCmd.Flag("verbose").NoOptDefVal = " "
rootCmd.Flag("verbose").OptargDelimiter = ':'
rootCmd.Flag("Xbootclasspath").NoOptDefVal = " "
rootCmd.Flag("Xbootclasspath").OptargDelimiter = ':'
rootCmd.Flag("Xbootclasspath/a").NoOptDefVal = " "
rootCmd.Flag("Xbootclasspath/a").OptargDelimiter = ':'
rootCmd.Flag("Xbootclasspath/p").NoOptDefVal = " "
rootCmd.Flag("Xbootclasspath/p").OptargDelimiter = ':'
rootCmd.Flag("Xloggc").NoOptDefVal = " "
rootCmd.Flag("Xloggc").OptargDelimiter = ':'
rootCmd.Flag("Xms").NoOptDefVal = " "
rootCmd.Flag("Xms").OptargDelimiter = ':'
rootCmd.Flag("Xmx").NoOptDefVal = " "
rootCmd.Flag("Xmx").OptargDelimiter = ':'
rootCmd.Flag("Xss").NoOptDefVal = " "
rootCmd.Flag("Xss").OptargDelimiter = ':'
rootCmd.Flag("Xcheck").NoOptDefVal = " "
rootCmd.Flag("Xcheck").OptargDelimiter = ':'
rootCmd.Flag("Xshare").NoOptDefVal = " "
rootCmd.Flag("Xshare").OptargDelimiter = ':'
rootCmd.Flag("XshowSettings").NoOptDefVal = " "
rootCmd.Flag("XshowSettings").OptargDelimiter = ':'
rootCmd.Flag("XX").NoOptDefVal = " "
rootCmd.Flag("XX").OptargDelimiter = ':'

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"XX": action.ActionAdvanced(),
Expand Down Expand Up @@ -192,4 +194,8 @@ func init() {
return carapace.ActionValues()
}),
)

carapace.Gen(rootCmd).PreRun(func(cmd *cobra.Command, args []string) {
os.Setenv("CARAPACE_LENIENT", "1") // TODO hacky empty optargdelimiter support for now
})
}
88 changes: 51 additions & 37 deletions completers/javac_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,69 @@ var rootCmd = &cobra.Command{
}

func Execute() error {
for _, arg := range os.Args {
// yuck - these are flags that require an argument but don't allow space between name and value
// which essentially makes them new flags. To prevent unkown flag errors these are added as fake
// flags just as they are.
for _, flag := range []string{"-A", "-J"} { // TODO support `=` in `-A`
if strings.HasPrefix(arg, flag) && len(arg) > 2 {
fakeflag := strings.SplitN(arg[1:], "=", 2)[0]
if rootCmd.Flag(fakeflag) == nil {
rootCmd.Flags().String(fakeflag, "", "") // fake flag to prevent errors
rootCmd.Flag(fakeflag).NoOptDefVal = " "
}
}
}
}

carapace.Override(carapace.Opts{
OptArgDelimiter: ":",
})
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().StringS("A", "A", "", "Options to pass to annotation processors")
rootCmd.Flags().BoolS("?", "?", false, "Print help message")
rootCmd.Flags().BoolS("A", "A", false, "Options to pass to annotation processors")
rootCmd.Flags().BoolS("J", "J", false, "Pass flag directly to the runtime system")
rootCmd.Flags().BoolS("Werror", "Werror", false, "Terminate compilation if warnings occur")
rootCmd.Flags().StringS("bootclasspath", "bootclasspath", "", "Override location of bootstrap class files")
rootCmd.Flags().StringS("classpath", "classpath", "", "Specify where to find user class files and annotation processors")
rootCmd.Flags().String("add-modules", "", "Root modules to resolve in addition to the initial modules")
rootCmd.Flags().StringP("boot-class-path", "bootclasspath", "", "Override location of bootstrap class files")
rootCmd.Flags().StringP("class-path", "classpath", "", "Specify where to find user class files and annotation processors")
rootCmd.Flags().StringS("cp", "cp", "", "Specify where to find user class files and annotation processors")
rootCmd.Flags().BoolS("d", "d", false, "Specify where to place generated class files")
rootCmd.Flags().BoolS("deprecation", "deprecation", false, "Output source locations where deprecated APIs are used")
rootCmd.Flags().Bool("enable-preview", false, "Enable preview languge features")
rootCmd.Flags().StringS("encoding", "encoding", "", "Specify character encoding used by source files")
rootCmd.Flags().StringS("endorseddirs", "endorseddirs", "", "Override location of endorsed standards path")
rootCmd.Flags().StringS("extdirs", "extdirs", "", "Override location of installed extensions")
rootCmd.Flags().StringS("g", "g", "", "Generates all debugging information")
rootCmd.Flags().BoolS("h", "h", false, "Specify where to place generated native header files")
rootCmd.Flags().BoolS("help", "help", false, "Print a synopsis of standard options")
rootCmd.Flags().BoolS("help", "help", false, "Print help message")
rootCmd.Flags().BoolS("help-extra", "X", false, "Print help on extra options")
rootCmd.Flags().StringS("implicit", "implicit", "", "Specify whether or not to generate class files for implicitly referenced files")
rootCmd.Flags().String("limit-modules", "", "Limit the universe of observable modules")
rootCmd.Flags().String("module", "", "Compile only the specified module")
rootCmd.Flags().StringP("module-path", "p", "", "Root modules to resolve in addition to the initial modules")
rootCmd.Flags().String("module-source-path", "", "Specify where to find input source files for multiple modules")
rootCmd.Flags().String("module-version", "", "Specify version of modules that are being compiled")
rootCmd.Flags().BoolS("nowarn", "nowarn", false, "Generate no warnings")
rootCmd.Flags().BoolS("parameters", "parameters", false, "Generate metadata for reflection on method parameters")
rootCmd.Flags().StringS("proc", "proc", "", "Control whether annotation processing and/or compilation is done.")
rootCmd.Flags().StringS("processor", "processor", "", "Names of the annotation processors to run; bypasses default discovery process")
rootCmd.Flags().StringS("processorpath", "processorpath", "", "Specify where to find annotation processors")
rootCmd.Flags().String("processor-module-path", "", "Specify a module path where to find annotation processors")
rootCmd.Flags().StringP("processor-path", "processorpath", "", "Specify where to find annotation processors")
rootCmd.Flags().StringS("profile", "profile", "", "Check that API used is available in the specified profile")
rootCmd.Flags().String("release", "", "Compile for a specific VM version")
rootCmd.Flags().BoolS("s", "s", false, "Specify where to place generated source files")
rootCmd.Flags().StringS("source", "source", "", "Provide source compatibility with specified release")
rootCmd.Flags().StringS("sourcepath", "sourcepath", "", "Specify where to find input source files")
rootCmd.Flags().StringP("source-path", "sourcepath", "", "Specify where to find input source files")
rootCmd.Flags().String("system", "", "Override location of system modules")
rootCmd.Flags().StringS("target", "target", "", "Generate class files for specific VM version")
rootCmd.Flags().String("upgrade-module-path", "", "Override location of upgradeable modules")
rootCmd.Flags().BoolS("verbose", "verbose", false, "Output messages about what the compiler is doing")
rootCmd.Flags().BoolS("version", "version", false, "Version information")
rootCmd.Flags().BoolP("version", "version", false, "Version information")

rootCmd.Flag("g").NoOptDefVal = " "
rootCmd.Flag("g").OptargDelimiter = ':'
rootCmd.Flag("implicit").NoOptDefVal = " "
rootCmd.Flag("implicit").OptargDelimiter = ':'
rootCmd.Flag("proc").NoOptDefVal = " "
rootCmd.Flag("proc").OptargDelimiter = ':'

rootCmd.Flag("A").NoOptDefVal = " "
rootCmd.Flag("A").OptargDelimiter = -1
rootCmd.Flag("J").NoOptDefVal = " "
rootCmd.Flag("J").OptargDelimiter = -1

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"bootclasspath": carapace.ActionFiles(".jar", ".zip").UniqueList(":"),
"classpath": carapace.ActionFiles(".jar", ".zip").UniqueList(":"),
"cp": carapace.ActionFiles(".jar", ".zip").UniqueList(":"),
"d": carapace.ActionDirectories(),
"boot-class-path": carapace.ActionFiles(".jar", ".zip").UniqueList(":"),
"class-path": carapace.ActionFiles(".jar", ".zip").UniqueList(":"),
"cp": carapace.ActionFiles(".jar", ".zip").UniqueList(":"),
"d": carapace.ActionDirectories(),
// TODO encoding
"endorseddirs": carapace.ActionDirectories(),
"extdirs": carapace.ActionDirectories(),
Expand All @@ -86,22 +89,33 @@ func init() {
"lines", "Line number debugging information",
"vars", "Local variable debugging information",
).UniqueList(","),
"h": carapace.ActionDirectories(),
"implicit": carapace.ActionValues("none", "class"),
"proc": carapace.ActionValues("none", "only"),
"processorpath": carapace.ActionDirectories(),
"profile": carapace.ActionValues("compact1", "compact2", "compact3"),
"s": carapace.ActionDirectories(),
"source": action.ActionReleases(),
"target": action.ActionReleases(), // TODO limit to `>+ source version`
"h": carapace.ActionDirectories(),
"implicit": carapace.ActionValues("none", "class"),
"module-path": carapace.ActionDirectories(),
"module-source-path": carapace.ActionDirectories(),
"proc": carapace.ActionValues("none", "only"),
"processor-module-path": carapace.ActionDirectories(),
"processor-path": carapace.ActionDirectories(),
"profile": carapace.ActionValues("compact1", "compact2", "compact3"),
"s": carapace.ActionDirectories(),
"source": action.ActionReleases(),
"source-path": carapace.ActionDirectories(),
"system": carapace.ActionValues("jdk", "none"),
"target": action.ActionReleases(), // TODO limit to `>+ source version`
"upgrade-module-path": carapace.ActionDirectories(),
})

carapace.Gen(rootCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if strings.HasPrefix(c.CallbackValue, "@") {
c.CallbackValue = strings.TrimPrefix(c.CallbackValue, "@")
return carapace.ActionFiles().Invoke(c).Prefix("@").ToA()
}
return carapace.ActionFiles(".java")
}),
)

carapace.Gen(rootCmd).PreRun(func(cmd *cobra.Command, args []string) {
os.Setenv("CARAPACE_LENIENT", "1") // TODO hacky -A and -J support for now
})
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/pelletier/go-toml v1.9.5
github.com/rsteube/carapace v0.31.1
github.com/rsteube/carapace v0.32.1
github.com/rsteube/carapace-spec v0.5.2
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
Expand All @@ -20,4 +20,4 @@ require (
github.com/stretchr/testify v1.7.0 // indirect
)

replace github.com/spf13/pflag => github.com/rsteube/carapace-pflag v0.0.4
replace github.com/spf13/pflag => github.com/rsteube/carapace-pflag v0.0.6
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rsteube/carapace v0.31.1 h1:6KPWunJkjuiU5I8nx/ydvI8STldhPcTl8woP5fPV7fw=
github.com/rsteube/carapace v0.31.1/go.mod h1:/ALYHicIpak6TjQnKl7HupclqJydy2LQb6CkawYBxDo=
github.com/rsteube/carapace-pflag v0.0.4 h1:Onb0cLNLxg1xJr2EsMlBldAI5KkybrvZ89b5cRElZXI=
github.com/rsteube/carapace-pflag v0.0.4/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/rsteube/carapace v0.32.1 h1:zoB9W4e7qjkvqNz7qPBLt0euLWIVoZwhaEGMvV8KsTw=
github.com/rsteube/carapace v0.32.1/go.mod h1:/ALYHicIpak6TjQnKl7HupclqJydy2LQb6CkawYBxDo=
github.com/rsteube/carapace-pflag v0.0.6 h1:8qloiXqoRdrX6sU1e+sIq9fYrl8Htrm0V/YY+UUjvVU=
github.com/rsteube/carapace-pflag v0.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/rsteube/carapace-spec v0.5.2 h1:dN2TA5MtgU071z/NwNufPikj+fBXVY+bLMSD1xkO408=
github.com/rsteube/carapace-spec v0.5.2/go.mod h1:NcK3NorH0B/tcE088MbcA8/L8eMf4WkvXb/X4NuSSKU=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down

0 comments on commit dfea6a5

Please sign in to comment.