Skip to content

Commit

Permalink
added carapace
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed May 18, 2021
1 parent 001e92e commit 07aedf0
Show file tree
Hide file tree
Showing 87 changed files with 3,079 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.github/**/node_modules
/CHANGELOG.md
/script/build
.env

# VS Code
.vscode
Expand Down
52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3'

services:
build: &base
image: rsteube/carapace:0.5.1
command: sh -c 'sh -c "cd /gh/cmd/gh/ && go build -ldflags=\"-s -w\" ."'
environment:
TARGET: /gh/cmd/gh/gh
GITHUB_TOKEN: $GITHUB_TOKEN
working_dir: /gh
volumes:
- '.:/gh/'
- 'go:/home/circleci/go/'

bash:
<<: *base
command: bash

elvish:
<<: *base
command: elvish

fish:
<<: *base
command: fish

ion:
<<: *base
command: ion

nushell:
<<: *base
command: nu

oil:
<<: *base
command: osh --completion-display minimal

powershell:
<<: *base
command: pwsh

xonsh:
<<: *base
command: xonsh

zsh:
<<: *base
command: zsh

volumes:
go:
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/muesli/termenv v0.8.1
github.com/rivo/uniseg v0.1.0
github.com/rsteube/carapace v0.5.12
github.com/shurcooL/githubv4 v0.0.0-20200928013246-d292edc3691b
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed
golang.org/x/text v0.3.4 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
Expand Down
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rsteube/carapace v0.5.12 h1:htkAhY/YMBEGdR8VhKaf4tIMZHLNEMw+zUJobE+aWj4=
github.com/rsteube/carapace v0.5.12/go.mod h1:PyIaGGutQyWKcjsoKN7E1tqu8ktOkVF5MYdAd1p4gwE=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
Expand All @@ -248,6 +250,7 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
Expand Down Expand Up @@ -354,8 +357,9 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 h1:dXfMednGJh/SUUFjTLsWJz3P+TQt9qnR11GgeI3vWKs=
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed h1:Ei4bQjjpYUsS4efOUz+5Nz++IVkHk87n2zBA0NxBWc0=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down Expand Up @@ -419,6 +423,7 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/alias/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (

"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -36,6 +38,10 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
},
}

carapace.Gen(cmd).PositionalCompletion(
action.ActionAliases(),
)

return cmd
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import (
"github.com/cli/cli/internal/ghinstance"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/export"
"github.com/cli/cli/pkg/iostreams"
"github.com/cli/cli/pkg/jsoncolor"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -218,6 +220,24 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command
cmd.Flags().StringVarP(&opts.Template, "template", "t", "", "Format the response using a Go template")
cmd.Flags().StringVarP(&opts.FilterOutput, "jq", "q", "", "Query to select values from the response using jq syntax")
cmd.Flags().DurationVar(&opts.CacheTTL, "cache", 0, "Cache the response, e.g. \"3600s\", \"60m\", \"1h\"")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"hostname": action.ActionConfigHosts(),
"method": action.ActionHttpMethods(),
"input": carapace.ActionFiles(),
"preview": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
return action.ActionApiPreviews().Invoke(c).Filter(c.Parts).ToA()
}),
})

carapace.Gen(cmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
v3 := action.ActionApiV3Paths(cmd).Invoke(c)
graphql := carapace.ActionValues("graphql").Invoke(c)
return v3.Merge(graphql).ToA()
}),
)

return cmd
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/cmd/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"github.com/cli/cli/internal/ghinstance"
"github.com/cli/cli/pkg/cmd/auth/shared"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/cli/cli/pkg/prompt"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -116,6 +118,13 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
cmd.Flags().BoolVar(&tokenStdin, "with-token", false, "Read token from standard input")
cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open a browser to authenticate")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"hostname": action.ActionConfigHosts(),
"scopes": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
return action.ActionAuthScopes().Invoke(c).Filter(c.Parts).ToA()
}),
})

