ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

hidden arguments? #64

Open LeventErkok opened 4 years ago

LeventErkok commented 4 years ago

Is there a way to add an argument, but not make it show up in the help message? (Useful in implementing backdoor developer-only testing features.)

ndmitchell commented 4 years ago

Is https://hackage.haskell.org/package/cmdargs-0.10.20/docs/System-Console-CmdArgs-Implicit.html#v:ignore what you are after?

LeventErkok commented 4 years ago

Thanks Neil!

Unfortunately that's not quite what I want. I still want this to be a valid parameter to the program, just not displayed in the "help" output.

I've found this stack-overflow question that describes the issue https://stackoverflow.com/questions/33199324/hidden-arguments-with-cmdargs

But the accepted solution seems quite hackish and it dates back to 2015. So, I'm wondering if there's a better way to do the same.

ndmitchell commented 4 years ago

Unfortunately nothing better available I'm afraid. I can't think of a better way than that.

LeventErkok commented 4 years ago

Thanks! I'll close this ticket; but feel free to re-open it if you want to implement something! It's definitely a nice-to-have. Much appreciated.

ndmitchell commented 4 years ago

Let's leave open to add - it's pretty hacky as it stands now...

LeventErkok commented 4 years ago

In case this helps anyone else, I found a workaround that sort of works. You first do:

allNames :: [String]
allNames = concatMap flagNames $ modeFlags defaultOptions

where defaultOptions is the record you construct for arguments. This grabs all the flag names. Then, do a preprocessing step and check all "flag-like" arguments to be in this list before calling cmdArgs itself. If you find anything outside, you can do a more detailed analysis as needed.

Rather hackish, but it does do the trick for my use case. I'd like to hear if anyone has a better idea that doesn't require mocking with cmdArgs itself.