Skip to content

Commit

Permalink
Add public add / remove methods for subcommands.
Browse files Browse the repository at this point in the history
This allows consumer of the gmailctl/cmd package to customize the
subcommands.
  • Loading branch information
mbrt committed Dec 30, 2020
1 parent 7f2f136 commit 6f5666f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/gmailctl/cmd/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
tokenPath string
)

// rootCmd represents the base command when called without any subcommands
// rootCmd is the command run when executing without subcommands.
var rootCmd = &cobra.Command{
Use: "gmailctl",
Short: "Declarative configuration for Gmail",
Expand All @@ -33,6 +33,22 @@ func Execute() {
}
}

// RemoveCommand removes a subcommand.
func RemoveCommand(name string) bool {
for _, c := range rootCmd.Commands() {
if c.Name() == name {
rootCmd.RemoveCommand(c)
return true
}
}
return false
}

// AddCommand adds a subcommand.
func AddCommand(cmd *cobra.Command) {
rootCmd.AddCommand(cmd)
}

func init() {
cobra.OnInitialize(initConfig)

Expand Down

0 comments on commit 6f5666f

Please sign in to comment.