|
1 |
| -# go-gh beta |
| 1 | +# Go library for the GitHub CLI |
2 | 2 |
|
3 |
| -**This project is in beta!** Feedback is welcome. |
| 3 | +`go-gh` is a collection of Go modules to make authoring [GitHub CLI extensions][extensions] easier. |
4 | 4 |
|
5 |
| -A Go module for CLI Go applications and [gh extensions][extensions] that want a convenient way to interact with [gh][], and the GitHub API using [gh][] environment configuration. |
| 5 | +Modules from this library will obey GitHub CLI conventions by default: |
6 | 6 |
|
7 |
| -`go-gh` supports multiple ways of getting access to `gh` functionality: |
| 7 | +- [`CurrentRepository()`](https://pkg.go.dev/github.com/cli/go-gh#CurrentRepository) respects the value of the `GH_REPO` environment variable and reads from git remote configuration as fallback. |
8 | 8 |
|
9 |
| -* Helpers that automatically read a `gh` config to authenticate themselves |
10 |
| -* `gh.Exec` shells out to a `gh` install on your machine |
| 9 | +- GitHub API requests will be authenticated using the same mechanism as `gh`, i.e. using the values of `GH_TOKEN` and `GH_HOST` environment variables and falling back to the user's stored OAuth token. |
11 | 10 |
|
12 |
| -If you'd like to use `go-gh` on systems without `gh` installed and configured, you can provide custom authentication details to the `go-gh` API helpers. |
| 11 | +- [Terminal capabilities](https://pkg.go.dev/github.com/cli/go-gh/pkg/term) are determined by taking environment variables `GH_FORCE_TTY`, `NO_COLOR`, `CLICOLOR`, etc. into account. |
13 | 12 |
|
| 13 | +- Generating [table](https://pkg.go.dev/github.com/cli/go-gh/pkg/tableprinter) or [Go template](https://pkg.go.dev/github.com/cli/go-gh/pkg/template) output uses the same engine as gh. |
14 | 14 |
|
15 |
| -## Installation |
16 |
| -```bash |
17 |
| -go get github.com/cli/go-gh |
18 |
| -``` |
| 15 | +- The [`browser`](https://pkg.go.dev/github.com/cli/go-gh/pkg/browser) module activates the user's preferred web browser. |
19 | 16 |
|
20 | 17 | ## Usage
|
| 18 | + |
| 19 | +See the full `go-gh` [reference documentation](https://pkg.go.dev/github.com/cli/go-gh) for more information |
| 20 | + |
21 | 21 | ```golang
|
22 | 22 | package main
|
| 23 | + |
23 | 24 | import (
|
24 | 25 | "fmt"
|
| 26 | + "log" |
25 | 27 | "github.com/cli/go-gh"
|
26 | 28 | )
|
27 | 29 |
|
28 | 30 | func main() {
|
29 | 31 | // These examples assume `gh` is installed and has been authenticated
|
30 | 32 |
|
31 |
| - // Execute `gh issue list -R cli/cli`, and print the output. |
32 |
| - args := []string{"issue", "list", "-R", "cli/cli"} |
33 |
| - stdOut, _, err := gh.Exec(args...) |
| 33 | + // Shell out to a gh command and read its output |
| 34 | + issueList, _, err := gh.Exec("issue", "list", "--repo", "cli/cli", "--limit", "5") |
34 | 35 | if err != nil {
|
35 |
| - fmt.Println(err) |
36 |
| - return |
| 36 | + log.Fatal(err) |
37 | 37 | }
|
38 |
| - fmt.Println(stdOut.String()) |
| 38 | + fmt.Println(issueList.String()) |
39 | 39 |
|
40 | 40 | // Use an API helper to grab repository tags
|
41 | 41 | client, err := gh.RESTClient(nil)
|
42 | 42 | if err != nil {
|
43 |
| - fmt.Println(err) |
44 |
| - return |
| 43 | + log.Fatal(err) |
45 | 44 | }
|
46 |
| - response := []struct{ Name string }{} |
| 45 | + response := []struct{ |
| 46 | + Name string |
| 47 | + }{} |
47 | 48 | err = client.Get("repos/cli/cli/tags", &response)
|
48 | 49 | if err != nil {
|
49 |
| - fmt.Println(err) |
50 |
| - return |
| 50 | + log.Fatal(err) |
51 | 51 | }
|
52 | 52 | fmt.Println(response)
|
53 | 53 | }
|
54 | 54 | ```
|
55 | 55 |
|
56 |
| -See [examples][examples] for more use cases. |
57 |
| - |
58 |
| -## Reference Documentation |
59 |
| - |
60 |
| -Full reference docs can be found on [pkg.go.dev](https://pkg.go.dev/github.com/cli/go-gh). |
| 56 | +See [examples][] for more demonstrations of usage. |
61 | 57 |
|
62 | 58 | ## Contributing
|
63 | 59 |
|
64 |
| -If anything feels off, or if you feel that some functionality is missing, please check out the [contributing page][contributing]. There you will find instructions for sharing your feedback, and submitting pull requests to the project. |
| 60 | +If anything feels off, or if you feel that some functionality is missing, please check out our [contributing docs][contributing]. There you will find instructions for sharing your feedback and for submitting pull requests to the project. Thank you! |
| 61 | + |
65 | 62 |
|
66 |
| -[extensions]: https://github.com/topics/gh-extension |
67 |
| -[gh]: https://github.com/cli/cli |
| 63 | +[extensions]: https://docs.github.com/en/github-cli/github-cli/creating-github-cli-extensions |
68 | 64 | [examples]: ./example_gh_test.go
|
69 | 65 | [contributing]: ./.github/CONTRIBUTING.md
|
0 commit comments