So I have run into a situation several times, that the standard modules don't seem to support. And that makes me think maybe I am doing it wrong...
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?


In reply to Command line options by rpelak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.