Changeset 283


Ignore:
Timestamp:
24-06-07 21:52:23 (6 years ago)
Author:
thomas
Message:
  • command.py: Add help command. Fixes #240.
Location:
trunk/moap/extern/command
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/moap/extern/command/command.py

    r268 r283  
    183183            return ret 
    184184 
     185        # handle pleas for help 
     186        if args and args[0] == 'help': 
     187            self.debug('Asked for help, args %r' % args) 
     188             
     189            # give help on current command if only 'help' is passed 
     190            if len(args) == 1: 
     191                self.outputHelp() 
     192                return 0 
     193 
     194            # complain if we were asked for help on a subcommand, but we don't 
     195            # have any 
     196            if not self.subCommands: 
     197                self.stderr.write('No subcommands defined.') 
     198                self.parser.print_usage(file=self.stderr) 
     199                self.stderr.write( 
     200                    "Use --help to get more information about this command.\n") 
     201                return 1 
     202 
     203            # rewrite the args the other way around; 
     204            # help doap becomes doap help so it gets deferred to the doap 
     205            # command 
     206            args = [args[1], args[0]] 
     207 
    185208        # if we don't have subcommands, defer to our do() method 
    186209        if not self.subCommands: 
     
    206229        return 1 
    207230 
     231    def outputHelp(self): 
     232        """ 
     233        Output help information. 
     234        """ 
     235        self.parser.print_help(file=self.stderr) 
     236 
    208237    def outputUsage(self): 
    209238        """ 
Note: See TracChangeset for help on using the changeset viewer.