in reply to Re^4: how to deal with 20 commands
in thread how to deal with 20 commands

Are there getopt libraries for other languages that take input from places other than the command line? I realize that taking values from the environment or from an rc file might be useful, but I would argue against putting that in the getopt library but rather have applications handle it on a case by case basis.

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

Replies are listed 'Best First'.
Re^6: how to deal with 20 commands
by gaal (Parson) on May 23, 2005 at 18:05 UTC
    Sure, any c getopt library accepts any command line source you give it, which may or may not be the one your program got. Likewise for Java.

    I would have expected a perlish lib to accept an optional arrayref, and fall back on @ARGV if not supplied. (By which I mean, I understand perfectly well how to get around this when I need to, but I don't want to need to.)

      Sure, any c getopt library accepts any command line source you give it, which may or may not be the one your program got. Likewise for Java.
      I'm not sure I follow what you're saying. For my own learning experience, would you mind contriving an example?

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        Sure! Take for example the code in getopt(3) (I'm not posting it here in full because it's longish). Note how you have, essentially,

        #include <stdio.h> #include <getopt.h> int main (argc, argv) int argc; char **argv; { /* ... */ getopt_long (argc, argv, "abc:d:012", /* short spec */ long_options, &option_index); /* ... */ }

        The "argc" and "argv" you're passing the library function getopt_long just happen to be the ones given to you on the command line. But if you'd have constructed any other, er, argument vector, you could have passed that instead.

        The same thing happens in Java, when your entry point accepts a String args[], and passes that (or a different String[]) to the options parsing library.