Subject: Getopt
From: "Johan Sundström (Achtung Liebe!) @ Pike (-) importmöte för mailinglistan" <6341@lyskom.lysator.liu.se>
Date: Tue, 13 Mar 2007 AD 06:45:00 -0400
Getopt unfortunately wants you to use a much more convoluted piece of
boilerplate code, like this (with HAS_ARG and MAY_HAVE_ARG options):
foreach( Getopt.find_all_options( argv, ({
({ "help", Getopt.NO_ARG, "-h,--help"/"," }),
({ "version", Getopt.NO_ARG, "-V,--version"/"," }),
({ "quiet", Getopt.NO_ARG, "-q,--quiet"/"," }),
({ "verbose", Getopt.NO_ARG, "-v,--verbose"/"," }),
({ "recurse", Getopt.NO_ARG, "-r,--recursive"/"," }),
({ "backup", Getopt.NO_ARG, "-b,--backup"/"," }) })),
array opt )
switch(opt[0]) {
case "help":
write( usage );
exit( 0 );
case "version":
write( version + "\n" );
exit( 0 );
case "quiet":
verbosity = 0;
break;
case "verbose":
verbosity++;
break;
case "recurse":
recursive = 1;
break;
case "backup":
overwrite = 0;
break;
}
argv = Getopt.get_args(argv);
You now have non-flag args in argv[1..]. A less contrived system for
consuming command line arguments would be a great addition to Pike. I
haven't seen any better design propositions so far, though.
Return to results