#81 --config=CONFIG rejected if no name on command line

v3.0
closed-fixed
Edward Loper
5
2006-04-02
2006-04-01
Pierre Rouleau
No

Note: tested with revision 1129.

The command line is rejected if the only command line
option is a --config=CONFIG and no other module is
listed on the command line even if there are modules
inside the configuration file.

This forces the user to specify at least one module at
the command line event if the intent is to be able to
list all the modules inside the configuration file.

cli.cli() calls cli.parse_arguments() before calling
cli.main() where the configfile is parsed. But
cli.parse_arguments() rejects the command line if there
is no names. This rejecttion is too soon if we want to
allow entering the names inside the config file.

There are other issues related to the config file and
the normal command line parsing.

- cli.parse_arguments() performs shell expansion of
names but this is not done for names taken from the
config file.
- The --text option allows only 1 name, as checked by
cli.parse_arguments() but that check is not performed
when the options are taken from the config file.

Suggestion
----------

Instead of calling parse_configfiles() from main(), why
not call it inside parse_arguments() right after
calling optparser.parse_args() ? This way, all option
processing would be done in one spot, and all
constraints on the options could be verified in one
spot as well.

svn diff cli.py
Index: cli.py
===================================================================
--- cli.py (revision 1129)
+++ cli.py (working copy)
@@ -209,6 +209,16 @@
# Parse the arguments.
options, names = optparser.parse_args()

+ # Process any config files.
+ if options.configfiles:
+ try:
+ parse_configfiles(options.configfiles,
options, names)
+ except KeyboardInterrupt,SystemExit: raise
+ except ValueError, e:
+ optparser.error('Error reading config
file: %s' % e)
+ except ConfigParser.ParsingError, e:
+ optparser.error('Error reading config
file: %s' % e)
+
# Check to make sure all options are valid.
if len(names) == 0:
optparser.error("No names specified.")
@@ -310,18 +320,6 @@
if options.parse and options.introspect:
options.parse = False

- # Process any config files.
- if options.configfiles:
- try:
- parse_configfiles(options.configfiles,
options, names)
- except KeyboardInterrupt,SystemExit: raise
- except ValueError, e:
- print 'Error reading config file: %s' % e
- return
- except ConfigParser.ParsingError, e:
- print 'Error reading config file: %s' % e
- return
-
# Set up the logger
if options.action == 'text':
logger = None # no logger for text output.

Discussion

  • Pierre Rouleau
    Pierre Rouleau
    2006-04-02

    svn diff of suggestion

     
    Attachments
  • Edward Loper
    Edward Loper
    2006-04-02

    • status: open --> closed-fixed
     
  • Edward Loper
    Edward Loper
    2006-04-02

    Logged In: YES
    user_id=195958

    Fixed in subversion revision 1133 (along with a copule
    other bugs in handling of config files).