def run(self): """Overload Application.run to handle bash completion calls. """ log.debug("{}.run".format(self.__class__.__name__)) parser = self.argparser_factory(add_help=False, argv=self.argv, stdout=self.stdout, stderr=self.stderr) for (args, kwargs) in self.__arguments: parser.add_argument(*args, **kwargs) args, rest = parser.parse_known_args(self.argv[1:]) if args.bash_eval: print ('complete -C "{} --bash-complete" {}'.format(self.argv[0], self.argv[0])) sys.exit(0) elif args.bash_complete: log.debug("self.argv: {}".format(self.argv)) first = self.argv[2] current = self.argv[3] previous = self.argv[4] line = os.environ["COMP_LINE"] index = os.environ["COMP_POINT"] words = line.split() # exclude bash completion related actions from completion actions = dict( [(name, action) for name, action in self.actions.items() if name not in ("bash_complete", "bash_eval")] ) completer = CommandCompleter(actions) candidates = completer.complete(first, current, previous, words, index) log.debug("CompletionMixin candidates: %s", candidates) print "\n".join(candidates) sys.exit(0) else: Application.run(self)
def setup(self): Application.setup(self) CommandLineMixin.setup(self) LoggingMixin.setup(self)
def pre_run(self): Application.pre_run(self) CommandLineMixin.pre_run(self) LoggingMixin.pre_run(self)
def __init__(self, main=None, **kwargs): CommandLineMixin.__init__(self, **kwargs) LoggingMixin.__init__(self, **kwargs) Application.__init__(self, main, **kwargs)
def setup(self): Application.setup(self) CommandLineMixin.setup(self) LoggingMixin.setup(self) DaemonizingMixin.setup(self)
def __init__(self, main=None, **kwargs): DaemonizingMixin.__init__(self, **kwargs) LoggingMixin.__init__(self, **kwargs) CommandLineMixin.__init__(self, **kwargs) Application.__init__(self, main, **kwargs)
def pre_run(self): # Let Command run the CommandLineMixin.pre_run() Application.pre_run(self) LoggingMixin.pre_run(self)
def pre_run(self): # SubCommands need to set up their own logging. Application.pre_run(self) CommandLineMixin.pre_run(self)
from cli.app import Application if __name__ == '__main__': Application.clear() app = Application() try: app.cmdloop() except KeyboardInterrupt: del app Application.clear()