def __init__(self, *args, **kwargs): super(DemosArgParser, self).__init__(*args, **kwargs) self.description = "Run a yowsup demo" net_layer_opts = self.add_argument_group("Network layer props") net_layer_opts.add_argument( '--layer-network-dispatcher', action="store", choices=("asyncore", "socket"), help="Specify which connection dispatcher to use") cmdopts = self.add_argument_group("Command line interface demo") cmdopts.add_argument('-y', '--yowsup', action="store_true", help="Start the Yowsup command line client") logging = self.add_argument_group("Logging options") logging.add_argument("--log-dissononce", action="store_true", help="Configure logging for dissononce/noise") logging.add_argument("--log-consonance", action="store_true", help="Configure logging for consonance") self._layer_network_dispatcher = None
def define_arguments(): std_args = ArgumentParser(add_help=False) std_args.add_argument("profile", help="(aka environment)") std_args.add_argument("region", help="e.g. us-east-1, us-west-2, etc.") std_args.add_argument("vpc", help="VPC ID or 'classic'") logging = std_args.add_mutually_exclusive_group() logging.add_argument("--verbose", action="store_true", default=False) logging.add_argument("--debug", action="store_true", default=False) group_selection = std_args.add_mutually_exclusive_group() group_selection.add_argument("--groups", nargs="*", metavar="GROUP", default=[], help="Only list/modify these groups") ap = ArgumentParser() sp = ap.add_subparsers(title="Subcommands", dest="subcommand") sp.required = True #===== listcmd = sp.add_parser("list", parents=[std_args], description="List current rules") listcmd.add_argument("--names", action='store_true', default=False) listcmd.set_defaults(do=do_list_rules) # the rest of the command require file input ... std_args.add_argument("--files", nargs="*", metavar="FILE", default=["-"], help="Read rules from FILE instead of stdin. To include stdin explicitly, use '-'") std_args.add_argument("--tty", action="store_true", default=False, help="Allow input from a tty") # ... and can make changes std_args.add_argument("--noop", action="store_true", default=False, help="Don't change anything, just print what would have changed") #===== addcmd = sp.add_parser("add", parents=[std_args], description="Add given rules") addcmd.add_argument("--create", help="Create named groups if needed") addcmd.set_defaults(do=do_add_rules) #===== delcmd = sp.add_parser("remove", parents=[std_args]) delcmd.set_defaults(do=do_remove_rules) #===== upd_order = std_args.add_mutually_exclusive_group() upd_order.add_argument("--add-before-remove", action='store_true', default=True) upd_order.add_argument("--remove-before-add", action='store_false', dest="add_before_remove") group_selection.add_argument("--obliterate", action="store_true", default=False, help="Remove all rules from groups not mentioned in the rule set") updcmd = sp.add_parser("update", parents=[std_args]) updcmd.set_defaults(do=do_update_rules) return ap
def make_parser(self, defaults): """Create an argparse ArgumentParser, setup --verbose, --silent, --debug and call specify_other_args""" parser = argparse.ArgumentParser(description=self.description) logging = parser.add_mutually_exclusive_group() logging.add_argument("--verbose" , help = "Enable debug logging" , action = "store_true" ) if "default" in defaults.get("--silent", {}): kwargs = defaults["--silent"] else: kwargs = {"action": "store_true"} logging.add_argument("--silent" , help = "Only log errors" , **kwargs ) logging.add_argument("--debug" , help = "Debug logs" , action = "store_true" ) logging.add_argument("--logging-program" , help = "The program name to use when not logging to the console" ) parser.add_argument("--tcp-logging-address" , help = "The address to use for giving log messages to tcp (i.e. localhost:9001)" , default = "" ) parser.add_argument("--udp-logging-address" , help = "The address to use for giving log messages to udp (i.e. localhost:9001)" , default = "" ) parser.add_argument("--syslog-address" , help = "The address to use for syslog (i.e. /dev/log)" , default = "" ) parser.add_argument("--json-console-logs" , help = "If we haven't set other logging arguments, this will mean we log json lines to the console" , action = "store_true" ) parser.add_argument("--version" , help = "Print out the version!" , action = "store_true" ) self.specify_other_args(parser, defaults) return parser
def define_arguments(): """ Define command line arguments. :return: Argparser object """ std_args = ArgumentParser() std_args.add_argument("profile", help="(aka environment)") std_args.add_argument("region", help="e.g. us-east-1, us-west-2, etc.") std_args.add_argument( "--all", action="store_true", default=False, help="List all events including past events; " "by default, this only reports events that have not occurred" ) logging = std_args.add_mutually_exclusive_group() logging.add_argument("--verbose", action="store_true", default=False) logging.add_argument("--debug", action="store_true", default=False) return std_args
def make_parser(self, defaults): """Create an argparse ArgumentParser, setup --verbose, --silent, --debug and call specify_other_args""" parser = argparse.ArgumentParser(description=self.description) logging = parser.add_mutually_exclusive_group() logging.add_argument("--verbose" , help = "Enable debug logging" , action = "store_true" ) logging.add_argument("--silent" , help = "Only log errors" , action = "store_true" ) logging.add_argument("--debug" , help = "Debug logs" , action = "store_true" ) self.specify_other_args(parser, defaults) return parser
def make_parser(self, default_task=NotSpecified, default_image=NotSpecified): parser = argparse.ArgumentParser(description="Opinionated layer around docker") logging = parser.add_mutually_exclusive_group() logging.add_argument("--verbose" , help = "Enable debug logging" , action = "store_true" ) logging.add_argument("--silent" , help = "Only log errors" , action = "store_true" ) opts = {} if os.path.exists("./harpoon.yml"): opts["default"] = "./harpoon.yml" else: opts["required"] = True parser.add_argument("--harpoon-config" , help = "The config file specifying what harpoon should care about" , type = argparse.FileType("r") , **opts ) extra = {"default": "list_tasks"} if default_task is not NotSpecified: extra["default"] = default_task parser.add_argument("--task" , help = "The task to run" , **extra ) parser.add_argument("--non-interactive" , help = "Make this non interactive" , dest = "interactive" , action = "store_false" ) extra = {} if default_image is not NotSpecified: extra["default"] = default_image parser.add_argument("--image" , help = "Specify a particular image" , **extra ) command = parser.add_mutually_exclusive_group() command.add_argument("--command" , help = "Specify a command to run for tasks that need one" ) command.add_argument("--bash" , help = "Specify a command that will be ran as /bin/bash -c '<command>'" ) parser.add_argument("--silent-build" , help = "Make the build process quiet" , action = "store_true" ) parser.add_argument("--keep-replaced" , help = "Don't delete images that have their tag stolen by a new image" , action = "store_true" ) parser.add_argument("--no-intervention" , help = "Don't ask to intervene broken builds" , action = "store_true" ) parser.add_argument("--env" , help = "Environment option to start the container with" , action = "append" ) parser.add_argument("--port" , help = "Specify a port to publish in the running container you make" , dest = "ports" , action = "append" ) return parser
def define_arguments(): std_args = ArgumentParser(add_help=False) std_args.add_argument("profile", help="(aka environment)") std_args.add_argument("region", help="e.g. us-east-1, us-west-2, etc.") std_args.add_argument("vpc", help="VPC ID or 'classic'") logging = std_args.add_mutually_exclusive_group() logging.add_argument("--verbose", action="store_true", default=False) logging.add_argument("--debug", action="store_true", default=False) group_selection = std_args.add_mutually_exclusive_group() group_selection.add_argument("--groups", nargs="*", metavar="GROUP", default=[], help="Only list/modify these groups") ap = ArgumentParser() sp = ap.add_subparsers(title="Subcommands", dest="subcommand") sp.required = True #===== listcmd = sp.add_parser("list", parents=[std_args], description="List current rules") listcmd.add_argument("--names", action='store_true', default=False) listcmd.set_defaults(do=do_list_rules) # the rest of the command require file input ... std_args.add_argument( "--files", nargs="*", metavar="FILE", default=["-"], help= "Read rules from FILE instead of stdin. To include stdin explicitly, use '-'" ) std_args.add_argument("--tty", action="store_true", default=False, help="Allow input from a tty") # ... and can make changes std_args.add_argument( "--noop", action="store_true", default=False, help="Don't change anything, just print what would have changed") #===== addcmd = sp.add_parser("add", parents=[std_args], description="Add given rules") addcmd.add_argument("--create", help="Create named groups if needed") addcmd.set_defaults(do=do_add_rules) #===== delcmd = sp.add_parser("remove", parents=[std_args]) delcmd.set_defaults(do=do_remove_rules) #===== upd_order = std_args.add_mutually_exclusive_group() upd_order.add_argument("--add-before-remove", action='store_true', default=True) upd_order.add_argument("--remove-before-add", action='store_false', dest="add_before_remove") group_selection.add_argument( "--obliterate", action="store_true", default=False, help="Remove all rules from groups not mentioned in the rule set") updcmd = sp.add_parser("update", parents=[std_args]) updcmd.set_defaults(do=do_update_rules) return ap
def make_parser(self, default_task=NotSpecified, default_image=NotSpecified): parser = argparse.ArgumentParser( description="Opinionated layer around docker") logging = parser.add_mutually_exclusive_group() logging.add_argument("--verbose", help="Enable debug logging", action="store_true") logging.add_argument("--silent", help="Only log errors", action="store_true") logging.add_argument("--debug", help="Debug logs", action="store_true") opts = {} if os.path.exists("./harpoon.yml"): opts["default"] = "./harpoon.yml" opts["required"] = False else: opts["required"] = True if "HARPOON_CONFIG" in os.environ: opts["default"] = os.environ["HARPOON_CONFIG"] del opts["required"] parser.add_argument( "--harpoon-config", help="The config file specifying what harpoon should care about", type=argparse.FileType("r"), **opts) extra = {"default": "list_tasks"} if default_task is not NotSpecified: extra["default"] = default_task parser.add_argument("--task", help="The task to run", dest="harpoon_chosen_task", **extra) parser.add_argument("--non-interactive", help="Make this non interactive", dest="harpoon_interactive", action="store_false") extra = {"default": ""} if default_image is not NotSpecified: extra["default"] = default_image parser.add_argument("--image", help="Specify a particular image", dest="harpoon_chosen_image", **extra) command = parser.add_mutually_exclusive_group() command.add_argument( "--command", help="Specify a command to run for tasks that need one") command.add_argument( "--bash", help= "Specify a command that will be ran as /bin/bash -c '<command>'") parser.add_argument("--silent-build", help="Make the build process quiet", dest="harpoon_silent_build", action="store_true") parser.add_argument( "--keep-replaced", help= "Don't delete images that have their tag stolen by a new image", dest="harpoon_keep_replaced", action="store_true") parser.add_argument("--no-intervention", help="Don't ask to intervene broken builds", dest="harpoon_no_intervention", action="store_true") parser.add_argument( "--env", help="Environment option to start the container with", dest="extra_env", action="append") parser.add_argument( "--port", help="Specify a port to publish in the running container you make", dest="extra_ports", action="append") parser.add_argument("--flat", help="Used with the show command", dest="harpoon_flat", action="store_true") parser.add_argument( "--ignore-missing", help= "Used by the pull commands to ignore if an image doesn't exist", dest="harpoon_ignore_missing", action="store_true") return parser