Your method of determining if a flag has been set won't work. The test you make flag.Lookup("name") == nil will only return true if no flag variable with that name exists, meaning you didn't create a flag with that name. The return value of the Lookup method is a Flag structure which represent the flags that have been assigned to the default command line parser.
The only way to change the output of the usage message is to change the value of the flag.Usage function variable so that it does something other than call flag.PrintDefaults (ie: write your own usage message).
To make a mandatory flag (or at least be able to tell if a flag was set), two techniques come to mind:
- Create a new Value type, so you can track if Set() was ever called.
- Use a different type of flag, such as a string or float64 flag, where it's easy to tell if the input is invalid (ie: when it's not a valid integer), but it's possible to pass a value that is an integer, and set the default to an invalid value
The latter involves little code, but has some problem cases (using strings would be more code but more accurate). The former is a lot more code, but give a lot more control over the specifics, and is more logically connected to what you are attempting to track.