Python argparse.SUPPRESS() Examples

The following are code examples for showing how to use argparse.SUPPRESS(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: quartetsampling   Author: FePhyFoFum   File: merge_output.py    (GNU General Public License v3.0) View Source Project 11 votes vote down vote up
def generate_argparser():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        epilog=LICENSE)
    parser.add_argument('-d', '--nodedata', required=True, nargs=1,
                        help=("file containing paths of one or more"
                              "RESULT.node.score.csv files"))
    parser.add_argument('-t', '--tree', required=True, type=open,
                        nargs=1,
                        help="tree file in Newick format")
    parser.add_argument('-o', '--out', required=True,
                        nargs=1,
                        help="new output files prefix")
    parser.add_argument("-v", "--verbose", action="store_true")
    # These args are hidden to pass through to the treedata object
    parser.add_argument("-c", "--clade", nargs=1, help=argparse.SUPPRESS)
    parser.add_argument("-s", "--startk", type=int, default=0,
                        help=argparse.SUPPRESS)
    parser.add_argument("-p", "--stopk", type=int, help=argparse.SUPPRESS)
    return parser 
Example 2
Project: devsecops-example-helloworld   Author: boozallen   File: main.py    (license) View Source Project 7 votes vote down vote up
def _getDiscoveryArgParser(self, parent):
        parser = argparse.ArgumentParser(parents=[parent])
        parser.prog = '%s discover' % self.progName
        parser.epilog = ('For test discovery all test modules must be '
                         'importable from the top level directory of the '
                         'project.')

        parser.add_argument('-s', '--start-directory', dest='start',
                            help="Directory to start discovery ('.' default)")
        parser.add_argument('-p', '--pattern', dest='pattern',
                            help="Pattern to match tests ('test*.py' default)")
        parser.add_argument('-t', '--top-level-directory', dest='top',
                            help='Top level directory of project (defaults to '
                                 'start directory)')
        for arg in ('start', 'pattern', 'top'):
            parser.add_argument(arg, nargs='?',
                                default=argparse.SUPPRESS,
                                help=argparse.SUPPRESS)

        return parser 
Example 3
Project: aws-encryption-sdk-cli   Author: awslabs   File: arg_parsing.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
def add_dummy_redirect_argument(self, expected_name):
        # type: (argparse.ArgumentParser, str) -> None
        """Adds a dummy redirect argument to the provided parser to catch typos when calling
        the specified valid long-form name.

        :param parser: Parser to which to add argument
        :type parser: argparse.ArgumentParser
        :param str expected_name: Valid long-form name for which to add dummy redirect
        """
        self.add_argument(
            expected_name[1:],
            dest='dummy_redirect',
            action='store_const',
            const=expected_name[1:],
            help=argparse.SUPPRESS
        )
        # ArgumentParser subclass confuses mypy
        self.__dummy_arguments.append(expected_name[1:])  # type: ignore 
