-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
427 lines (354 loc) · 17.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
package main
import (
"flag"
"fmt"
"github.com/jxskiss/mcli"
)
func main() {
optCategoryCoreCommands := mcli.WithCategory("Core Commands")
optCategoryActionsCommands := mcli.WithCategory("Actions Commands")
optCategoryAdditionalCommands := mcli.WithCategory("Additional Commands")
mcli.SetOptions(mcli.Options{
EnableFlagCompletionForAllCommands: true,
})
mcli.Add("browse", Example_githubCliCommandBrowse, "Open the repository in the browser",
optCategoryCoreCommands)
mcli.Add("actions", dummyCmd, "Learn about working with GitHub Actions",
optCategoryCoreCommands)
mcli.AddGroup("issue", "Manage issues",
optCategoryCoreCommands)
mcli.Add("issue close", Example_githubCliCommandIssueClose, "Close issue")
mcli.Add("issue comment", Example_githubCliCommandIssueComment, "Create a new issue comment")
mcli.Add("issue create", Example_githubCliCommandIssueCreate, "Create a new issue")
mcli.Add("issue delete", dummyCmd, "Delete issue")
mcli.Add("issue edit", Example_githubCliCommandIssueEdit, "Edit an issue")
mcli.Add("issue list", dummyCmd, "List and filter issues in this repository")
mcli.Add("issue reopen", dummyCmd, "Reopen issue")
mcli.Add("issue status", dummyCmd, "Show status of relevant issues")
mcli.Add("issue transfer", dummyCmd, "Transfer issue to another repository")
mcli.Add("issue view", dummyCmd, "View an issue")
mcli.AddGroup("codespace", "Connect to and manage your codespaces",
optCategoryCoreCommands)
mcli.Add("codespace code", dummyCmd, "Open a codespace in Visual Studio Code")
mcli.Add("codespace cp", dummyCmd, "Copy files between local and remote file systems")
mcli.Add("codespace create", dummyCmd, "Create a codespace")
mcli.Add("codespace delete", dummyCmd, "Delete a codespace")
mcli.Add("codespace list", dummyCmd, "List your codespaces")
mcli.Add("codespace logs", dummyCmd, "Access codespace logs")
mcli.Add("codespace ports", dummyCmd, "List ports in a codespace")
mcli.Add("codespace ssh", dummyCmd, "SSH into a codespace")
mcli.Add("codespace stop", dummyCmd, "Stop a running codespace")
mcli.AddGroup("gist", "Manage gists",
optCategoryCoreCommands)
mcli.Add("gist clone", dummyCmd, "Clone a gist locally")
mcli.Add("gist create", dummyCmd, "Create a new gist")
mcli.Add("gist delete", dummyCmd, "Delete a gist")
mcli.Add("gist edit", dummyCmd, "Edit one of your gists")
mcli.Add("gist list", dummyCmd, "List your gists")
mcli.Add("gist view", dummyCmd, "View a gist")
mcli.AddGroup("pr", "Manage pull requests",
optCategoryCoreCommands)
mcli.Add("pr checkout", dummyCmd, "Check out a pull request in git")
mcli.Add("pr checks", dummyCmd, "Show CI status for a single pull request")
mcli.Add("pr close", dummyCmd, "Close a pull request")
mcli.Add("pr comment", dummyCmd, "Create a new pr comment")
mcli.Add("pr create", dummyCmd, "Create a pull request")
mcli.Add("pr diff", dummyCmd, "View changes in a pull request")
mcli.Add("pr edit", dummyCmd, "Edit a pull request")
mcli.Add("pr list", dummyCmd, "List and filter pull requests in this repository")
mcli.Add("pr merge", dummyCmd, "Merge a pull request")
mcli.Add("pr ready", dummyCmd, "Mark a pull request as ready for review")
mcli.Add("pr reopen", dummyCmd, "Reopen a pull request")
mcli.Add("pr review", dummyCmd, "Add a review to a pull request")
mcli.Add("pr status", dummyCmd, "Show status of relevant pull requests")
mcli.Add("pr view", dummyCmd, "View a pull request")
mcli.AddGroup("release", "Manage GitHub releases",
optCategoryCoreCommands)
mcli.Add("release create", dummyCmd, "Create a new release")
mcli.Add("release delete", dummyCmd, "Delete a release")
mcli.Add("release download", dummyCmd, "Download release assets")
mcli.Add("release list", dummyCmd, "List releases in a repository")
mcli.Add("release upload", dummyCmd, "Upload assets to a release")
mcli.Add("release view", dummyCmd, "View information about a release")
mcli.AddGroup("repo", "Create, clone, fork, and view repositories",
optCategoryCoreCommands)
mcli.Add("repo archive", dummyCmd, "Archive a repository")
mcli.Add("repo clone", dummyCmd, "Clone a repository locally")
mcli.Add("repo create", dummyCmd, "Create a new repository")
mcli.Add("repo delete", dummyCmd, "Delete a repository")
mcli.Add("repo edit", dummyCmd, "Edit repository settings")
mcli.Add("repo fork", dummyCmd, "Create a fork of a repository")
mcli.Add("repo list", dummyCmd, "List repositories owned by user or organization")
mcli.Add("repo rename", dummyCmd, "Rename a repository")
mcli.Add("repo sync", dummyCmd, "Sync a repository")
mcli.Add("repo view", dummyCmd, "View a repository")
mcli.AddGroup("run", "View details about workflow runs",
optCategoryActionsCommands)
mcli.Add("run cancel", dummyCmd, "Cancel a workflow run")
mcli.Add("run download", dummyCmd, "Download artifacts generated by a workflow run")
mcli.Add("run list", dummyCmd, "List recent workflow runs")
mcli.Add("run rerun", dummyCmd, "Rerun a failed run")
mcli.Add("run view", dummyCmd, "View a summary of a workflow run")
mcli.Add("run watch", dummyCmd, "Watch a run until it completes, showing its progress")
mcli.AddGroup("workflow", "View details about GitHub Actions workflows",
optCategoryActionsCommands)
mcli.Add("workflow disable", dummyCmd, "Disable a workflow")
mcli.Add("workflow enable", dummyCmd, "Enable a workflow")
mcli.Add("workflow list", dummyCmd, "List workflows")
mcli.Add("workflow run", dummyCmd, "Run a workflow by creating a workflow_dispatch event")
mcli.Add("workflow view", dummyCmd, "View the summary of a workflow")
mcli.AddGroup("alias", "Create command shortcuts",
optCategoryAdditionalCommands)
mcli.Add("alias delete", dummyCmd, "Delete an alias")
mcli.Add("alias list", dummyCmd, "List your aliases")
mcli.Add("alias set", dummyCmd, "Create a shortcut for a gh command")
mcli.Add("api", dummyCmd, "Make an authenticated GitHub API request",
optCategoryAdditionalCommands)
mcli.AddGroup("auth", "Login, logout, and refresh your authentication",
optCategoryCoreCommands)
mcli.Add("auth login", dummyCmd, "Authenticate with a GitHub host")
mcli.Add("auth logout", dummyCmd, "Log out of a GitHub host")
mcli.Add("auth refresh", dummyCmd, "Refresh stored authentication credentials")
mcli.Add("auth setup-git", dummyCmd, "Configure git to use GitHub CLI as a credential helper")
mcli.Add("auth status", dummyCmd, "View authentication status")
mcli.AddGroup("config", "Manage configuration for gh",
optCategoryAdditionalCommands)
mcli.Add("config get", dummyCmd, "Print the value of a given configuration key")
mcli.Add("config list", dummyCmd, "Print a list of configuration keys and values")
mcli.Add("config set", dummyCmd, "Update configuration with a value for the given key")
mcli.AddGroup("extension", "Manage gh extensions",
optCategoryAdditionalCommands)
mcli.Add("extension create", dummyCmd, "Create a new extension")
mcli.Add("extension install", dummyCmd, "Install a gh extension from a repository")
mcli.Add("extension list", dummyCmd, "List installed extension commands")
mcli.Add("extension remove", dummyCmd, "Remove an installed extension")
mcli.Add("extension upgrade", dummyCmd, "Upgrade installed extensions")
mcli.AddGroup("gpg-key", "Manage GPG keys",
optCategoryAdditionalCommands)
mcli.Add("gpg-key add", dummyCmd, "Add a GPG key to your GitHub account")
mcli.Add("gpg-key list", dummyCmd, "Lists GPG keys in your GitHub account")
mcli.AddGroup("secret", "Manage GitHub secrets",
optCategoryAdditionalCommands)
mcli.Add("secret list", dummyCmd, "List secrets")
mcli.Add("secret remove", dummyCmd, "Remove secrets")
mcli.Add("secret set", dummyCmd, "Create or update secrets")
mcli.AddGroup("ssh-key", "Manage SSH keys",
optCategoryAdditionalCommands)
mcli.Add("ssh-key add", dummyCmd, "Add an SSH key to your GitHub account")
mcli.Add("ssh-key list", dummyCmd, "Lists SSH keys in your GitHub account")
// Enable the "help" command.
mcli.AddHelp()
// Enable auto-completion.
mcli.AddCompletion()
mcli.Run()
}
/*
Open the GitHub repository in the web browser.
USAGE
gh browse [<number> | <path>] [flags]
FLAGS
-b, --branch string Select another branch by passing in the branch name
-c, --commit Open the last commit
-n, --no-browser Print destination URL instead of opening the browser
-p, --projects Open repository projects
-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format
-s, --settings Open repository settings
-w, --wiki Open repository wiki
INHERITED FLAGS
--help Show help for command
ARGUMENTS
A browser location can be specified using arguments in the following format:
- by number for issue or pull request, e.g. "123"; or
- by path for opening folders and files, e.g. "cmd/gh/main.go"
EXAMPLES
$ gh browse
#=> Open the home page of the current repository
$ gh browse 217
#=> Open issue or pull request 217
$ gh browse --settings
#=> Open repository settings
$ gh browse main.go:312
#=> Open main.go at line 312
$ gh browse main.go --branch main
#=> Open main.go in the main branch
ENVIRONMENT VARIABLES
To configure a web browser other than the default, use the BROWSER environment variable.
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
*/
func Example_githubCliCommandBrowse() {
args := struct {
Branch string `cli:"-b, --branch, Select another branch by passing in the branch name"`
Commit bool `cli:"-c, --commit, Open the last commit"`
NoBrowser bool `cli:"-n, --no-browser, Print destination URL instead of opening the browser"`
Projects bool `cli:"-p, --projects, Open repository projects"`
Repo string `cli:"-R, --repo, Select another repository using the '[HOST/]OWNER/REPO' format"`
Settings bool `cli:"-s, --settings, Open repository settings"`
Wiki bool `cli:"-w, --wiki, Open repository wiki"`
Location string `cli:"location, A browser location can be specified using arguments in the following format:\n- by number for issue or pull request, e.g. \"123\"; or\n- by path for opening folders and files, e.g. \"cmd/gh/main.go\""`
}{}
_, err := mcli.Parse(&args, mcli.WithErrorHandling(flag.ContinueOnError))
if err != nil && err != flag.ErrHelp {
fmt.Printf("mcli.Parse error: %v", err)
fmt.Println()
}
}
type CommonIssueArgs struct {
Repo string `cli:"-R, --repo, Select another repository using the '[HOST/]OWNER/REPO' format"`
}
/*
Close issue
USAGE
gh issue close {<number> | <url>} [flags]
INHERITED FLAGS
--help Show help for command
-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
*/
func Example_githubCliCommandIssueClose() {
var args struct {
CommonIssueArgs
}
_, err := mcli.Parse(&args, mcli.WithErrorHandling(flag.ContinueOnError))
if err != nil && err != flag.ErrHelp {
fmt.Printf("mcli.Parse error: %v", err)
fmt.Println()
}
}
/*
Create a new issue comment
USAGE
gh issue comment {<number> | <url>} [flags]
FLAGS
-b, --body string Supply a body. Will prompt for one otherwise.
-F, --body-file file Read body text from file (use "-" to read from standard input)
-e, --editor Add body using editor
-w, --web Add body in browser
INHERITED FLAGS
--help Show help for command
-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format
EXAMPLES
$ gh issue comment 22 --body "I was able to reproduce this issue, lets fix it."
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
*/
func Example_githubCliCommandIssueComment() {
var args struct {
Body string `cli:"-b, --body Supply a body. Will prompt for one otherwise."`
BodyFile string `cli:"-F, --body-file Read body text from 'file' (use \"-\" to read from standard input)"`
Editor bool `cli:"-e, --editor, Add body using editor"`
Web bool `cli:"-w, --web, Add body in browser"`
CommonIssueArgs
}
_, err := mcli.Parse(&args, mcli.WithErrorHandling(flag.ContinueOnError))
if err != nil && err != flag.ErrHelp {
fmt.Printf("mcli.Parse error: %v", err)
fmt.Println()
}
}
/*
Create a new issue
USAGE
gh issue create [flags]
FLAGS
-a, --assignee login Assign people by their login. Use "@me" to self-assign.
-b, --body string Supply a body. Will prompt for one otherwise.
-F, --body-file file Read body text from file (use "-" to read from standard input)
-l, --label name Add labels by name
-m, --milestone name Add the issue to a milestone by name
-p, --project name Add the issue to projects by name
--recover string Recover input from a failed run of create
-t, --title string Supply a title. Will prompt for one otherwise.
-w, --web Open the browser to create an issue
INHERITED FLAGS
--help Show help for command
-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format
EXAMPLES
$ gh issue create --title "I found a bug" --body "Nothing works"
$ gh issue create --label "bug,help wanted"
$ gh issue create --label bug --label "help wanted"
$ gh issue create --assignee monalisa,hubot
$ gh issue create --assignee "@me"
$ gh issue create --project "Roadmap"
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
*/
func Example_githubCliCommandIssueCreate() {
var args struct {
Assignee string `cli:"-a, --assignee Assign people by their 'login'. Use \"@me\" to self-assign."`
Body string `cli:"-b, --body Supply a body. Will prompt for one otherwise."`
BodyFile string `cli:"-F, --body-file Read body text from 'file' (use \"-\" to read from standard input)"`
Label string `cli:"-l, --label Add labels by 'name'"`
Milestone string `cli:"-m, --milestone Add the issue to a milestone by 'name'"`
Project string `cli:"-p, --project Add the issue to projects by 'name'"`
Recover string `cli:" --recover Recover input from a failed run of create"`
Title string `cli:"-t, --title Supply a title. Will prompt for one otherwise."`
Web bool `cli:"-w, --web Open the browser to create an issue"`
CommonIssueArgs
}
_, err := mcli.Parse(&args, mcli.WithErrorHandling(flag.ContinueOnError))
if err != nil && err != flag.ErrHelp {
fmt.Printf("mcli.Parse error: %v", err)
fmt.Println()
}
}
/*
Edit an issue
USAGE
gh issue edit {<number> | <url>} [flags]
FLAGS
--add-assignee login Add assigned users by their login. Use "@me" to assign yourself.
--add-label name Add labels by name
--add-project name Add the issue to projects by name
-b, --body string Set the new body.
-F, --body-file file Read body text from file (use "-" to read from standard input)
-m, --milestone name Edit the milestone the issue belongs to by name
--remove-assignee login Remove assigned users by their login. Use "@me" to unassign yourself.
--remove-label name Remove labels by name
--remove-project name Remove the issue from projects by name
-t, --title string Set the new title.
INHERITED FLAGS
--help Show help for command
-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format
EXAMPLES
$ gh issue edit 23 --title "I found a bug" --body "Nothing works"
$ gh issue edit 23 --add-label "bug,help wanted" --remove-label "core"
$ gh issue edit 23 --add-assignee "@me" --remove-assignee monalisa,hubot
$ gh issue edit 23 --add-project "Roadmap" --remove-project v1,v2
$ gh issue edit 23 --milestone "Version 1"
$ gh issue edit 23 --body-file body.txt
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
*/
func Example_githubCliCommandIssueEdit() {
// The description don't need to be aligned.
var args struct {
AddAssignee []string `cli:"--add-assignee Add assigned users by their 'login'. Use \"@me\" to assign yourself."`
AddLabel string `cli:"--add-label Add labels by 'name'"`
AddProject string `cli:"--add-project Add the issue to projects by 'name'"`
Body string `cli:"-b, --body Set the new body."`
BodyFile string `cli:"-F, --body-file Read body text from 'file' (use \"-\" to read from standard input)"`
Milestone string `cli:"-m, --milestone Edit the milestone the issue belongs to by 'name'"`
RemoveAssignee string `cli:"--remove-assignee Remove assigned users by their 'login'. Use \"@me\" to unassign yourself."`
RemoveLabel string `cli:"--remove-label Remove labels by 'name'"`
RemoveProject string `cli:"--remove-project Remove the issue from projects by 'name'"`
Title string `cli:"-t, --title Set the new title."`
CommonIssueArgs
}
// Optionally, we can specify a custom ErrorHandling option.
_, err := mcli.Parse(&args, mcli.WithErrorHandling(flag.ContinueOnError))
if err != nil && err != flag.ErrHelp {
fmt.Printf("mcli.Parse error: %v", err)
fmt.Println()
}
}
func dummyCmd() {
mcli.Parse(nil)
mcli.PrintHelp()
}