Skip to content

Commit d1640c0

Browse files
authored
Merge pull request #14 from mdb/update-command-docs
2 parents 34a44d7 + 69860c4 commit d1640c0

File tree

7 files changed

+85
-17
lines changed

7 files changed

+85
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SOURCE=./...
22
GOFMT_FILES?=$$(find . -type f -name '*.go')
3-
VERSION?=0.0.1
3+
VERSION?=0.0.2
44

55
default: build
66

cmd/repository.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88

9+
"github.com/MakeNowJust/heredoc"
910
"github.com/cli/cli/v2/pkg/cmd/workflow/shared"
1011
"github.com/cli/cli/v2/pkg/iostreams"
1112
"github.com/cli/go-gh"
@@ -33,10 +34,30 @@ var (
3334

3435
// repositoryCmd represents the repository subcommand
3536
var repositoryCmd = &cobra.Command{
36-
Use: "repository",
37-
Short: `The 'repository' subcommand triggers repository dispatch events`,
38-
Long: `The 'repository' subcommand triggers repository dispatch events`,
39-
Example: `TODO`,
37+
Use: heredoc.Doc(`
38+
repository \
39+
--repo [owner/repo] \
40+
--event-type [event-type] \
41+
--client-payload [json-string] \
42+
--workflow [workflow-name]
43+
`),
44+
Short: "Send a repository dispatch event and watch the resulting GitHub Actions run",
45+
Long: heredoc.Doc(`
46+
This command sends a repository dispatch event and attempts to find and watch the
47+
resulting GitHub Actions run whose name is specified as '--workflow'.
48+
49+
Note that the command assumes the specified workflow supports a repository_dispatch
50+
'on' trigger. Also note that the command is vulnerable to race conditions and may
51+
watch an unrelated GitHub Actions workflow run in the event that multiple runs of
52+
the specified workflow are running concurrently.
53+
`),
54+
Example: heredoc.Doc(`
55+
gh dispatch repository \
56+
--repo mdb/gh-dispatch \
57+
--event-type 'hello' \
58+
--client-payload '{"name": "Mike"}' \
59+
--workflow Hello
60+
`),
4061
RunE: func(cmd *cobra.Command, args []string) error {
4162
repo, _ := cmd.Flags().GetString("repo")
4263

cmd/root.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package cmd
33
import (
44
"os"
55

6+
"github.com/MakeNowJust/heredoc"
67
"github.com/spf13/cobra"
78
)
89

910
// rootCmd is the root command.
1011
var rootCmd = &cobra.Command{
11-
Use: "gh dispatch",
12-
Short: "gh dispatch: Trigger a GitHub dispatch event and watch the resulting GitHub Actions run",
13-
Long: "gh dispatch: Trigger a GitHub dispatch event and watch the resulting GitHub Actions run",
14-
Example: "TODO",
12+
Use: "gh dispatch",
13+
Short: "Send a GitHub dispatch event and watch the resulting GitHub Actions run",
14+
Long: heredoc.Doc(`
15+
Send a workflow_dispatch or repository_dispatch event and watch the resulting
16+
GitHub Actions run.
17+
`),
1518
SilenceUsage: true,
1619
}
1720

cmd/workflow.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88

9+
"github.com/MakeNowJust/heredoc"
910
"github.com/cli/cli/v2/pkg/cmd/workflow/shared"
1011
"github.com/cli/cli/v2/pkg/iostreams"
1112
"github.com/cli/go-gh"
@@ -32,14 +33,36 @@ var (
3233
)
3334

3435
// workflowCmd represents the workflow subcommand
35-
// TODO: it appears the resulting run rendering may
36-
// sometimes fail to denote each job as passing or failing,
37-
// perhaps due to a race condition somewhere?
3836
var workflowCmd = &cobra.Command{
39-
Use: "workflow",
40-
Short: `The 'workflow' subcommand triggers workflow dispatch events`,
41-
Long: `The 'workflow' subcommand triggers workflow dispatch events`,
42-
Example: `TODO`,
37+
Use: heredoc.Doc(`
38+
workflow \
39+
--repo [owner/repo] \
40+
--inputs [json-string] \
41+
--workflow [workflow-file-name.yaml]
42+
`),
43+
Short: "Send a workflow dispatch event and watch the resulting GitHub Actions run",
44+
Long: heredoc.Doc(`
45+
This command sends a workflow dispatch event and attempts to find and watch the
46+
resulting GitHub Actions run whose file name or ID is specified as '--workflow'.
47+
48+
Note that the command assumes the specified workflow supports a workflow_dispatch
49+
'on' trigger. Also note that the command is vulnerable to race conditions and may
50+
watch an unrelated GitHub Actions workflow run in the event that multiple runs of
51+
the specified workflow are running concurrently.
52+
`),
53+
Example: heredoc.Doc(`
54+
gh dispatch workflow \
55+
--repo mdb/gh-dispatch \
56+
--inputs '{"name": "Mike"}' \
57+
--workflow workflow_dispatch.yaml
58+
59+
# Specify a workflow ref other than 'main'
60+
gh dispatch workflow \
61+
--repo mdb/gh-dispatch \
62+
--inputs '{"name": "Mike"}' \
63+
--workflow workflow_dispatch.yaml \
64+
--ref my-feature-branch
65+
`),
4366
RunE: func(cmd *cobra.Command, args []string) error {
4467
repo, _ := cmd.Flags().GetString("repo")
4568

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/mdb/gh-dispatch
33
go 1.19
44

55
require (
6+
github.com/MakeNowJust/heredoc v1.0.0
67
github.com/cli/cli/v2 v2.18.1
78
github.com/cli/go-gh v0.1.2
89
github.com/spf13/cobra v1.6.0

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
github.com/AlecAivazis/survey/v2 v2.3.6 h1:NvTuVHISgTHEHeBFqt6BHOe4Ny/NwGZr7w+F8S9ziyw=
22
github.com/AlecAivazis/survey/v2 v2.3.6/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI=
33
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
4+
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
45
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
56
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
67
github.com/briandowns/spinner v1.18.1 h1:yhQmQtM1zsqFsouh09Bk/jCjd50pC3EOGsh28gLVvwY=

main_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212
"time"
1313

14+
"github.com/MakeNowJust/heredoc"
1415
"github.com/stretchr/testify/assert"
1516
)
1617

@@ -26,7 +27,25 @@ func TestMain(m *testing.M) {
2627
}
2728

2829
func TestRootAcceptance(t *testing.T) {
29-
basicOut := "gh dispatch: Trigger a GitHub dispatch event and watch the resulting GitHub Actions run\n\nUsage:\n gh [command]\n\nExamples:\nTODO\n\nAvailable Commands:\n completion Generate the autocompletion script for the specified shell\n help Help about any command\n repository The 'repository' subcommand triggers repository dispatch events\n workflow The 'workflow' subcommand triggers workflow dispatch events\n\nFlags:\n -h, --help help for gh\n -R, --repo string The targeted repository's full name (in 'owner/repo' format)\n -v, --version version for gh\n\nUse \"gh [command] --help\" for more information about a command.\n"
30+
basicOut := heredoc.Doc(`Send a workflow_dispatch or repository_dispatch event and watch the resulting
31+
GitHub Actions run.
32+
33+
Usage:
34+
gh [command]
35+
36+
Available Commands:
37+
completion Generate the autocompletion script for the specified shell
38+
help Help about any command
39+
repository Send a repository dispatch event and watch the resulting GitHub Actions run
40+
workflow Send a workflow dispatch event and watch the resulting GitHub Actions run
41+
42+
Flags:
43+
-h, --help help for gh
44+
-R, --repo string The targeted repository's full name (in 'owner/repo' format)
45+
-v, --version version for gh
46+
47+
Use "gh [command] --help" for more information about a command.
48+
`)
3049
tests := []struct {
3150
args []string
3251
wantOut string

0 commit comments

Comments
 (0)