Changeset 4283:8a72da8e56a9 in livinglogic.python.xist for src/ll/scripts/ucat.py

Show
Ignore:
Timestamp:
01/19/11 17:26:04 (9 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Enhance handling of flags on the command line.

Replace misc.flag() with a new action class misc.FlagAction?. This supports flag
options without a value (this toggles the option).

Display defaults for all options in scripts.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/scripts/ucat.py

    r4113 r4283  
    1313import sys, argparse, contextlib, errno 
    1414 
    15 from ll import url 
     15from ll import misc, url 
    1616 
    1717try: 
     
    5050    p = argparse.ArgumentParser(description="print URL content on the screen") 
    5151    p.add_argument("urls", metavar="url", help="URLs to be printed", nargs="+", type=url.URL) 
    52     p.add_argument("-v", "--verbose", dest="verbose", help="Be verbose?", action="store_true", default=False) 
    53     p.add_argument("-r", "--recursive", dest="recursive", help="Copy stuff recursively?", action="store_true", default=False) 
    54     p.add_argument("-x", "--ignoreerrors", dest="ignoreerrors", help="Ignore errors?", action="store_true", default=False) 
     52    p.add_argument("-v", "--verbose", dest="verbose", help="Be verbose? (default: %(default)s)", action=misc.FlagAction, default=False) 
     53    p.add_argument("-r", "--recursive", dest="recursive", help="Copy stuff recursively? (default: %(default)s)", action=misc.FlagAction, default=False) 
     54    p.add_argument("-x", "--ignoreerrors", dest="ignoreerrors", help="Ignore errors? (default: %(default)s)", action=misc.FlagAction, default=False) 
    5555 
    5656    args = p.parse_args(args)