Skip to content
Snippets Groups Projects
Select Git revision
  • f842347fd1130056a6ba786ea339d51bc3b547aa
  • master default protected
  • debian/exp
  • pristine-tar protected
  • upstream protected
  • debian/1%10.0.0+r36-10
  • debian/1%10.0.0+r36-9
  • debian/1%10.0.0+r36-8
  • debian/1%10.0.0+r36-7
  • debian/1%10.0.0+r36-7_exp2
  • debian/1%10.0.0+r36-7_exp1
  • debian/1%10.0.0+r36-6
  • debian/1%10.0.0+r36-5
  • debian/1%10.0.0+r36-4
  • debian/1%10.0.0+r36-3
  • debian/1%10.0.0+r36-3_stage1.2
  • debian/1%10.0.0+r36-3_stage1.1
  • debian/1%10.0.0+r36-3_stage1
  • debian/1%10.0.0+r36-2
  • debian/1%10.0.0+r36-1
  • debian/1%10.0.0+r36-1_stage1.3
  • debian/1%10.0.0+r36-1_stage1.2
  • debian/1%10.0.0+r36-1_stage1.1
  • debian/1%10.0.0+r36-1_stage1
  • upstream/10.0.0+r36
25 results

CodeCacheStatFail_test.cpp

Blame
  • first_app.py 1.78 KiB
    #!/usr/bin/env python
    # coding=utf-8
    """
    A simple application using cmd2 which demonstrates 8 key features:
    
        * Settings
        * Commands
        * Argument Parsing
        * Generating Output
        * Help
        * Shortcuts
        * Multiline Commands
        * History
    """
    
    import cmd2
    
    
    class FirstApp(cmd2.Cmd):
        """A simple cmd2 application."""
    
        def __init__(self):
            shortcuts = cmd2.DEFAULT_SHORTCUTS
            shortcuts.update({'&': 'speak'})
            super().__init__(multiline_commands=['orate'], shortcuts=shortcuts)
    
            # Make maxrepeats settable at runtime
            self.maxrepeats = 3
            self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command', self))
    
        speak_parser = cmd2.Cmd2ArgumentParser()
        speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
        speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
        speak_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
        speak_parser.add_argument('words', nargs='+', help='words to say')
    
        @cmd2.with_argparser(speak_parser)
        def do_speak(self, args):
            """Repeats what you tell me to."""
            words = []
            for word in args.words:
                if args.piglatin:
                    word = '%s%say' % (word[1:], word[0])
                if args.shout:
                    word = word.upper()
                words.append(word)
            repetitions = args.repeat or 1
            for _ in range(min(repetitions, self.maxrepeats)):
                # .poutput handles newlines, and accommodates output redirection too
                self.poutput(' '.join(words))
    
        # orate is a synonym for speak which takes multiline input
        do_orate = do_speak
    
    
    if __name__ == '__main__':
        import sys
    
        c = FirstApp()
        sys.exit(c.cmdloop())