Is there anyway to ignore case (case insensitive) of Go flags?
I'd like to make my program forgiving and user friendly as possible.
dbType := flags.String( "dbType", "", "The `dbType` to deploy. )
I'd like this flag's value to be initialized if the user enters any of the following:
-dbtype
-dbType
-DBTYPE
Unfortunately, for this project I am limited to using the flag
library.
Go flags are case-sensitive, so you can't do what you want by default. But you can set the values you allow the user enter, and let them point to the same variable, ie:
const dbTypeUsage = "The `dbType` to deploy."
var dbType string
flag.StringVar(&dbType, "dbType", "", dbTypeUsage)
flag.StringVar(&dbType, "DBTYPE", "", dbTypeUsage)
flag.StringVar(&dbType, "DBType", "", dbTypeUsage)
flag.StringVar(&dbType, "dbtype", "", dbTypeUsage)
...