rpelak has asked for the wisdom of the Perl Monks concerning the following question:
So I wanted to come here and ask... :)
I write scripts... in various languages... perl and tcl to name the major ones.
Those scripts usually have command line interfaces.
I often find myself wishing I could check if that value of an option post-parsing came from the user providing it on the command line, or was just the default.
Seems odd. But it's true.
here is one such general case.
I have an option, it has a default that "might work" for the user. The users of course can also give a value, and that should always be used. But I could also derive a value from the env that if it comes up with a value at all (doesn't always) would be better than the default, yet should still lose to a user given value.
So basically the order of preference is, user given, derived, default.
Most parsers will handle user given, and default, but don't provide a good way to know which was used for any specific option.
I can (and have on occasion) written my own command line parser, but such a simple thing as if an option was actually on the command line seems like it would be in the normal parsers, yet I don't see it, making me think it isn't normal to need it. And thus I might be off, or my need it just uncommon.
thoughts?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Command line options
by roboticus (Chancellor) on Nov 01, 2011 at 20:03 UTC | |
by rpelak (Sexton) on Nov 01, 2011 at 20:26 UTC | |
by graff (Chancellor) on Nov 02, 2011 at 07:52 UTC | |
by rpelak (Sexton) on Nov 02, 2011 at 17:12 UTC | |
Re: Command line options
by mrstlee (Beadle) on Nov 01, 2011 at 20:34 UTC | |
Re: Command line options
by choroba (Cardinal) on Nov 02, 2011 at 17:24 UTC | |
by rpelak (Sexton) on Nov 02, 2011 at 18:55 UTC | |
by graff (Chancellor) on Nov 03, 2011 at 02:52 UTC |