def parser_for_options(): """ Handle command-line options with LoggingOptionParser. Return parser, largely for use in `parse_arguments`. On this parser, you must call parser.parse_args() """ # # Initialize # parser = LoggingOptionParser( usage='presto-admin [options] <command> [arg]', version='presto-admin %s' % __version__, epilog='\n' + '\n'.join(list_commands(None, 'normal'))) # # Define options that don't become `env` vars (typically ones which cause # Fabric to do something other than its normal execution, such as # --version) # # Display info about a specific command parser.add_option('-d', '--display', dest='display', action='store_true', default=False, help='print detailed information about command') parser.add_option('--extended-help', action='store_true', dest='extended_help', default=False, help='print out all options, including advanced ones') parser.add_option('-I', '--initial-password-prompt', action='store_true', default=False, help="Force password prompt up-front") parser.add_option('--nodeps', action='store_true', dest='nodeps', default=False, help=SUPPRESS_HELP) parser.add_option('--force', action='store_true', dest='force', default=False, help=SUPPRESS_HELP) # # Add in options which are also destined to show up as `env` vars. # advanced_options = HiddenOptionGroup(parser, "Advanced Options", suppress_help=True) # Hide most of the options from the help text so it's simpler. Need to # document the other options, however. commands_to_show = ['password'] for option in presto_env_options: if option.dest in commands_to_show: parser.add_option(option) else: advanced_options.add_option(option) advanced_options.add_option('--serial', action='store_true', dest='serial', default=False, help="default to serial execution method") # Allow setting of arbitrary env vars at runtime. advanced_options.add_option('--set', metavar="KEY=VALUE,...", dest='env_settings', default="", help=SUPPRESS_HELP) parser.add_option_group(advanced_options) # Return parser return parser
def parser_for_options(): """ Handle command-line options with LoggingOptionParser. Return parser, largely for use in `parse_arguments`. On this parser, you must call parser.parse_args() """ # # Initialize # parser = LoggingOptionParser( usage='presto-admin [options] <command> [arg]', version='presto-admin %s' % __version__, epilog='\n' + '\n'.join(list_commands(None, 'normal'))) # # Define options that don't become `env` vars (typically ones which cause # Fabric to do something other than its normal execution, such as # --version) # # Display info about a specific command parser.add_option( '-d', '--display', dest='display', action='store_true', default=False, help='print detailed information about command' ) parser.add_option( '--extended-help', action='store_true', dest='extended_help', default=False, help='print out all options, including advanced ones' ) parser.add_option( '-I', '--initial-password-prompt', action='store_true', default=False, help="Force password prompt up-front" ) parser.add_option( '--nodeps', action='store_true', dest='nodeps', default=False, help=SUPPRESS_HELP ) parser.add_option( '--force', action='store_true', dest='force', default=False, help=SUPPRESS_HELP ) # # Add in options which are also destined to show up as `env` vars. # advanced_options = HiddenOptionGroup(parser, "Advanced Options", suppress_help=True) # Hide most of the options from the help text so it's simpler. Need to # document the other options, however. commands_to_show = ['password'] for option in presto_env_options: if option.dest in commands_to_show: parser.add_option(option) else: advanced_options.add_option(option) advanced_options.add_option( '--serial', action='store_true', dest='serial', default=False, help="default to serial execution method" ) # Allow setting of arbitrary env vars at runtime. advanced_options.add_option( '--set', metavar="KEY=VALUE,...", dest='env_settings', default="", help=SUPPRESS_HELP ) parser.add_option_group(advanced_options) # Return parser return parser
def test_print_extended_help(self): parser = LoggingOptionParser(usage="Hello World") parser.add_option_group("a") hidden_group = HiddenOptionGroup(parser, "b", suppress_help=True) non_hidden_group = HiddenOptionGroup(parser, "c", suppress_help=False) parser.add_option_group(hidden_group) parser.add_option_group(non_hidden_group) help_out = StringIO() parser.print_help(help_out) self.assertEqual( help_out.getvalue(), "Usage: Hello World\n\nOptions:\n -h, --help show " "this help message and exit\n\n a:\n\n\n c:\n") extended_help_out = StringIO() parser.print_extended_help(extended_help_out) self.assertEqual( extended_help_out.getvalue(), "Usage: Hello World\n\nOptions:\n -h, --help show " "this help message and exit\n\n a:\n\n b:\n\n " "c:\n")
def test_print_extended_help(self): parser = LoggingOptionParser(usage="Hello World") parser.add_option_group("a") hidden_group = HiddenOptionGroup(parser, "b", suppress_help=True) non_hidden_group = HiddenOptionGroup(parser, "c", suppress_help=False) parser.add_option_group(hidden_group) parser.add_option_group(non_hidden_group) help_out = StringIO() parser.print_help(help_out) self.assertEqual(help_out.getvalue(), "Usage: Hello World\n\nOptions:\n -h, --help show " "this help message and exit\n\n a:\n\n\n c:\n") extended_help_out = StringIO() parser.print_extended_help(extended_help_out) self.assertEqual(extended_help_out.getvalue(), "Usage: Hello World\n\nOptions:\n -h, --help show " "this help message and exit\n\n a:\n\n b:\n\n " "c:\n")