Let's say that 'bheerdb' is an interface to an external data store. It has a bunch of options that are typically used in a few standard patterns. I'd like to save a bunch of typing by aliasing 'bheerdb' to various names and using $0 to set appropriate defaults for getopt. For example, 'create-tap duff' should set defaults '--action create' and '--type domestic', while 'update-tap --class premium duff' should only set a default of '--action update'.

The aliases I'm using are all 'verb-objtype' and some defaults depend on the verb, some on objtype, and a few actually depend on both. I guess I need some sort of decision table, but Re^3: Burned by precedence rules is the only Perlmonks discussion that even mentions the subject. I don't want to write a bunch of wrapper scripts, because I occasionally need to change the default values, and I don't want to have to change a bunch of scripts. So if anyone has any ideas, I'd appreciate hearing them.

BTW, as I was writing my question, I realized that what I need is similar to something usually found in text adventure games, where there's a generic response to some commands, which can be overridden by both the object and the room you're in. I guess I'll look into that as well.


In reply to Set getopt defaults based on $0 by samwyse

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.