From 6f5666fd36a9a8eefcd457dc2c8a2b3c7bc1968b Mon Sep 17 00:00:00 2001 From: Michele Bertasi Date: Wed, 30 Dec 2020 13:47:32 +0100 Subject: [PATCH] Add public add / remove methods for subcommands. This allows consumer of the gmailctl/cmd package to customize the subcommands. --- cmd/gmailctl/cmd/root_cmd.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/gmailctl/cmd/root_cmd.go b/cmd/gmailctl/cmd/root_cmd.go index fbb3e4d3..83b7917c 100644 --- a/cmd/gmailctl/cmd/root_cmd.go +++ b/cmd/gmailctl/cmd/root_cmd.go @@ -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", @@ -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)