return cmd
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/auth/logout/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/cli/cli/api"
"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/cli/cli/pkg/prompt"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -61,6 +63,10 @@ func NewCmdLogout(f *cmdutil.Factory, runF func(*LogoutOptions) error) *cobra.Co

cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "The hostname of the GitHub instance to log out of")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"hostname": action.ActionConfigHosts(),
})

return cmd
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/cmd/auth/refresh/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmd/auth/shared"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/cli/cli/pkg/prompt"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -72,6 +74,13 @@ func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra.
cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "The GitHub host to use for authentication")
cmd.Flags().StringSliceVarP(&opts.Scopes, "scopes", "s", nil, "Additional authentication scopes for gh to have")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"hostname": action.ActionConfigHosts(),
"scopes": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
return action.ActionAuthScopes().Invoke(c).Filter(c.Parts).ToA()
}),
})

return cmd
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/auth/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmd/auth/shared"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -51,6 +53,10 @@ func NewCmdStatus(f *cmdutil.Factory, runF func(*StatusOptions) error) *cobra.Co
cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "Check a specific hostname's auth status")
cmd.Flags().BoolVarP(&opts.ShowToken, "show-token", "t", false, "Display the auth token")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"hostname": action.ActionConfigHosts(),
})

return cmd
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/cmd/config/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,6 +51,19 @@ func NewCmdConfigGet(f *cmdutil.Factory, runF func(*GetOptions) error) *cobra.Co

cmd.Flags().StringVarP(&opts.Hostname, "host", "h", "", "Get per-host setting")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"host": action.ActionConfigHosts(),
})

carapace.Gen(cmd).PositionalCompletion(
carapace.ActionValuesDescribed(
"git_protocol", "What protocol to use when performing git operations.",
"editor", "What editor gh should run when creating issues, pull requests, etc.",
"prompt", "toggle interactive prompting in the terminal",
"pager", "the terminal pager program to send standard output to",
),
)

return cmd
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -55,6 +57,33 @@ func NewCmdConfigSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Co

cmd.Flags().StringVarP(&opts.Hostname, "host", "h", "", "Set per-host setting")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"host": action.ActionConfigHosts(),
})

carapace.Gen(cmd).PositionalCompletion(
carapace.ActionValuesDescribed(
"git_protocol", "What protocol to use when performing git operations.",
"editor", "What editor gh should run when creating issues, pull requests, etc.",
"prompt", "toggle interactive prompting in the terminal",
"pager", "the terminal pager program to send standard output to",
),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
switch c.Args[0] {
case "git_protocol":
return carapace.ActionValues("ssh", "https")
case "editor":
return carapace.ActionValues("emacs", "micro", "nano", "nvim", "vi", "vim")
case "prompt":
return carapace.ActionValues("enabled", "disabled")
case "pager":
return carapace.ActionValues("bat --style header,grid", "more", "most", "less")
default:
return carapace.ActionValues()
}
}),
)

return cmd
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/cmd/gist/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"github.com/cli/cli/git"
"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/cmdutil/action"
"github.com/cli/cli/pkg/iostreams"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -64,6 +66,11 @@ func NewCmdClone(f *cmdutil.Factory, runF func(*CloneOptions) error) *cobra.Comm
return &cmdutil.FlagError{Err: fmt.Errorf("%w\nSeparate git clone flags with '--'.", err)}
})

carapace.Gen(cmd).PositionalCompletion(
action.ActionGists(cmd),
carapace.ActionDirectories(),
)

return cmd
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/gist/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/iostreams"
"github.com/cli/cli/utils"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -99,6 +100,9 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser with created gist")
cmd.Flags().BoolVarP(&opts.Public, "public", "p", false, "List the gist publicly (default: private)")
cmd.Flags().StringVarP(&opts.FilenameOverride, "filename", "f", "", "Provide a filename to be used when reading from STDIN")

carapace.Gen(cmd).PositionalAnyCompletion(carapace.ActionFiles())

return cmd
}

Expand Down

0 comments on commit 07aedf0

Please sign in to comment.