Django

Code

Changeset 8228

Show
Ignore:
Timestamp:
08/08/08 08:40:11 (4 months ago)
Author:
russellm
Message:

Fixed #8120, #7997 -- Cleaned up the help messages displayed by django-admin so that the lax options aren't repeated, and the lax options are displayed when no subcommand is provided. Thanks to Scott Moonen <smoonen@andstuff.org> and trevor for the respective reports.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/__init__.py

    r8227 r8228  
    150150        pass 
    151151     
     152    def print_help(self): 
     153        """Output nothing. 
     154         
     155        The lax options are included in the normal option parser, so under 
     156        normal usage, we don't need to print the lax options. 
     157        """ 
     158        pass 
     159     
     160    def print_lax_help(self): 
     161        """Output the basic options available to every command. 
     162         
     163        This just redirects to the default print_help() behaviour. 
     164        """ 
     165        OptionParser.print_help(self) 
     166         
    152167    def _process_args(self, largs, rargs, values): 
    153168        """ 
     
    196211        Returns the script's main help text, as a string. 
    197212        """ 
    198         usage = ['%s <subcommand> [options] [args]' % self.prog_name] 
    199         usage.append('Django command line tool, version %s' % django.get_version()) 
    200         usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name) 
     213        usage = ['',"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,''] 
    201214        usage.append('Available subcommands:') 
    202215        commands = get_commands(self.user_commands, self.project_directory).keys() 
     
    233246        # These options could affect the commands that are available, so they 
    234247        # must be processed early. 
    235         parser = LaxOptionParser(version=get_version(), option_list=BaseCommand.option_list) 
     248        parser = LaxOptionParser(usage="%prog subcommand [options] [args]", 
     249                                 version=get_version(),  
     250                                 option_list=BaseCommand.option_list) 
    236251        try: 
    237252            options, args = parser.parse_args(self.argv) 
     
    250265                self.fetch_command(args[2]).print_help(self.prog_name, args[2]) 
    251266            else: 
     267                parser.print_lax_help() 
    252268                sys.stderr.write(self.main_help_text() + '\n') 
    253269                sys.exit(1) 
     
    258274            pass 
    259275        elif self.argv[1:] == ['--help']: 
     276            parser.print_lax_help() 
    260277            sys.stderr.write(self.main_help_text() + '\n') 
    261278        else: 
  • django/trunk/tests/regressiontests/admin_scripts/tests.py

    r8227 r8228  
    895895        out, err = self.run_manage(args) 
    896896        if sys.version_info < (2, 5): 
    897             self.assertOutput(out, "usage: manage.py [options]") 
     897            self.assertOutput(out, "usage: manage.py subcommand [options] [args]") 
    898898        else: 
    899             self.assertOutput(out, "Usage: manage.py [options]") 
     899            self.assertOutput(out, "Usage: manage.py subcommand [options] [args]") 
    900900        self.assertOutput(err, "Type 'manage.py help <subcommand>' for help on a specific subcommand.") 
    901901