diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 752be5b..3e15a0c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,6 +10,7 @@ builds: - linux - windows - netbsd + main: ./cmd/main.go archives: - name_template: "{{ .Os }}-{{ .Arch }}" format: binary diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..31c31ed --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "os" + + "github.com/MakeNowJust/heredoc" + "github.com/mdb/gh-dispatch/dispatch" + "github.com/spf13/cobra" +) + +// version's value is passed in at build time. +var version string + +func main() { + rootCmd := &cobra.Command{ + Use: "gh dispatch", + Short: "Send a GitHub dispatch event and watch the resulting GitHub Actions run", + Long: heredoc.Doc(` + Send a workflow_dispatch or repository_dispatch event and watch the resulting + GitHub Actions run. + `), + SilenceUsage: true, + Version: version, + } + + // TODO: how to make this required? + rootCmd.PersistentFlags().StringP("repo", "R", "", "The targeted repository's full name (in 'owner/repo' format)") + + repositoryCmd := dispatch.NewCmdRepository() + rootCmd.AddCommand(repositoryCmd) + + workflowCmd := dispatch.NewCmdWorkflow() + rootCmd.AddCommand(workflowCmd) + + if err := rootCmd.Execute(); err != nil { + os.Exit(1) + } +} diff --git a/main_test.go b/cmd/main_test.go similarity index 100% rename from main_test.go rename to cmd/main_test.go diff --git a/cmd/repository.go b/cmd/repository.go deleted file mode 100644 index 031856b..0000000 --- a/cmd/repository.go +++ /dev/null @@ -1,8 +0,0 @@ -package cmd - -import "github.com/mdb/gh-dispatch/dispatch" - -func init() { - repositoryCmd := dispatch.NewCmdRepository() - rootCmd.AddCommand(repositoryCmd) -} diff --git a/cmd/root.go b/cmd/root.go deleted file mode 100644 index 056ed4c..0000000 --- a/cmd/root.go +++ /dev/null @@ -1,32 +0,0 @@ -package cmd - -import ( - "os" - - "github.com/MakeNowJust/heredoc" - "github.com/spf13/cobra" -) - -// rootCmd is the root command. -var rootCmd = &cobra.Command{ - Use: "gh dispatch", - Short: "Send a GitHub dispatch event and watch the resulting GitHub Actions run", - Long: heredoc.Doc(` - Send a workflow_dispatch or repository_dispatch event and watch the resulting - GitHub Actions run. - `), - SilenceUsage: true, -} - -func init() { - // TODO: how to make this required? - rootCmd.PersistentFlags().StringP("repo", "R", "", "The targeted repository's full name (in 'owner/repo' format)") -} - -// Execute executes the root command. -func Execute(version string) { - rootCmd.Version = version - if err := rootCmd.Execute(); err != nil { - os.Exit(1) - } -} diff --git a/cmd/workflow.go b/cmd/workflow.go deleted file mode 100644 index 7c5f176..0000000 --- a/cmd/workflow.go +++ /dev/null @@ -1,10 +0,0 @@ -package cmd - -import ( - "github.com/mdb/gh-dispatch/dispatch" -) - -func init() { - workflowCmd := dispatch.NewCmdWorkflow() - rootCmd.AddCommand(workflowCmd) -} diff --git a/main.go b/main.go deleted file mode 100644 index 7fb63d5..0000000 --- a/main.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -import "github.com/mdb/gh-dispatch/cmd" - -// version's value is passed in at build time. -var version string - -func main() { - cmd.Execute(version) -}