Skip to content

Commit

Permalink
ensure flags are properly passed to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mdb committed Nov 14, 2022
1 parent fafb25e commit 32606ba
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 51 deletions.
17 changes: 1 addition & 16 deletions cmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,7 @@ package cmd

import "github.com/mdb/gh-dispatch/dispatch"

var (
repositoryEventType string
repositoryClientPayload string
repositoryWorkflow string
)

// repositoryCmd represents the repository subcommand
var repositoryCmd = dispatch.NewCmdRepository()

func init() {
repositoryCmd.Flags().StringVarP(&repositoryEventType, "event-type", "e", "", "The repository dispatch event type.")
repositoryCmd.MarkFlagRequired("event-type")
repositoryCmd.Flags().StringVarP(&repositoryClientPayload, "client-payload", "p", "", "The repository dispatch event client payload JSON string.")
repositoryCmd.MarkFlagRequired("client-payload")
repositoryCmd.Flags().StringVarP(&repositoryWorkflow, "workflow", "w", "", "The resulting GitHub Actions workflow name.")
repositoryCmd.MarkFlagRequired("workflow")

repositoryCmd := dispatch.NewCmdRepository()
rootCmd.AddCommand(repositoryCmd)
}
22 changes: 1 addition & 21 deletions cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,7 @@ import (
"github.com/mdb/gh-dispatch/dispatch"
)

var (
workflowInputs string
workflowName string
workflowRef string
)

// workflowCmd represents the workflow subcommand
var workflowCmd = dispatch.NewCmdWorkflow()

func init() {
// TODO: how does the 'gh run' command represent inputs?
// Is it worth better emulating its interface?
workflowCmd.Flags().StringVarP(&workflowInputs, "inputs", "i", "", "The workflow dispatch inputs JSON string.")
workflowCmd.MarkFlagRequired("inputs")
// TODO: how does the 'gh run' command represent workflow?
// Is it worth better emulating its interface?
workflowCmd.Flags().StringVarP(&workflowName, "workflow", "w", "", "The resulting GitHub Actions workflow name.")
workflowCmd.MarkFlagRequired("workflow")
// TODO: how does the 'gh run' command represent ref?
// Is it worth better emulating its interface?
workflowCmd.Flags().StringVarP(&workflowRef, "ref", "f", "main", "The git reference for the workflow. Can be a branch or tag name.")

workflowCmd := dispatch.NewCmdWorkflow()
rootCmd.AddCommand(workflowCmd)
}
23 changes: 16 additions & 7 deletions dispatch/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type repositoryDispatchOptions struct {
dispatchOptions
}

var (
repositoryEventType string
repositoryClientPayload string
repositoryWorkflow string
)

func NewCmdRepository() *cobra.Command {
return &cobra.Command{
var (
repositoryEventType string
repositoryClientPayload string
repositoryWorkflow string
)

cmd := &cobra.Command{
Use: heredoc.Doc(`
repository \
--repo [owner/repo] \
Expand Down Expand Up @@ -81,6 +81,15 @@ func NewCmdRepository() *cobra.Command {
})
},
}

cmd.Flags().StringVarP(&repositoryEventType, "event-type", "e", "", "The repository dispatch event type.")
cmd.MarkFlagRequired("event-type")
cmd.Flags().StringVarP(&repositoryClientPayload, "client-payload", "p", "", "The repository dispatch event client payload JSON string.")
cmd.MarkFlagRequired("client-payload")
cmd.Flags().StringVarP(&repositoryWorkflow, "workflow", "w", "", "The resulting GitHub Actions workflow name.")
cmd.MarkFlagRequired("workflow")

return cmd
}

func repositoryDispatchRun(opts *repositoryDispatchOptions) error {
Expand Down
28 changes: 21 additions & 7 deletions dispatch/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type workflowDispatchOptions struct {
dispatchOptions
}

var (
workflowInputs string
workflowName string
workflowRef string
)

func NewCmdWorkflow() *cobra.Command {
return &cobra.Command{
var (
workflowInputs string
workflowName string
workflowRef string
)

cmd := &cobra.Command{
Use: heredoc.Doc(`
workflow \
--repo [owner/repo] \
Expand Down Expand Up @@ -86,6 +86,20 @@ func NewCmdWorkflow() *cobra.Command {
})
},
}

// TODO: how does the 'gh run' command represent inputs?
// Is it worth better emulating its interface?
cmd.Flags().StringVarP(&workflowInputs, "inputs", "i", "", "The workflow dispatch inputs JSON string.")
cmd.MarkFlagRequired("inputs")
// TODO: how does the 'gh run' command represent workflow?
// Is it worth better emulating its interface?
cmd.Flags().StringVarP(&workflowName, "workflow", "w", "", "The resulting GitHub Actions workflow name.")
cmd.MarkFlagRequired("workflow")
// TODO: how does the 'gh run' command represent ref?
// Is it worth better emulating its interface?
cmd.Flags().StringVarP(&workflowRef, "ref", "f", "main", "The git reference for the workflow. Can be a branch or tag name.")

return cmd
}

func workflowDispatchRun(opts *workflowDispatchOptions) error {
Expand Down

0 comments on commit 32606ba

Please sign in to comment.