Example 4
Project: allennlp   Author: allenai   File: train.py    (license) View Source Project 6 votes vote down vote up
def add_subparser(self, name: str, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
        # pylint: disable=protected-access
        description = '''Train the specified model on the specified dataset.'''
        subparser = parser.add_parser(
                name, description=description, help='Train a model')
        subparser.add_argument('param_path',
                               type=str,
                               help='path to parameter file describing the model to be trained')

        # This is necessary to preserve backward compatibility
        serialization = subparser.add_mutually_exclusive_group(required=True)
        serialization.add_argument('-s', '--serialization-dir',
                                   type=str,
                                   help='directory in which to save the model and its logs')
        serialization.add_argument('--serialization_dir',
                                   type=str,
                                   help=argparse.SUPPRESS)

        subparser.set_defaults(func=train_model_from_args)

        return subparser 
Example 5
Project: argparseinator   Author: ellethee   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def formatter_factory(show_defaults=True):
    """Formatter factory"""
    def get_help_string(self, action):
        lhelp = action.help
        if isinstance(show_defaults, (list, tuple)):
            if "-" + action.dest in show_defaults:
                return lhelp
        if '%(default)' not in action.help:
            if action.default is not argparse.SUPPRESS:
                defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
                if action.option_strings or action.nargs in defaulting_nargs:
                    lhelp += ' (default: %(default)s)'
        return lhelp

    def default_help_string(self, action):
        return action.help
    if show_defaults is True:
        ARPIFormatter._get_help_string = classmethod(get_help_string)
    else:
        ARPIFormatter._get_help_string = classmethod(default_help_string)
    return ARPIFormatter 
Example 6
Project: python-bileanclient   Author: openstack   File: shell.py    (license) View Source Project 6 votes vote down vote up
def _find_actions(self, subparsers, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            # Replace underscores with hyphens in the commands
            # displayed to the user
            command = attr[3:].replace('_', '-')
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            help = desc.strip().split('\n')[0]
            arguments = getattr(callback, 'arguments', [])

            subparser = subparsers.add_parser(command,
                                              help=help,
                                              description=desc,
                                              add_help=False,
                                              formatter_class=HelpFormatter
                                              )
            subparser.add_argument('-h', '--help',
                                   action='help',
                                   help=argparse.SUPPRESS,
                                   )
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)
            subparser.set_defaults(func=callback) 
Example 7
Project: python-bileanclient   Author: openstack   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 8
Project: cheribuild   Author: CTSRD-CHERI   File: loader.py    (license) View Source Project 6 votes vote down vote up
def finalizeOptions(self, availableTargets: list):
        targetOption = self._parser.add_argument("targets", metavar="TARGET", nargs=argparse.ZERO_OR_MORE,
                                                 help="The targets to build", choices=availableTargets + [[]])
        if argcomplete and "_ARGCOMPLETE" in os.environ:
            # if IS_FREEBSD: # FIXME: for some reason this won't work
            excludes = ["-t", "--skip-dependencies"]
            if sys.platform.startswith("freebsd"):
                excludes += ["--freebsd-builder-copy-only", "--freebsd-builder-hostname",
                             "--freebsd-builder-output-path"]

            visibleTargets = availableTargets.copy()
            visibleTargets.remove("__run_everything__")
            targetCompleter = argcomplete.completers.ChoicesCompleter(visibleTargets)
            targetOption.completer = targetCompleter
            # make sure we get target completion for the unparsed args too by adding another zero_or more options
            # not sure why this works but it's a nice hack
            unparsed = self._parser.add_argument("targets", metavar="TARGET", type=list, nargs=argparse.ZERO_OR_MORE,
                                                 help=argparse.SUPPRESS, choices=availableTargets)
            unparsed.completer = targetCompleter
            argcomplete.autocomplete(
                self._parser,
                always_complete_options=None,  # don't print -/-- by default
                exclude=excludes,  # hide these options from the output
                print_suppressed=True,  # also include target-specific options
            ) 
Example 9
Project: TCP-IP   Author: JackZ0   File: util.py    (license) View Source Project 6 votes vote down vote up
def add_deprecated_argument(add_argument, argument_name, nargs):
    """Adds a deprecated argument with the name argument_name.

    Deprecated arguments are not shown in the help. If they are used on
    the command line, a warning is shown stating that the argument is
    deprecated and no other action is taken.

    :param callable add_argument: Function that adds arguments to an
        argument parser/group.
    :param str argument_name: Name of deprecated argument.
    :param nargs: Value for nargs when adding the argument to argparse.

    """
    if _ShowWarning not in configargparse.ACTION_TYPES_THAT_DONT_NEED_A_VALUE:
        # In version 0.12.0 ACTION_TYPES_THAT_DONT_NEED_A_VALUE was
        # changed from a set to a tuple.
        if isinstance(configargparse.ACTION_TYPES_THAT_DONT_NEED_A_VALUE, set):
            # pylint: disable=no-member
            configargparse.ACTION_TYPES_THAT_DONT_NEED_A_VALUE.add(
                _ShowWarning)
        else:
            configargparse.ACTION_TYPES_THAT_DONT_NEED_A_VALUE += (
                _ShowWarning,)
    add_argument(argument_name, action=_ShowWarning,
                 help=argparse.SUPPRESS, nargs=nargs) 
Example 10
Project: python-kingbirdclient   Author: openstack   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 11
Project: ngraph   Author: NervanaSystems   File: flexargparser.py    (license) View Source Project 6 votes vote down vote up
def setup_flex_args(argParser):
        """
        Add flex specific arguments to other default args used by ngraph
        """
        # use fixed point for flex backend
        argParser.add_argument('--fixed_point',
                               action="store_true",
                               help=argparse.SUPPRESS)
        # turn on flex verbosity for debug
        argParser.add_argument('--flex_verbose',
                               action="store_true",
                               help=argparse.SUPPRESS)
        # collect flex data and save it to h5py File
        argParser.add_argument('--collect_flex_data',
                               action="store_true",
                               default=argparse.SUPPRESS) 
Example 12
Project: ribolands   Author: bad-ants-fleet   File: BarMap.py    (license) View Source Project 6 votes vote down vote up
def add_barmap_args(parser):
  """ A collection of arguments that are used by BarMap """
  ril.argparse_add_arguments(parser, 
      RNAsubopt=True,
      barriers=True,
      treekin=True,
      noLP=True, temperature=True, 
      tmpdir=True, name=True, force=True, verbose=True,
      start=True, stop=True, k0=True, tX=True, cutoff=True)

  parser.add_argument("--plot_title", default='')

  parser.add_argument("--pyplot", action="store_true",
      help="Plot the simulation using matplotlib. Interpret the legend \
          using the *log* output")
  parser.add_argument("--xmgrace", action="store_true",
      help="Print a plot for xmgrace. " + \
          "Interpret the legend using the *log* output")

  parser.add_argument("--adaptive", action="store_true",
      help="Automatically raise suboptimal energy range if computations fail.")

  parser.add_argument("--s_sortdir", default="/tmp", action="store", \
      help=argparse.SUPPRESS)
  return 
Example 13
Project: flasky   Author: RoseOu   File: config.py    (license) View Source Project 6 votes vote down vote up
def parser(self):
        kwargs = {
            "usage": self.usage,
            "prog": self.prog
        }
        parser = argparse.ArgumentParser(**kwargs)
        parser.add_argument("-v", "--version",
                action="version", default=argparse.SUPPRESS,
                version="%(prog)s (version " + __version__ + ")\n",
                help="show program's version number and exit")
        parser.add_argument("args", nargs="*", help=argparse.SUPPRESS)

        keys = sorted(self.settings, key=self.settings.__getitem__)
        for k in keys:
            self.settings[k].add_option(parser)

        return parser 
Example 14
Project: hologram-python   Author: hologram-io   File: hologram_send.py    (license) View Source Project 6 votes vote down vote up
def parse_hologram_send_args(parser):

    # Create a subparser
    parser.add_argument('--devicekey', nargs='?', help='Hologram device key (8 characters long)')
    parser.add_argument('message', nargs='?', help='Message that will be sent to the cloud')
    parser.add_argument('-v', nargs='?', action=VAction, dest='verbose', required=False)
    parser.add_argument('--host', required=False, help=argparse.SUPPRESS)
    parser.add_argument('-p', '--port', required=False, help=argparse.SUPPRESS)
    parser.add_argument('--authtype', default='totp', nargs='?',
                        help='The authentication type used if HologramCloud is in use. Choose between \'totp\' and \'csrpsk\'')

    # $ hologram send cloud ...
    parse_cloud_args(parser)

    # $ hologram send sms ...
    parse_sms_args(parser)

# EFFECTS: Parses the send cloud options. Sets the default command_selected option
#          to send_cloud. 
Example 15
Project: slicer_cli_web   Author: girder   File: cli_list_entrypoint.py    (license) View Source Project 6 votes vote down vote up
def _make_print_cli_list_spec_action(cli_list_spec_file):

    with open(cli_list_spec_file) as f:
        str_cli_list_spec = f.read()

    class _PrintCLIListSpecAction(argparse.Action):

        def __init__(self,
                     option_strings,
                     dest=argparse.SUPPRESS,
                     default=argparse.SUPPRESS,
                     help=None):
            super(_PrintCLIListSpecAction, self).__init__(
                option_strings=option_strings,
                dest=dest,
                default=default,
                nargs=0,
                help=help)

        def __call__(self, parser, namespace, values, option_string=None):
            print str_cli_list_spec
            parser.exit()

    return _PrintCLIListSpecAction 
Example 16
Project: chkit.old   Author: containerum   File: parser.py    (license) View Source Project 6 votes vote down vote up
def add_argument(self, action):
        if action.help is not argparse.SUPPRESS:

            # find all invocations
            get_invocation = self._format_action_invocation
            invocations = [get_invocation(action)]
            current_indent = self._current_indent
            for subaction in self._iter_indented_subactions(action):
                # compensate for the indent that will be added
                indent_chg = self._current_indent - current_indent
                added_indent = 'x'*indent_chg
                invocations.append(added_indent+get_invocation(subaction))
            # print('inv', invocations)

            # update the maximum item length
            invocation_length = max([len(s) for s in invocations])
            action_length = invocation_length + self._current_indent
            self._action_max_length = max(self._action_max_length,
                                          action_length)

            # add the item to the list
            self._add_item(self._format_action, [action]) 
Example 17
Project: calmjs   Author: calmjs   File: runtime.py    (license) View Source Project 6 votes vote down vote up
def init_argparser_source_registry(
            self, argparser, default=None, help=(
                'comma separated list of registries to use for gathering '
                'JavaScript sources from the given Python packages'
            )):
        """
        For setting up the source registry flag.
        """

        argparser.add_argument(
            '--source-registry', default=default,
            dest=CALMJS_MODULE_REGISTRY_NAMES, action=StoreDelimitedList,
            metavar='registry_name[,registry_name[...]]',
            help=help,
        )

        argparser.add_argument(
            '--source-registries', default=default,
            dest=CALMJS_MODULE_REGISTRY_NAMES, action=StoreDelimitedList,
            help=SUPPRESS,
        ) 
Example 18
Project: temboard-agent   Author: dalibo   File: adduser.py    (license) View Source Project 6 votes vote down vote up
def main(argv, environ):
    parser = ArgumentParser(
        prog='temboard-agent-adduser',
        description="Add a new temboard-agent user.",
        argument_default=UNDEFINED_ARGUMENT,
    )
    args = parser.parse_args(argv)
    config = load_configuration(
        specs=list_options_specs(), args=args, environ=environ,
    )

    # Load configuration from the configuration file.
    username = ask_username(config)
    password = ask_password()
    hash_ = hash_password(username, password).decode('utf-8')
    try:
        with open(config.temboard['users'], 'a') as fd:
            fd.write("%s:%s\n" % (username, hash_))
    except IOError as e:
        raise UserError(str(e))
    else:
        stdout.write("Done.\n") 
Example 19
Project: python-zunclient   Author: openstack   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 20
Project: chihu   Author: yelongyu   File: config.py    (license) View Source Project 6 votes vote down vote up
def parser(self):
        kwargs = {
            "usage": self.usage,
            "prog": self.prog
        }
        parser = argparse.ArgumentParser(**kwargs)
        parser.add_argument("-v", "--version",
                action="version", default=argparse.SUPPRESS,
                version="%(prog)s (version " + __version__ + ")\n",
                help="show program's version number and exit")
        parser.add_argument("args", nargs="*", help=argparse.SUPPRESS)

        keys = sorted(self.settings, key=self.settings.__getitem__)
        for k in keys:
            self.settings[k].add_option(parser)

        return parser 
Example 21
Project: ShelbySearch   Author: Agentscreech   File: config.py    (license) View Source Project 6 votes vote down vote up
def parser(self):
        kwargs = {
            "usage": self.usage,
            "prog": self.prog
        }
        parser = argparse.ArgumentParser(**kwargs)
        parser.add_argument("-v", "--version",
                action="version", default=argparse.SUPPRESS,
                version="%(prog)s (version " + __version__ + ")\n",
                help="show program's version number and exit")
        parser.add_argument("args", nargs="*", help=argparse.SUPPRESS)

        keys = sorted(self.settings, key=self.settings.__getitem__)
        for k in keys:
            self.settings[k].add_option(parser)

        return parser 
Example 22
Project: keras_experiments   Author: avolkov1   File: cifar10_cnn_mgpu_dflow.py    (license) View Source Project 6 votes vote down vote up
def parser_(desc):
    parser = parser_def_mgpu(desc)

    checkptfile = 'cifar10_cnn_mgpu.weights.best.hdf5'
    parser.add_argument(
        '--checkpt', action='store', nargs='?',
        const=checkptfile, default=SUPPRESS,
        help='S|Save (overwrites) and load the model weights if available.'
        '\nOptionally specify a file/filepath if the default name is '
        'undesired.\n(default: {})'.format(checkptfile))

    parser.add_argument('--aug', action='store_true', default=False,
                        help='S|Perform data augmentation on cifar10 set.\n')

    parser.add_argument('--logdevp', action='store_true', default=False,
                        help='S|Log device placement in Tensorflow.\n')

    args = parser.parse_args()

    return args 
Example 23
Project: keras_experiments   Author: avolkov1   File: cifar10_cnn_mgpu_tfqueue.py    (license) View Source Project 6 votes vote down vote up
def parser_(desc):
    parser = parser_def_mgpu(desc)

    remove_options(parser, ['--nccl', '--enqueue', '--syncopt', '--rdma'])

    parser.add_argument(
        '--checkpt', action='store', nargs='?',
        const=checkptfile, default=SUPPRESS,
        help='S|Save (overwrites) and load the model weights if available.'
        '\nOptionally specify a file/filepath if the default name is '
        'undesired.\n(default: {})'.format(checkptfile))

    parser.add_argument('--aug', action='store_true', default=False,
                        help='S|Perform data augmentation on cifar10 set.\n')

    parser.add_argument('--logdevp', action='store_true', default=False,
                        help='S|Log device placement in Tensorflow.\n')

    parser.add_argument('--datadir', default=SUPPRESS,
                        help='Data directory with Cifar10 dataset.')

    args = parser.parse_args()

    return args 
Example 24
Project: keras_experiments   Author: avolkov1   File: cifar10_cnn_mgpu_tfqueue_var.py    (license) View Source Project 6 votes vote down vote up
def parser_(desc):
    parser = parser_def_mgpu(desc)

    remove_options(parser, ['--nccl', '--enqueue', '--syncopt', '--rdma'])

    parser.add_argument(
        '--checkpt', action='store', nargs='?',
        const=checkptfile, default=SUPPRESS,
        help='S|Save (overwrites) and load the model weights if available.'
        '\nOptionally specify a file/filepath if the default name is '
        'undesired.\n(default: {})'.format(checkptfile))

    parser.add_argument('--aug', action='store_true', default=False,
                        help='S|Perform data augmentation on cifar10 set.\n')

    parser.add_argument('--logdevp', action='store_true', default=False,
                        help='S|Log device placement in Tensorflow.\n')

    parser.add_argument('--datadir', default=SUPPRESS,
                        help='Data directory with Cifar10 dataset.')

    args = parser.parse_args()

    return args 
Example 25
Project: keras_experiments   Author: avolkov1   File: cifar10_cnn_distrib_slurm.py    (license) View Source Project 6 votes vote down vote up
def parser_(desc):
    parser = parser_def_mgpu(desc)
    remove_options(parser, ['--mgpu', '--nccl'])

    checkptfile = 'cifar10_cnn_distrib.weights.best.hdf5'
    parser.add_argument(
        '--checkpt', action='store', nargs='?',
        const=checkptfile, default=SUPPRESS,
        help='S|Save (overwrites) and load the model weights if available.'
        '\nOptionally specify a file/filepath if the default name is '
        'undesired.\n(default: {})'.format(checkptfile))

    parser.add_argument('--aug', action='store_true', default=False,
                        help='S|Perform data augmentation on cifar10 set.\n')

    parser.add_argument('--logdevp', action='store_true', default=False,
                        help='S|Log device placement in Tensorflow.\n')

    args = parser.parse_args()

    return args 
Example 26
Project: keras_experiments   Author: avolkov1   File: cifar10_cnn_distrib_v2_slurm.py    (license) View Source Project 6 votes vote down vote up
def parser_(desc):
    parser = parser_def_mgpu(desc)
    remove_options(parser, ['--mgpu', '--nccl'])

    checkptfile = 'cifar10_cnn_distrib_v2.weights.best.hdf5'
    parser.add_argument(
        '--checkpt', action='store', nargs='?',
        const=checkptfile, default=SUPPRESS,
        help='S|Save (overwrites) and load the model weights if available.'
        '\nOptionally specify a file/filepath if the default name is '
        'undesired.\n(default: {})'.format(checkptfile))

    parser.add_argument('--aug', action='store_true', default=False,
                        help='S|Perform data augmentation on cifar10 set.\n')

    parser.add_argument('--logdevp', action='store_true', default=False,
                        help='S|Log device placement in Tensorflow.\n')

    args = parser.parse_args()

    return args 
Example 27
Project: keras_experiments   Author: avolkov1   File: variational_autoencoder_deconv_mgpu.py    (license) View Source Project 6 votes vote down vote up
def parser_(desc):
    parser = ap.ArgumentParser(description=desc)

    parser.add_argument(
        '--mgpu', action='store', nargs='?', type=int,
        const=-1,  # if mgpu is specified but value not provided then -1
        # if mgpu is not specified then defaults to 0 - single gpu
        # mgpu = 0 if getattr(args, 'mgpu', None) is None else args.mgpu
        default=ap.SUPPRESS,
        help='Run on multiple-GPUs using all available GPUs on a system.\n'
        'If not passed does not use multiple GPU. If passed uses all GPUs.\n'
        'Optionally specify a number to use that many GPUs. Another\n'
        'approach is to specify CUDA_VISIBLE_DEVICES=0,1,... when calling\n'
        'script and specify --mgpu to use this specified device list.\n'
        'This option is only supported with TensorFlow backend.\n')

    parser.add_argument('--epochs', type=int, default=5,
                        help='Number of epochs to run training for.')

    args = parser.parse_args()

    return args 
Example 28
Project: python-siggen   Author: larsks   File: main.py    (license) View Source Project 6 votes vote down vote up
def parse_args():
    p = argparse.ArgumentParser()
    g = p.add_argument_group('Logging options')
    g.add_argument('--verbose', '-v',
                   action='store_const',
                   const='INFO',
                   dest='loglevel')
    g.add_argument('--debug',
                   action='store_const',
                   const='DEBUG',
                   dest='loglevel')

    p.add_argument('--config', '-f',
                   default='siggen.yml')

    p.add_argument('--nomidi',
                   action='store_true',
                   help=argparse.SUPPRESS)

    p.add_argument('--list', '-l',
                   action='store_true',
                   help='list available devices')

    p.set_defaults(loglevel='WARN')
    return p.parse_args() 
Example 29
Project: certbot   Author: nikoloskii   File: cli.py    (license) View Source Project 6 votes vote down vote up
def add(self, topic, *args, **kwargs):
        """Add a new command line argument.

        :param str: help topic this should be listed under, can be None for
                    "always documented"
        :param list *args: the names of this argument flag
        :param dict **kwargs: various argparse settings for this argument

        """

        if self.detect_defaults:
            kwargs = self.modify_kwargs_for_default_detection(**kwargs)

        if self.visible_topics[topic]:
            if topic in self.groups:
                group = self.groups[topic]
                group.add_argument(*args, **kwargs)
            else:
                self.parser.add_argument(*args, **kwargs)
        else:
            kwargs["help"] = argparse.SUPPRESS
            self.parser.add_argument(*args, **kwargs) 
Example 30
Project: certbot   Author: nikoloskii   File: util.py    (license) View Source Project 6 votes vote down vote up
def add_deprecated_argument(add_argument, argument_name, nargs):
    """Adds a deprecated argument with the name argument_name.

    Deprecated arguments are not shown in the help. If they are used on
    the command line, a warning is shown stating that the argument is
    deprecated and no other action is taken.

    :param callable add_argument: Function that adds arguments to an
        argument parser/group.
    :param str argument_name: Name of deprecated argument.
    :param nargs: Value for nargs when adding the argument to argparse.

    """
    class ShowWarning(argparse.Action):
        """Action to log a warning when an argument is used."""
        def __call__(self, unused1, unused2, unused3, option_string=None):
            sys.stderr.write(
                "Use of {0} is deprecated.\n".format(option_string))

    configargparse.ACTION_TYPES_THAT_DONT_NEED_A_VALUE.add(ShowWarning)
    add_argument(argument_name, action=ShowWarning,
                 help=argparse.SUPPRESS, nargs=nargs) 
Example 31
Project: intel-manager-for-lustre   Author: intel-hpdd   File: handlers.py    (license) View Source Project 6 votes vote down vote up
def _api_fields_to_parser_args(self, parser, add_help=False):
        if add_help:
            parser.add_argument("--help", "-h",
                                help="show this help message and exit",
                                default=SUPPRESS, action='help')
        for name, attrs in self.api_endpoint.fields.items():
            if attrs['readonly']:
                continue

            kwargs = {'help': attrs['help_text']}
            if attrs['type'] in ["related", "list"]:
                kwargs['action'] = "append"
                kwargs['type'] = str
            elif attrs['type'] == "boolean":
                kwargs['action'] = "store_true"
                kwargs['default'] = False
            elif attrs['type'] == "integer":
                kwargs['type'] = int

            parser.add_argument("--%s" % name, **kwargs) 
Example 32
Project: Price-Comparator   Author: Thejas-1   File: config.py    (license) View Source Project 6 votes vote down vote up
def parser(self):
        kwargs = {
            "usage": self.usage,
            "prog": self.prog
        }
        parser = argparse.ArgumentParser(**kwargs)
        parser.add_argument("-v", "--version",
                action="version", default=argparse.SUPPRESS,
                version="%(prog)s (version " + __version__ + ")\n",
                help="show program's version number and exit")
        parser.add_argument("args", nargs="*", help=argparse.SUPPRESS)

        keys = sorted(self.settings, key=self.settings.__getitem__)
        for k in keys:
            self.settings[k].add_option(parser)

        return parser 
Example 33
Project: dockercloud-cli   Author: docker   File: cli.py    (license) View Source Project 6 votes vote down vote up
def initialize_parser():
    # Top parser
    parser = argparse.ArgumentParser(description="Docker Cloud CLI", prog='docker-cloud')
    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
    parser.add_argument('--debug', action='store_true', help=argparse.SUPPRESS)
    subparsers = parser.add_subparsers(title="Docker Cloud CLI commands", dest='cmd')
    # Command Parsers
    parsers.add_action_parser(subparsers)
    parsers.add_container_parser(subparsers)
    parsers.add_event_parser(subparsers)
    parsers.add_exec_parser(subparsers)
    parsers.add_login_parser(subparsers)
    parsers.add_node_parser(subparsers)
    parsers.add_nodecluster_parser(subparsers)
    parsers.add_repository_parser(subparsers)
    parsers.add_run_parser(subparsers)
    parsers.add_service_parser(subparsers)
    parsers.add_stack_parser(subparsers)
    parsers.add_tag_parser(subparsers)
    parsers.add_trigger_parser(subparsers)
    parsers.add_up_parser(subparsers)
    return parser 
Example 34
Project: tabmaster   Author: NicolasMinghetti   File: config.py    (license) View Source Project 6 votes vote down vote up
def parser(self):
        kwargs = {
            "usage": self.usage,
            "prog": self.prog
        }
        parser = argparse.ArgumentParser(**kwargs)
        parser.add_argument("-v", "--version",
                action="version", default=argparse.SUPPRESS,
                version="%(prog)s (version " + __version__ + ")\n",
                help="show program's version number and exit")
        parser.add_argument("args", nargs="*", help=argparse.SUPPRESS)

        keys = sorted(self.settings, key=self.settings.__getitem__)
        for k in keys:
            self.settings[k].add_option(parser)

        return parser 
Example 35
Project: nicfit.py   Author: nicfit   File: logger.py    (license) View Source Project 6 votes vote down vote up
def addCommandLineArgs(arg_parser):
    """Add logging option to an ArgumentParser."""
    arg_parser.register("action", "log_levels", LogLevelAction)
    arg_parser.register("action", "log_files", LogFileAction)
    arg_parser.register("action", "log_help", LogHelpAction)

    group = arg_parser.add_argument_group("Logging options")
    group.add_argument(
        "-l", "--log-level", dest="log_levels",
        action="log_levels", metavar="LOGGER:LEVEL", default=[],
        help="Set log levels for individual loggers. See --help-logging for "
             "complete details.")

    group.add_argument(
        "-L", "--log-file", dest="log_files",
        action="log_files", metavar="LOGGER:FILE", default=[],
        help="Set log the output file for individual loggers. "
             " See --help-logging for complete details.")

    group.add_argument("--help-logging", action="log_help",
                       help=argparse.SUPPRESS) 
Example 36
Project: python-karborclient   Author: openstack   File: shell.py    (license) View Source Project 6 votes vote down vote up
def _find_actions(self, subparsers, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            # I prefer to be hypen-separated instead of underscores.
            command = attr[3:].replace('_', '-')
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            help = desc.strip().split('\n')[0]
            arguments = getattr(callback, 'arguments', [])

            subparser = subparsers.add_parser(command, help=help,
                                              description=desc,
                                              add_help=False,
                                              formatter_class=HelpFormatter)
            subparser.add_argument('-h', '--help', action='help',
                                   help=argparse.SUPPRESS)
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)
            subparser.set_defaults(func=callback) 
Example 37
Project: python-karborclient   Author: openstack   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 38
Project: python-distilclient   Author: openstack   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 39
Project: infiblog   Author: RajuKoushik   File: config.py    (license) View Source Project 6 votes vote down vote up
def parser(self):
        kwargs = {
            "usage": self.usage,
            "prog": self.prog
        }
        parser = argparse.ArgumentParser(**kwargs)
        parser.add_argument("-v", "--version",
                action="version", default=argparse.SUPPRESS,
                version="%(prog)s (version " + __version__ + ")\n",
                help="show program's version number and exit")
        parser.add_argument("args", nargs="*", help=argparse.SUPPRESS)

        keys = sorted(self.settings, key=self.settings.__getitem__)
        for k in keys:
            self.settings[k].add_option(parser)

        return parser 
Example 40
Project: eclcli   Author: nttcom   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 41
Project: eclcli   Author: nttcom   File: shell.py    (license) View Source Project 6 votes vote down vote up
def _find_actions(self, subparsers, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            # I prefer to be hyphen-separated instead of underscores.
            command = attr[3:].replace('_', '-')
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            help = desc.strip().split('\n')[0]
            arguments = getattr(callback, 'arguments', [])

            subparser = subparsers.add_parser(command,
                                              help=help,
                                              description=desc,
                                              add_help=False,
                                              formatter_class=HelpFormatter)
            subparser.add_argument('-h', '--help',
                                   action='help',
                                   help=argparse.SUPPRESS)
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)
            subparser.set_defaults(func=callback) 
Example 42
Project: eclcli   Author: nttcom   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 43
Project: eclcli   Author: nttcom   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 44
Project: eclcli   Author: nttcom   File: service.py    (license) View Source Project 6 votes vote down vote up
def get_parser(self, prog_name):
        parser = super(CreateService, self).get_parser(prog_name)
        parser.add_argument(
            'type_or_name',
            metavar='<type>',
            help=_('New service type (compute, image, identity, volume, etc)'),
        )
        type_or_name_group = parser.add_mutually_exclusive_group()
        type_or_name_group.add_argument(
            '--type',
            metavar='<type>',
            help=argparse.SUPPRESS,
        )
        type_or_name_group.add_argument(
            '--name',
            metavar='<name>',
            help=_('New service name'),
        )
        parser.add_argument(
            '--description',
            metavar='<description>',
            help=_('New service description'),
        )
        return parser 
Example 45
Project: eclcli   Author: nttcom   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 46
Project: eclcli   Author: nttcom   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 47
Project: eclcli   Author: nttcom   File: shell.py    (license) View Source Project 6 votes vote down vote up
def _find_actions(self, subparsers, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            # I prefer to be hypen-separated instead of underscores.
            command = attr[3:].replace('_', '-')
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            help = desc.strip().split('\n')[0]
            arguments = getattr(callback, 'arguments', [])

            subparser = subparsers.add_parser(command, help=help,
                                              description=desc,
                                              add_help=False,
                                              formatter_class=HelpFormatter)
            subparser.add_argument('-h', '--help', action='help',
                                   help=argparse.SUPPRESS)
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)
            subparser.set_defaults(func=callback) 
Example 48
Project: eclcli   Author: nttcom   File: auth.py    (license) View Source Project 6 votes vote down vote up
def _parser_add_opt(parser, opt):
        """Add an option to parser in two variants.

        :param opt: option name (with underscores)
        """
        dashed_opt = opt.replace("_", "-")
        env_var = "OS_%s" % opt.upper()
        arg_default = os.environ.get(env_var, "")
        arg_help = "Defaults to env[%s]." % env_var
        parser.add_argument(
            "--os-%s" % dashed_opt,
            metavar="<%s>" % dashed_opt,
            default=arg_default,
            help=arg_help)
        parser.add_argument(
            "--os_%s" % opt,
            metavar="<%s>" % dashed_opt,
            help=argparse.SUPPRESS) 
Example 49
Project: pocscan   Author: erevus-cn   File: command.py    (license) View Source Project 6 votes vote down vote up
def add_headers_args(parser):
    headers_group = parser.add_argument_group('headers', 'headers for request')
    headers_group.add_argument(
        '-c', '--cookie',
        action=Grouped, dest="headers.Cookie",
        default=argparse.SUPPRESS, help="HTTP Cookie field"
    )
    headers_group.add_argument(
        '-r', '--referer',
        action=Grouped, dest="headers.Referer",
        default=argparse.SUPPRESS, help="HTTP Referer field"
    )
    headers_group.add_argument(
        '-u', '--user-agent',
        action=Grouped, dest="headers.User-Agent",
        default=argparse.SUPPRESS, help="HTTP User-Agent field"
    ) 
Example 50
Project: python-cratonclient   Author: openstack   File: main.py    (license) View Source Project 6 votes vote down vote up
def _find_subparsers(self, subparsers, actions_module):
        """Find subparsers by looking at *_shell files."""
        help_formatter = argparse.HelpFormatter
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            command = attr[3:].replace('_', '-')
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            action_help = desc.strip()
            arguments = getattr(callback, 'arguments', [])
            subparser = (subparsers.add_parser(command,
                                               help=action_help,
                                               description=desc,
                                               add_help=False,
                                               formatter_class=help_formatter)
                         )
            subparser.add_argument('-h', '--help',
                                   action='help',
                                   help=argparse.SUPPRESS)
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)
            subparser.set_defaults(func=callback)