I have a CLI with a flag name that I would like to rename, but I would also like to make it so this change is backwards compatible and using the old flag name still works, such as below:
# New flag name
root subcommand --no-color
# Old flag name still works
root subcommand --nocolour
My original thought with this was to alias the flag name to the new name as described here. This approach does change the flag name to the new name, but it does not make it so you can use the old name of a flag as well.
I have put in place an approach to solve this by defining another flag with the same properties but a different name and also moving the shorthands to the new flag, such as below:
// Old flag name
cmd.PersistentFlags().BoolP(
"nocolour", "", false,
"disable colouring (default: false)")
// New flag name
cmd.PersistentFlags().BoolP(
"no-color", "C", false,
"disable coloring (default: false)")
And then I mark the old name flag as hidden:
cmd.PersistentFlags().MarkHidden("nocolour")
I am wondering if there is a way to accomplish what I did above without having to define and support two flags?