Skip to content

Commit 4ae32fc

Browse files
authored
Merge pull request #872 from rsteube/gh-updates-from-2.5.0
gh: updates from 2.5.0
2 parents 1482f86 + a4fae93 commit 4ae32fc

File tree

17 files changed

+196
-13
lines changed

17 files changed

+196
-13
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package action
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
7+
"github.com/rsteube/carapace"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
type deployKey struct {
12+
Id int
13+
Title string
14+
Key string
15+
}
16+
17+
func ActionDeployKeys(cmd *cobra.Command) carapace.Action {
18+
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
19+
repo, err := repoOverride(cmd)
20+
if err != nil {
21+
return carapace.ActionMessage(err.Error())
22+
}
23+
24+
var queryResult []deployKey
25+
return ApiV3Action(cmd, fmt.Sprintf(`repos/%v/%v/keys`, repo.RepoOwner(), repo.RepoName()), &queryResult, func() carapace.Action {
26+
vals := make([]string, 0)
27+
for _, key := range queryResult {
28+
vals = append(vals, strconv.Itoa(key.Id), fmt.Sprintf("%v %v", key.Title, truncateMiddle(26, key.Key)))
29+
}
30+
return carapace.ActionValuesDescribed(vals...)
31+
})
32+
})
33+
}
34+
35+
func truncateMiddle(maxWidth int, t string) string {
36+
if len(t) <= maxWidth {
37+
return t
38+
}
39+
40+
ellipsis := "..."
41+
if maxWidth < len(ellipsis)+2 {
42+
return t[0:maxWidth]
43+
}
44+
45+
halfWidth := (maxWidth - len(ellipsis)) / 2
46+
remainder := (maxWidth - len(ellipsis)) % 2
47+
return t[0:halfWidth+remainder] + ellipsis + t[len(t)-halfWidth:]
48+
}

completers/gh_completer/cmd/api.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"github.com/rsteube/carapace"
55
"github.com/rsteube/carapace-bin/completers/gh_completer/cmd/action"
6+
"github.com/rsteube/carapace-bin/pkg/actions/net/http"
67
"github.com/spf13/cobra"
78
)
89

