From 0e7e122c81a5a00d7ba2e799599c7a04609c77b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Vallette=20d=27Osia?= Date: Fri, 13 Mar 2015 12:40:00 +0900 Subject: [PATCH] Add README section for RemoveCommand --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 64c29ef1..f340f6f1 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,15 @@ A flag can also be assigned locally which will only apply to that specific comma HugoCmd.Flags().StringVarP(&Source, "source", "s", "", "Source directory to read from") +### Remove a command from its parent + +Removing a command is not a common action is simple program but it allows 3rd parties to customize an existing command tree. + +In this exemple, we remove the existing `VersionCmd` command of an existing root command, and we replace it by our own version. + + mainlib.RootCmd.RemoveCommand(mainlib.VersionCmd) + mainlib.RootCmd.AddCommand(versionCmd) + ### Once all commands and flags are defined, Execute the commands Execute should be run on the root for clarity, though it can be called on any command.