From edf724277ea4c1da0148cb09e8319f8664a8ce51 Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 19 Sep 2023 21:42:27 +0200 Subject: [PATCH] env: fix positional completion --- completers/env_completer/cmd/root.go | 49 ++++++++++ pkg/actions/env/aws.go | 63 +++++++++++++ pkg/actions/env/carapace.go | 25 ++++++ pkg/actions/env/common.go | 21 +++++ pkg/actions/env/common_unix.go | 28 ++++++ pkg/actions/env/docker.go | 35 ++++++++ pkg/actions/env/env.go | 49 ++++++++++ pkg/actions/env/env_test.go | 13 +++ pkg/actions/env/git.go | 84 ++++++++++++++++++ pkg/actions/env/golang.go | 128 +++++++++++++++++++++++++++ pkg/actions/env/nocolor.go | 21 +++++ pkg/actions/env/xdg.go | 29 ++++++ pkg/actions/tools/aws/output.go | 17 ++++ 13 files changed, 562 insertions(+) create mode 100644 pkg/actions/env/aws.go create mode 100644 pkg/actions/env/carapace.go create mode 100644 pkg/actions/env/common.go create mode 100644 pkg/actions/env/common_unix.go create mode 100644 pkg/actions/env/docker.go create mode 100644 pkg/actions/env/env.go create mode 100644 pkg/actions/env/env_test.go create mode 100644 pkg/actions/env/git.go create mode 100644 pkg/actions/env/golang.go create mode 100644 pkg/actions/env/nocolor.go create mode 100644 pkg/actions/env/xdg.go create mode 100644 pkg/actions/tools/aws/output.go diff --git a/completers/env_completer/cmd/root.go b/completers/env_completer/cmd/root.go index 3e44a970e5..eea3109bca 100644 --- a/completers/env_completer/cmd/root.go +++ b/completers/env_completer/cmd/root.go @@ -1,9 +1,14 @@ package cmd import ( + "strings" + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/env" "github.com/rsteube/carapace-bin/pkg/actions/os" "github.com/rsteube/carapace-bin/pkg/actions/ps" + "github.com/rsteube/carapace-bridge/pkg/actions/bridge" + "github.com/rsteube/carapace/pkg/style" "github.com/spf13/cobra" ) @@ -19,6 +24,7 @@ func Execute() error { } func init() { carapace.Gen(rootCmd).Standalone() + rootCmd.Flags().SetInterspersed(false) rootCmd.Flags().String("block-signal", "", "block delivery of SIG signal(s) to COMMAND") rootCmd.Flags().StringP("chdir", "C", "", "change working directory to DIR") @@ -33,6 +39,10 @@ func init() { rootCmd.Flags().StringP("unset", "u", "", "remove variable from the environment") rootCmd.Flags().Bool("version", false, "output version information and exit") + rootCmd.Flag("block-signal").NoOptDefVal = " " + rootCmd.Flag("default-signal").NoOptDefVal = " " + rootCmd.Flag("ignore-signal").NoOptDefVal = " " + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ "block-signal": ps.ActionKillSignals(), "chdir": carapace.ActionDirectories(), @@ -40,4 +50,43 @@ func init() { "ignore-signal": ps.ActionKillSignals(), "unset": os.ActionEnvironmentVariables(), }) + + carapace.Gen(rootCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + for index, arg := range c.Args { + if strings.Contains(arg, "=") { + splitted := strings.SplitN(arg, "=", 2) + c.Setenv(splitted[0], splitted[1]) + } else { + return bridge.ActionCarapaceBin().Shift(index).Invoke(c).ToA() + } + } + + return carapace.Batch( + carapace.ActionMultiPartsN("=", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.Batch( + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + alreadySet := make([]string, 0) + for _, e := range c.Env { + alreadySet = append(alreadySet, strings.SplitN(e, "=", 2)[0]) + } + a := env.ActionKnownEnvironmentVariables().Filter(alreadySet...).Suffix("=") + if !strings.Contains(c.Value, "_") { + return a.MultiParts("_") // only do multipart completion for first underscore + } + return a + }), + os.ActionEnvironmentVariables().Style(style.Blue).Suffix("="), + ).ToA() + default: + return env.ActionEnvironmentVariableValues(c.Parts[0]) + } + }), + carapace.ActionExecutables(), + carapace.ActionFiles(), + ).ToA() + }), + ) } diff --git a/pkg/actions/env/aws.go b/pkg/actions/env/aws.go new file mode 100644 index 0000000000..8890057139 --- /dev/null +++ b/pkg/actions/env/aws.go @@ -0,0 +1,63 @@ +package env + +import ( + "os" + + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/aws" + "github.com/rsteube/carapace-bridge/pkg/actions/bridge" + "github.com/rsteube/carapace/pkg/style" +) + +func init() { + _bool := carapace.ActionValues("true", "false").StyleF(style.ForKeyword) + knownVariables["aws"] = variables{ + Condition: checkPath("aws"), + Names: map[string]string{ + "AWS_ACCESS_KEY_ID": "Specifies an AWS access key associated with an IAM account", + "AWS_CA_BUNDLE": "Specifies the path to a certificate bundle to use for HTTPS certificate validation", + "AWS_CLI_AUTO_PROMPT": "Enables the auto-prompt for the AWS CLI version 2", + "AWS_CLI_FILE_ENCODING": "Specifies the encoding used for text files", + "AWS_CONFIG_FILE": "Specifies the location of the file that the AWS CLI uses to store configuration profiles", + "AWS_DATA_PATH": "A list of additional directories to check outside of the built-in search path of ~/.aws/models", + "AWS_DEFAULT_OUTPUT": "Specifies the output format to use", + "AWS_DEFAULT_REGION": "The Default region name", + "AWS_EC2_METADATA_DISABLED": "Disables the use of the Amazon EC2 instance metadata service (IMDS)", + "AWS_ENDPOINT_URL": "Specifies the endpoint that is used for all service requests", + // "AWS_ENDPOINT_URL_": "pecifies a custom endpoint that is used for a specific service, where is replaced with the AWS service identifier. For example, Amazon DynamoDB has a serviceId of DynamoDB. For this service, the endpoint URL environment variable is AWS_ENDPOINT_URL_DYNAMODB. + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": "If enabled, the AWS CLI ignores all custom endpoint configurations", + "AWS_MAX_ATTEMPTS": "Specifies a value of maximum retry attempts the AWS CLI retry handler uses", + "AWS_METADATA_SERVICE_NUM_ATTEMPTS": "retry multiple times before giving up", + "AWS_METADATA_SERVICE_TIMEOUT": "The number of seconds before a connection to the instance metadata service should time out", + "AWS_PAGER": "Specifies the pager program used for output", + "AWS_PROFILE": "Specifies the name of the AWS CLI profile with the credentials and options to use", + "AWS_REGION": "The AWS SDK compatible environment variable that specifies the AWS Region to send the request to", + "AWS_RETRY_MODE": "Specifies which retry mode AWS CLI uses", + "AWS_ROLE_ARN": "Specifies the Amazon Resource Name (ARN) of an IAM role", + "AWS_ROLE_SESSION_NAME": "Specifies the name to attach to the role session", + "AWS_SECRET_ACCESS_KEY": "Specifies the secret key associated with the access key", + "AWS_SHARED_CREDENTIALS_FILE": "Specifies the location of the file that the AWS CLI uses to store access keys", + "AWS_USE_FIPS_ENDPOINT": "Federal Information Processing Standard (FIPS) endoint", + "AWS_WEB_IDENTITY_TOKEN_FILE": "Specifies the path to a file that contains an OAuth 2.0 access token", + }, + Values: map[string]carapace.Action{ + "AWS_CA_BUNDLE": carapace.ActionFiles(), + "AWS_CLI_AUTO_PROMPT": carapace.ActionValuesDescribed( + "on", "full auto-prompt mode each time you attempt to run an aws command", + "on-partial", "partial auto-prompt mode", + ).StyleF(style.ForKeyword), + "AWS_CONFIG_FILE": carapace.ActionFiles(), + "AWS_DATA_PATH": carapace.ActionDirectories().List(string(os.PathListSeparator)), + "AWS_DEFAULT_OUTPUT": aws.ActionOutputFormats(), + "AWS_DEFAULT_REGION": aws.ActionRegions(), + "AWS_EC2_METADATA_DISABLED": _bool, + "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS": _bool, + "AWS_PAGER": bridge.ActionCarapaceBin().Split(), + "AWS_PROFILE": aws.ActionProfiles(), + "AWS_REGION": aws.ActionRegions(), + "AWS_RETRY_MODE": carapace.ActionValues("legacy", "standard", "adaptive"), + "AWS_SHARED_CREDENTIALS_FILE": carapace.ActionFiles(), + "AWS_WEB_IDENTITY_TOKEN_FILE": carapace.ActionFiles(), + }, + } +} diff --git a/pkg/actions/env/carapace.go b/pkg/actions/env/carapace.go new file mode 100644 index 0000000000..46b2281f88 --- /dev/null +++ b/pkg/actions/env/carapace.go @@ -0,0 +1,25 @@ +package env + +import "github.com/rsteube/carapace" + +func init() { + knownVariables["carapace"] = variables{ + Names: map[string]string{ + "CARAPACE_COVERDIR": "coverage directory for sandbox tests", + "CARAPACE_HIDDEN": "show hidden commands/flags", + "CARAPACE_LENIENT": "allow unknown flags", + "CARAPACE_LOG": "enable logging", + "CARAPACE_MATCH": "match case insensitive", + "CARAPACE_SANDBOX": "mock context for sandbox tests", + "CARAPACE_ZSH_HASH_DIRS": "zsh hash directories", + }, + Values: map[string]carapace.Action{ + "CARAPACE_COVERDIR": carapace.ActionDirectories(), + "CARAPACE_HIDDEN": carapace.ActionValues("0", "1"), + "CARAPACE_LENIENT": carapace.ActionValues("0", "1"), + "CARAPACE_LOG": carapace.ActionValues("0", "1"), + "CARAPACE_MATCH": carapace.ActionValues("0", "1"), + }, + } + +} diff --git a/pkg/actions/env/common.go b/pkg/actions/env/common.go new file mode 100644 index 0000000000..35bec13c4a --- /dev/null +++ b/pkg/actions/env/common.go @@ -0,0 +1,21 @@ +package env + +import ( + _os "os" + + "github.com/rsteube/carapace" +) + +func init() { + knownVariables["common"] = variables{ + Names: map[string]string{ + "HTTP_PROXY": "http proxy server", + "HTTPS_PROXY": "https proxy server", + "PATH": "A list of directories to be searched when executing commands", + }, + Values: map[string]carapace.Action{ + "PATH": carapace.ActionDirectories().List(string(_os.PathListSeparator)).NoSpace(), + }, + } + +} diff --git a/pkg/actions/env/common_unix.go b/pkg/actions/env/common_unix.go new file mode 100644 index 0000000000..41d2530f86 --- /dev/null +++ b/pkg/actions/env/common_unix.go @@ -0,0 +1,28 @@ +package env + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/os" +) + +func init() { + knownVariables["common_unix"] = variables{ + Names: map[string]string{ + "USER": "The current logged in user", + "HOME": "The home directory of the current user", + "EDITOR": "The default file editor to be used", + "SHELL": "The path of the current user’s shell, such as bash or zsh", + "LOGNAME": "The name of the current user", + "LANG": "The current locales settings", + "TERM": "The current terminal emulation", + "MAIL": "Location of where the current user’s mail is stored", + }, + Values: map[string]carapace.Action{ + "HOME": carapace.ActionDirectories(), + "LANG": os.ActionLanguages(), + "LOGNAME": os.ActionUsers(), + "USER": os.ActionUsers(), + }, + } + +} diff --git a/pkg/actions/env/docker.go b/pkg/actions/env/docker.go new file mode 100644 index 0000000000..413d4d4bc3 --- /dev/null +++ b/pkg/actions/env/docker.go @@ -0,0 +1,35 @@ +package env + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace/pkg/style" +) + +func init() { + knownVariables["docker"] = variables{ + Condition: checkPath("docker"), + Names: map[string]string{ + "DOCKER_API_VERSION": "Override the negotiated API version to use for debugging", + "DOCKER_CERT_PATH": "Location of your authentication keys", + "DOCKER_CONFIG": "The location of your client configuration files", + "DOCKER_CONTENT_TRUST_SERVER": "The URL of the Notary server to use", + "DOCKER_CONTENT_TRUST": "When set Docker uses notary to sign and verify images", + "DOCKER_CONTEXT": "Name of the docker context to use", + "DOCKER_DEFAULT_PLATFORM": "Default platform for commands that take the --platform flag", + "DOCKER_HIDE_LEGACY_COMMANDS": "When set, Docker hides \"legacy\" top-level commands", + "DOCKER_HOST": "Daemon socket to connect to", + "DOCKER_TLS_VERIFY": "When set Docker uses TLS and verifies the remote", + "BUILDKIT_PROGRESS": "Set type of progress output", + }, + Values: map[string]carapace.Action{ + "DOCKER_CERT_PATH": carapace.ActionDirectories(), + "DOCKER_CONFIG": carapace.ActionFiles(), + "DOCKER_HIDE_LEGACY_COMMANDS": carapace.ActionStyledValuesDescribed( + "0", "show", style.Carapace.KeywordNegative, + "1", "hide", style.Carapace.KeywordPositive, + ), + "BUILDKIT_PROGRESS": carapace.ActionValues("auto", "plain", "tty"), + }, + } + +} diff --git a/pkg/actions/env/env.go b/pkg/actions/env/env.go new file mode 100644 index 0000000000..1fb26fa58c --- /dev/null +++ b/pkg/actions/env/env.go @@ -0,0 +1,49 @@ +package env + +import ( + "os/exec" + + "github.com/rsteube/carapace" +) + +type variables struct { + Condition func(c carapace.Context) bool + Names map[string]string + Values map[string]carapace.Action +} + +func checkPath(s string) func(c carapace.Context) bool { + return func(c carapace.Context) bool { + _, err := exec.LookPath(s) // TODO copy function to carapace as this needs to use carapace.Context$Env + return err == nil + } +} + +var knownVariables = map[string]variables{} + +func ActionKnownEnvironmentVariables() carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + vals := make([]string, 0) + for _, v := range knownVariables { + if v.Condition != nil && !v.Condition(c) { + continue + } + + for name, description := range v.Names { + vals = append(vals, name, description) + } + } + return carapace.ActionValuesDescribed(vals...) + }).Tag("known environment variables") +} + +func ActionEnvironmentVariableValues(s string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + for _, v := range knownVariables { + if action, ok := v.Values[s]; ok { + return action + } + } + return carapace.ActionFiles() + }) +} diff --git a/pkg/actions/env/env_test.go b/pkg/actions/env/env_test.go new file mode 100644 index 0000000000..1a48a96073 --- /dev/null +++ b/pkg/actions/env/env_test.go @@ -0,0 +1,13 @@ +package env + +import "testing" + +func TestKnownVariables(t *testing.T) { + for k, v := range knownVariables { + for name := range v.Values { + if _, ok := v.Names[name]; !ok { + t.Errorf("variables %#v is unknown in %#v", name, k) + } + } + } +} diff --git a/pkg/actions/env/git.go b/pkg/actions/env/git.go new file mode 100644 index 0000000000..ebfd9ae152 --- /dev/null +++ b/pkg/actions/env/git.go @@ -0,0 +1,84 @@ +package env + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/net/http" + "github.com/rsteube/carapace-bin/pkg/actions/time" + "github.com/rsteube/carapace-bin/pkg/actions/tools/git" + "github.com/rsteube/carapace/pkg/style" + "github.com/spf13/cobra" +) + +func init() { + _bool := carapace.ActionValues("true", "false").StyleF(style.ForKeyword) + knownVariables["git"] = variables{ + Condition: checkPath("git"), + Names: map[string]string{ + "GIT_ALTERNATE_OBJECT_DIRECTORIES": "is a colon-separated list which tells Git where to check for objects", + "GIT_ASKPASS": "is an override for the core.askpass configuration value", + "GIT_AUTHOR_DATE": "is the timestamp used for the “author” field", + "GIT_AUTHOR_EMAIL": "is the email for the “author” field", + "GIT_AUTHOR_NAME": "is the human-readable name in the “author” field", + "GIT_CEILING_DIRECTORIES": "controls the behavior of searching for a .git directory", + "GIT_COMMITTER_DATE": "is used for the timestamp in the “committer” field", + "GIT_COMMITTER_EMAIL": "is the email address for the “committer” field", + "GIT_COMMITTER_NAME": "sets the human name for the “committer” field", + "GIT_CONFIG_NOSYSTEM": "if set, disables the use of the system-wide configuration file", + "GIT_DIFF_OPTS": "controls the number of context lines shown in a git diff command", + "GIT_DIFF_PATH_COUNTER": "represents which file in a series is being diffed (starting with 1)", + "GIT_DIFF_PATH_TOTAL": "total number of files in the batch", + "GIT_DIR": "is the location of the .git folder", + "GIT_EDITOR": "is the editor Git will launch when the user needs to edit some text", + "GIT_EXEC_PATH": "determines where Git looks for its sub-programs", + "GIT_EXTERNAL_DIFF": "is used as an override for the diff.external configuration value", + "GIT_FLUSH": "can be used to force Git to use non-buffered I/O when writing incrementally to stdout", + "GIT_GLOB_PATHSPECS": "controls the default behavior of wildcards in pathspecs", + "GIT_HTTP_USER_AGENT": "sets the user-agent string used by Git when communicating over HTTP", + "GIT_ICASE_PATHSPECS": "sets all pathspecs to work in a case-insensitive manner", + "GIT_INDEX_FILE": "is the path to the index file (non-bare repositories only)", + "GIT_LITERAL_PATHSPECS": "disables both of the above behaviors", + "GIT_MERGE_VERBOSITY": "controls the output for the recursive merge strategy", + "GIT_NAMESPACE": "controls access to namespaced refs", + "GIT_NOGLOB_PATHSPECS": "controls the default behavior of wildcards in pathspecs", + "GIT_OBJECT_DIRECTORY": "can be used to specify the location of the directory that usually resides at .git/objects", + "GIT_PAGER": "controls the program used to display multi-page output on the command line", + "GIT_REFLOG_ACTION": "lets you specify the descriptive text written to the reflog", + "GIT_SSH": "a program that is invoked instead of ssh when Git tries to connect to an SSH host", + "GIT_SSH_COMMAND": "sets the SSH command used when Git tries to connect to an SSH host", + "GIT_SSL_NO_VERIFY": "tells Git not to verify SSL certificates", + "GIT_TRACE": "controls general traces, which don’t fit into any specific category", + "GIT_TRACE_PACK_ACCESS": "controls tracing of packfile access", + "GIT_TRACE_PACKET": "enables packet-level tracing for network operations", + "GIT_TRACE_PERFORMANCE": "controls logging of performance data", + "GIT_TRACE_SETUP": "shows information about what Git is discovering about the repository and environment it’s interacting with", + "GIT_WORK_TREE": "is the location of the root of the working directory for a non-bare repository", + }, + Values: map[string]carapace.Action{ + // TODO complete more variables + "GIT_ALTERNATE_OBJECT_DIRECTORIES": carapace.ActionDirectories().MultiParts(":"), + "GIT_ASKPASS": git.ActionConfigValues("core.askpass"), + "GIT_CEILING_DIRECTORIES": carapace.ActionDirectories().MultiParts("").NoSpace(), + "GIT_COMMITTER_DATE": time.ActionDate(), + "GIT_CONFIG_NOSYSTEM": _bool, + "GIT_DIR": carapace.ActionDirectories(), + "GIT_EXTERNAL_DIFF": git.ActionConfigValues("diff.external"), + "GIT_DIFF_OPTS": carapace.ActionCallback(func(c carapace.Context) carapace.Action { + cmd := &cobra.Command{} + carapace.Gen(cmd).Standalone() + cmd.Flags().StringP("unified", "U", "", "Generate diffs with lines of context instead of the usual three") + return carapace.ActionExecute(cmd) + }).Split(), + "GIT_EDITOR": git.ActionConfigValues("core.editor"), + "GIT_EXEC_PATH": carapace.ActionDirectories(), + "GIT_FLUSH": carapace.ActionValuesDescribed( + "0", "buffer all output", + "1", "flush more often", + ), + "GIT_HTTP_USER_AGENT": http.ActionUserAgents(), + "GIT_INDEX_FILE": carapace.ActionFiles(), + "GIT_OBJECT_DIRECTORY": carapace.ActionDirectories(), + "GIT_PAGER": git.ActionConfigValues("core.pager"), + "GIT_WORK_TREE": carapace.ActionDirectories(), + }, + } +} diff --git a/pkg/actions/env/golang.go b/pkg/actions/env/golang.go new file mode 100644 index 0000000000..0922f9e75a --- /dev/null +++ b/pkg/actions/env/golang.go @@ -0,0 +1,128 @@ +package env + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/golang" + "github.com/rsteube/carapace-bridge/pkg/actions/bridge" + "github.com/rsteube/carapace/pkg/style" +) + +func init() { + knownVariables["golang"] = variables{ + Names: map[string]string{ + "AR": "The command to use to manipulate library archives when building with the gccgo compiler", + "CC": "The command to use to compile C code", + "CGO_CFFLAGS_ALLOW": "Like CGO_CFLAGS_ALLOW but for the Fortran compiler", + "CGO_CFFLAGS_DISALLOW": "Like CGO_CFLAGS_DISALLOW but for the Fortran compiler", + "CGO_CFFLAGS": "Like CGO_CFLAGS but for the Fortran compiler", + "CGO_CFLAGS_ALLOW": "A regular expression specifying additional flags to allow to appear in #cgo CFLAGS source code directives", + "CGO_CFLAGS_DISALLOW": "A regular expression specifying flags that must be disallowed from appearing in #cgo CFLAGS source code directives", + "CGO_CFLAGS": "Flags that cgo will pass to the compiler when compiling C code", + "CGO_CPPFLAGS_ALLOW": "Like CGO_CFLAGS_ALLOW but for the C preprocessor", + "CGO_CPPFLAGS_DISALLOW": "Like CGO_CFLAGS_DISALLOW but for the C preprocessor", + "CGO_CPPFLAGS": "Like CGO_CFLAGS but for the C preprocessor", + "CGO_CXXFLAGS_ALLOW": "Like CGO_CFLAGS_ALLOW but for the C++ compiler", + "CGO_CXXFLAGS_DISALLOW": "Like CGO_CFLAGS_DISALLOW but for the C++ compiler", + "CGO_CXXFLAGS": "Like CGO_CFLAGS but for the C++ compiler", + "CGO_ENABLED": "Whether the cgo command is supported", + "CGO_LDFLAGS_ALLOW": "Like CGO_CFLAGS_ALLOW but for the linker", + "CGO_LDFLAGS_DISALLOW": "Like CGO_CFLAGS_DISALLOW but for the linker", + "CGO_LDFLAGS": "Like CGO_CFLAGS but for the linker", + "CXX": "The command to use to compile C++ code", + "FC": "The command to use to compile Fortran code", + "GCCGO": "The gccgo command to run for 'go build -compiler=gccgo'", + "GCCGOTOOLDIR": "If set, where to find gccgo tools, such as cgo", + "GO111MODULE": "Controls whether the go command runs in module-aware mode or GOPATH mode", + "GO386": "For GOARCH=386, how to implement floating point instructions", + "GOAMD64": "For GOARCH=amd64, the microarchitecture level for which to compile", + "GOARCH": "The architecture, or processor, for which to compile code", + "GOARM": "For GOARCH=arm, the ARM architecture for which to compile", + "GOBIN": "The directory where 'go install' will install a command", + "GOCACHE": "The directory where the go command will store cached information for reuse in future builds", + "GOCOVERDIR": "Directory into which to write code coverage data", + "GODEBUG": "Enable various debugging facilities", + "GOENV": "The location of the Go environment configuration file", + "GOEXE": "The executable file name suffix (\".exe\" on Windows, \"\" on other systems)", + "GOEXPERIMENT": "Comma-separated list of toolchain experiments to enable or disable", + "GO_EXTLINK_ENABLED": "Whether the linker should use external linking mode", + "GOFLAGS": "A space-separated list of -flag=value settings to apply to go commands by default", + "GOGCCFLAGS": "A space-separated list of arguments supplied to the CC command", + "GOHOSTARCH": "The architecture (GOARCH) of the Go toolchain binaries", + "GOHOSTOS": "The operating system (GOOS) of the Go toolchain binaries", + "GOINSECURE": "Comma-separated list of glob patterns", + "GOMIPS64": "For GOARCH=mips64{,le}, whether to use floating point instructions", + "GOMIPS": "For GOARCH=mips{,le}, whether to use floating point instructions", + "GOMODCACHE": "The directory where the go command will store downloaded modules", + "GOMOD": "The absolute path to the go.mod of the main module", + "GONOPROXY": "Comma-separated list of glob patterns", + "GONOSUMDB": "Comma-separated list of glob patterns", + "GOOS": "The operating system for which to compile code", + "GOPATH": "Controls where various files are stored", + "GOPPC64": "For GOARCH=ppc64{,le}, the target ISA (Instruction Set Architecture)", + "GOPRIVATE": "Comma-separated list of glob patterns", + "GOPROXY": "URL of Go module proxy", + "GOROOT_FINAL": "The root of the installed Go tree, when it is installed in a location other than where it is built", + "GOROOT": "The root of the go tree", + "GOSUMDB": "The name of checksum database to use and optionally its public key and URL", + "GOTMPDIR": "The directory where the go command will write temporary source files, packages, and binaries", + "GOTOOLCHAIN": "Controls which Go toolchain is used", + "GOTOOLDIR": "The directory where the go tools (compile, cover, doc, etc...) are installed", + "GOVCS": "Lists version control commands that may be used with matching servers", + "GOVERSION": "The version of the installed Go tree, as reported by runtime.Version", + "GOWASM": "For GOARCH=wasm, comma-separated list of experimental WebAssembly features to use", + "GOWORK": "In module aware mode, use the given go.work file as a workspace file", + "PKG_CONFIG": "Path to pkg-config tool", + }, + Values: map[string]carapace.Action{ + // TODO more flags + "AR": bridge.ActionCarapaceBin().Split(), + "CC": bridge.ActionCarapaceBin().Split(), + "CGO_ENABLED": carapace.ActionStyledValuesDescribed( + "0", "disabled", style.Carapace.KeywordNegative, + "1", "enabled", style.Carapace.KeywordPositive, + ), + "CXX": bridge.ActionCarapaceBin().Split(), + "FC": bridge.ActionCarapaceBin().Split(), + "GCCGO": bridge.ActionCarapaceBin().Split(), + "GCCGOTOOLDIR": carapace.ActionDirectories(), + "GO111MODULE": carapace.ActionValues("off", "on", "auto").StyleF(style.ForKeyword), + "GOARCH": golang.ActionArchitectures(), + "GOBIN": carapace.ActionDirectories(), + "GOCACHE": carapace.ActionDirectories(), + "GOENV": carapace.Batch( + carapace.ActionFiles(), + carapace.ActionValues("off").StyleF(style.ForKeyword), + ).ToA(), + "GOMODCACHE": carapace.ActionDirectories(), + "GOOS": golang.ActionOperatingSystems(), + "GOTMPDIR": carapace.ActionDirectories(), + "GOTOOLCHAIN": carapace.ActionMultiPartsN("+", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return golang.ActionVersions().Prefix("go") + default: + return carapace.ActionValues("auto").StyleF(style.ForKeyword) + } + }), + "GOVCS": carapace.ActionMultiPartsN(":", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionValues("public", "private").StyleF(style.ForKeyword).Suffix(":") + default: + return carapace.ActionValuesDescribed( + "all", "", + "bzr", "Bazaar", + "fossil", "Fossil", + "git", "Git", + "hg", "Mercurial", + "off", "", + "svn", "Subversion", + ).StyleF(style.ForKeyword).UniqueList("|") + } + }).List(","), + "GOWORK": carapace.ActionFiles(), + "PKG_CONFIG": carapace.ActionFiles(), + }, + } + +} diff --git a/pkg/actions/env/nocolor.go b/pkg/actions/env/nocolor.go new file mode 100644 index 0000000000..5ba3ea0f5e --- /dev/null +++ b/pkg/actions/env/nocolor.go @@ -0,0 +1,21 @@ +package env + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace/pkg/style" +) + +func init() { + knownVariables["nocolor"] = variables{ + Names: map[string]string{ + "NO_COLOR": "disable colors in supported commands", + }, + Values: map[string]carapace.Action{ + "NO_COLOR": carapace.ActionStyledValuesDescribed( + "0", "show colors", style.Carapace.KeywordNegative, + "1", "do not show colors", style.Carapace.KeywordPositive, + ), + }, + } + +} diff --git a/pkg/actions/env/xdg.go b/pkg/actions/env/xdg.go new file mode 100644 index 0000000000..0482ac355a --- /dev/null +++ b/pkg/actions/env/xdg.go @@ -0,0 +1,29 @@ +package env + +import ( + "github.com/rsteube/carapace" +) + +func init() { + knownVariables["xdg"] = variables{ + Names: map[string]string{ + "XDG_DATA_HOME": "base directory relative to which user-specific data files should be stored", + "XDG_CONFIG_HOME": "base directory relative to which user-specific configuration files should be stored", + "XDG_STATE_HOME": "base directory relative to which user-specific state files should be stored", + "XDG_DATA_DIRS": "base directories to search for data files", + "XDG_CONFIG_DIRS": "base directories to search for configuration files", + "XDG_CACHE_HOME": "base directory relative to which user-specific non-essential data files should be stored", + "XDG_RUNTIME_DIR": "base directory relative to which user-specific non-essential runtime files should be stored", + }, + Values: map[string]carapace.Action{ + "XDG_DATA_HOME": carapace.ActionDirectories(), + "XDG_CONFIG_HOME": carapace.ActionDirectories(), + "XDG_STATE_HOME": carapace.ActionDirectories(), + "XDG_DATA_DIRS": carapace.ActionDirectories().List(":"), + "XDG_CONFIG_DIRS": carapace.ActionDirectories().List(":"), + "XDG_CACHE_HOME": carapace.ActionDirectories(), + "XDG_RUNTIME_DIR": carapace.ActionDirectories(), + }, + } + +} diff --git a/pkg/actions/tools/aws/output.go b/pkg/actions/tools/aws/output.go new file mode 100644 index 0000000000..88bc3b28bc --- /dev/null +++ b/pkg/actions/tools/aws/output.go @@ -0,0 +1,17 @@ +package aws + +import "github.com/rsteube/carapace" + +// ActionOutputFormats completes output formats +// +// json (The output is formatted as a JSON string) +// yaml (The output is formatted as a YAML string) +func ActionOutputFormats() carapace.Action { + return carapace.ActionValuesDescribed( + "json", "The output is formatted as a JSON string", + "yaml", "The output is formatted as a YAML string", + "yaml-stream", "The output is streamed and formatted as a YAML string", + "text", "The output is formatted as multiple lines of tab-separated string values", + "table", "The output is formatted as a table", + ) +}