@@ -15,21 +16,22 @@ var apiCmd = &cobra.Command{
1516
func init() {
1617
carapace.Gen(apiCmd).Standalone()
1718
apiCmd.Flags().Duration("cache", 0, "Cache the response, e.g. \"3600s\", \"60m\", \"1h\"")
18-
apiCmd.Flags().StringArrayP("field", "F", nil, "Add a typed parameter in `key=value` format")
19-
apiCmd.Flags().StringArrayP("header", "H", nil, "Add a HTTP request header in `key:value` format")
19+
apiCmd.Flags().StringArrayP("field", "F", []string{}, "Add a typed parameter in `key=value` format")
20+
apiCmd.Flags().StringArrayP("header", "H", []string{}, "Add a HTTP request header in `key:value` format")
2021
apiCmd.Flags().String("hostname", "", "The GitHub hostname for the request (default \"github.com\")")
2122
apiCmd.Flags().BoolP("include", "i", false, "Include HTTP response headers in the output")
22-
apiCmd.Flags().String("input", "", "The `file` to use as body for the HTTP request")
23+
apiCmd.Flags().String("input", "", "The `file` to use as body for the HTTP request (use \"-\" to read from standard input)")
2324
apiCmd.Flags().StringP("jq", "q", "", "Query to select values from the response using jq syntax")
2425
apiCmd.Flags().StringP("method", "X", "GET", "The HTTP method for the request")
2526
apiCmd.Flags().Bool("paginate", false, "Make additional HTTP requests to fetch all pages of results")
26-
apiCmd.Flags().StringSliceP("preview", "p", nil, "Opt into GitHub API previews")
27-
apiCmd.Flags().StringArrayP("raw-field", "f", nil, "Add a string parameter in `key=value` format")
27+
apiCmd.Flags().StringSliceP("preview", "p", []string{}, "Opt into GitHub API previews")
28+
apiCmd.Flags().StringArrayP("raw-field", "f", []string{}, "Add a string parameter in `key=value` format")
2829
apiCmd.Flags().Bool("silent", false, "Do not print the response body")
2930
apiCmd.Flags().StringP("template", "t", "", "Format the response using a Go template")
3031
rootCmd.AddCommand(apiCmd)
3132

3233
carapace.Gen(apiCmd).FlagCompletion(carapace.ActionMap{
34+
"header": http.ActionHttpRequestHeaders(),
3335
"hostname": action.ActionConfigHosts(),
3436
"input": carapace.ActionFiles(),
3537
"method": action.ActionHttpMethods(),

completers/gh_completer/cmd/auth_login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var auth_loginCmd = &cobra.Command{
1515
func init() {
1616
carapace.Gen(auth_loginCmd).Standalone()
1717
auth_loginCmd.Flags().StringP("hostname", "h", "", "The hostname of the GitHub instance to authenticate with")
18-
auth_loginCmd.Flags().StringSliceP("scopes", "s", nil, "Additional authentication scopes for gh to have")
18+
auth_loginCmd.Flags().StringSliceP("scopes", "s", []string{}, "Additional authentication scopes for gh to have")
1919
auth_loginCmd.Flags().BoolP("web", "w", false, "Open a browser to authenticate")
2020
auth_loginCmd.Flags().Bool("with-token", false, "Read token from standard input")
2121
authCmd.AddCommand(auth_loginCmd)

completers/gh_completer/cmd/auth_refresh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var auth_refreshCmd = &cobra.Command{
1515
func init() {
1616
carapace.Gen(auth_refreshCmd).Standalone()
1717
auth_refreshCmd.Flags().StringP("hostname", "h", "", "The GitHub host to use for authentication")
18-
auth_refreshCmd.Flags().StringSliceP("scopes", "s", nil, "Additional authentication scopes for gh to have")
18+
auth_refreshCmd.Flags().StringSliceP("scopes", "s", []string{}, "Additional authentication scopes for gh to have")
1919
authCmd.AddCommand(auth_refreshCmd)
2020

2121
carapace.Gen(auth_refreshCmd).FlagCompletion(carapace.ActionMap{

completers/gh_completer/cmd/browse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func init() {
2626
browseCmd.Flags().BoolP("commit", "c", false, "Open the last commit")
2727
browseCmd.Flags().BoolP("no-browser", "n", false, "Print destination URL instead of opening the browser")
2828
browseCmd.Flags().BoolP("projects", "p", false, "Open repository projects")
29+
browseCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
2930
browseCmd.Flags().BoolP("settings", "s", false, "Open repository settings")
3031
browseCmd.Flags().BoolP("wiki", "w", false, "Open repository wiki")
31-
browseCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
3232
rootCmd.AddCommand(browseCmd)
3333

3434
carapace.Gen(browseCmd).FlagCompletion(carapace.ActionMap{

completers/gh_completer/cmd/codespace_ssh.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ var codespace_sshCmd = &cobra.Command{
1515
func init() {
1616
carapace.Gen(codespace_sshCmd).Standalone()
1717
codespace_sshCmd.Flags().StringP("codespace", "c", "", "Name of the codespace")
18+
codespace_sshCmd.Flags().Bool("config", false, "Write OpenSSH configuration to stdout")
1819
codespace_sshCmd.Flags().BoolP("debug", "d", false, "Log debug data to a file")
1920
codespace_sshCmd.Flags().String("debug-file", "", "Path of the file log to")
2021
codespace_sshCmd.Flags().String("profile", "", "Name of the SSH profile to use")
2122
codespace_sshCmd.Flags().Int("server-port", 0, "SSH server port number (0 => pick unused)")
23+
codespace_sshCmd.Flags().Bool("stdio", false, "Proxy sshd connection to stdio")
2224
codespaceCmd.AddCommand(codespace_sshCmd)
2325

2426
carapace.Gen(codespace_sshCmd).FlagCompletion(carapace.ActionMap{

completers/gh_completer/cmd/gist_edit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var gist_editCmd = &cobra.Command{
1515
func init() {
1616
carapace.Gen(gist_editCmd).Standalone()
1717
gist_editCmd.Flags().StringP("add", "a", "", "Add a new file to the gist")
18+
gist_editCmd.Flags().StringP("desc", "d", "", "New description for the gist")
1819
gist_editCmd.Flags().StringP("filename", "f", "", "Select a file to edit")
1920
gistCmd.AddCommand(gist_editCmd)
2021

completers/gh_completer/cmd/gist_view.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ var gist_viewCmd = &cobra.Command{
1313
}
1414

1515
func init() {
16+
carapace.Gen(gist_viewCmd).Standalone()
1617
gist_viewCmd.Flags().StringP("filename", "f", "", "Display a single file from the gist")
17-
gist_viewCmd.Flags().BoolP("files", "", false, "List file names from the gist")
18+
gist_viewCmd.Flags().Bool("files", false, "List file names from the gist")
1819
gist_viewCmd.Flags().BoolP("raw", "r", false, "Print raw instead of rendered gist contents")
1920
gist_viewCmd.Flags().BoolP("web", "w", false, "Open gist in the browser")
2021
gistCmd.AddCommand(gist_viewCmd)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cmd
2+
3+
import (
4+
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/gh_completer/cmd/action"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var release_deleteAssetCmd = &cobra.Command{
10+
Use: "delete-asset",
11+
Short: "Delete an asset from a release",
12+
Run: func(cmd *cobra.Command, args []string) {},
13+
}
14+
15+
func init() {
16+
carapace.Gen(release_deleteAssetCmd).Standalone()
17+
release_deleteAssetCmd.Flags().BoolP("yes", "y", false, "Skip the confirmation prompt")
18+
releaseCmd.AddCommand(release_deleteAssetCmd)
19+
20+
carapace.Gen(release_deleteAssetCmd).PositionalCompletion(
21+
action.ActionReleases(release_deleteAssetCmd),
22+
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
23+
return action.ActionReleaseAssets(release_deleteAssetCmd, c.Args[0])
24+
}),
25+
)
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/gh_completer/cmd/action"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var repo_deployKeyCmd = &cobra.Command{
10+
Use: "deploy-key",
11+
Short: "Manage deploy keys in a repository",
12+
Run: func(cmd *cobra.Command, args []string) {},
13+
}
14+
15+
func init() {
16+
carapace.Gen(repo_deployKeyCmd).Standalone()
17+
repo_deployKeyCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
18+
repoCmd.AddCommand(repo_deployKeyCmd)
19+
20+
carapace.Gen(repo_deployKeyCmd).FlagCompletion(carapace.ActionMap{
21+
"repo": action.ActionRepoOverride(repo_deployKeyCmd),
22+
})
23+
}

0 commit comments

Comments
 (0)