Esempio n. 1
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         names = get_all_bears_names()
         assert isinstance(names, list)
         self.assertSetEqual(
             set(names),
             set(TEST_BEAR_NAMES))
Esempio n. 2
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         self.assertSetEqual(
             set(get_all_bears_names()), {
                 'DependentBear', 'EchoBear', 'LineCountTestBear',
                 'JavaTestBear', 'SpaceConsistencyTestBear'
             })
Esempio n. 3
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         self.assertSetEqual(
             set(get_all_bears_names()),
             {'EchoBear',
              'LineCountTestBear',
              'JavaTestBear',
              'SpaceConsistencyTestBear'})
Esempio n. 4
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         names = get_all_bears_names()
         assert isinstance(names, list)
         self.assertSetEqual(
             set(names), {
                 'DependentBear', 'EchoBear', 'LineCountTestBear',
                 'JavaTestBear', 'SpaceConsistencyTestBear', 'TestBear'
             })
Esempio n. 5
0
 def test_argcomplete_imported(self):
     if coalib.parsing.DefaultArgParser.argcomplete is not None:
         coalib.parsing.DefaultArgParser.argcomplete = None
     parser = default_arg_parser()
     self.assertEqual(coalib.parsing.DefaultArgParser.argcomplete,
                      argcomplete)
     arg = _get_arg(parser, '--bears')
     self.assertTrue(hasattr(arg, 'completer'))
     bears = list(arg.completer())
     self.assertEqual(bears, get_all_bears_names())
Esempio n. 6
0
 def test_argcomplete_imported(self):
     if coalib.parsing.DefaultArgParser.argcomplete is not None:
         coalib.parsing.DefaultArgParser.argcomplete = None
     parser = default_arg_parser()
     self.assertEqual(coalib.parsing.DefaultArgParser.argcomplete,
                      argcomplete)
     arg = _get_arg(parser, '--bears')
     self.assertTrue(hasattr(arg, 'completer'))
     bears = list(arg.completer())
     self.assertEqual(bears, get_all_bears_names())
Esempio n. 7
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         names = get_all_bears_names()
         assert isinstance(names, list)
         self.assertSetEqual(
             set(names),
             {'DependentBear',
              'EchoBear',
              'LineCountTestBear',
              'JavaTestBear',
              'SpaceConsistencyTestBear',
              'TestBear'})
Esempio n. 8
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         names = get_all_bears_names()
         assert isinstance(names, list)
         self.assertSetEqual(
             set(names), {
                 'DependentBear', 'EchoBear', 'LineCountTestBear',
                 'JavaTestBear', 'SpaceConsistencyTestBear', 'TestBear',
                 'ErrorTestBear', 'RaiseTestBear', 'TestDepBearA',
                 'TestDepBearBDependsA', 'TestDepBearCDependsB',
                 'TestDepBearAA', 'TestDepBearDependsAAndAA'
             })
Esempio n. 9
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         names = get_all_bears_names()
         assert isinstance(names, list)
         self.assertSetEqual(
             set(names),
             {'DependentBear',
              'EchoBear',
              'LineCountTestBear',
              'JavaTestBear',
              'SpaceConsistencyTestBear',
              'TestBear',
              'ErrorTestBear',
              'RaiseTestBear',
              'TestDepBearA',
              'TestDepBearBDependsA',
              'TestDepBearCDependsB',
              'TestDepBearAA',
              'AspectTestBear',
              'TestDepBearDependsAAndAA'})
Esempio n. 10
0
def default_arg_parser(formatter_class=None):
    """
    This function creates an ArgParser to parse command line arguments.

    :param formatter_class: Formatting the arg_parser output into a specific
                            form. For example: In the manpage format.
    """
    formatter_class = formatter_class or CustomFormatter

    entry_point = sys.argv[0]
    for entry in [
            'coala-ci', 'coala-dbus', 'coala-format', 'coala-json',
            'coala-delete-orig'
    ]:
        if entry_point.endswith(entry):
            parser_type = entry
            break
    else:
        parser_type = 'coala'

    arg_parser = argparse.ArgumentParser(
        formatter_class=formatter_class,
        prog="coala",
        description="coala is a simple COde AnaLysis Application. Its goal "
        "is to make static code analysis easy and convenient "
        "for all languages. coala uses bears, which are analysis "
        "routines that can be combined arbitrarily.",
        # Use our own help so that we can put it in the group we want
        add_help=False)

    arg_parser.add_argument('TARGETS',
                            nargs='*',
                            help="Sections to be executed exclusively.")

    info_group = arg_parser.add_argument_group('Info')

    info_group.add_argument('-h',
                            '--help',
                            action='help',
                            help='show this help message and exit')

    info_group.add_argument('-v',
                            '--version',
                            action='version',
                            version=Constants.VERSION)

    config_group = arg_parser.add_argument_group('Configuration')

    CONFIG_HELP = ('Configuration file to be used, defaults to ' +
                   repr(Constants.default_coafile))
    config_group.add_argument('-c',
                              '--config',
                              nargs=1,
                              metavar='FILE',
                              help=CONFIG_HELP)

    FIND_CONFIG_HELP = ('Attempt to find config file by checking parent '
                        'directories of the current working directory. It is '
                        'assumed that the config file is named ' +
                        repr(Constants.default_coafile) + '. This arg is '
                        'ignored if --config is also given')
    config_group.add_argument('-F',
                              '--find-config',
                              nargs='?',
                              const=True,
                              metavar='BOOL',
                              help=FIND_CONFIG_HELP)

    config_group.add_argument('-I',
                              '--no-config',
                              nargs='?',
                              const=True,
                              metavar='BOOL',
                              help="Run without using any config file")

    SAVE_HELP = ('Save the used arguments to a config file at the given path, '
                 "or at the value of -c, which is '.coafile' by default.")
    config_group.add_argument('-s',
                              '--save',
                              nargs='?',
                              const=True,
                              metavar='FILE',
                              help=SAVE_HELP)

    inputs_group = arg_parser.add_argument_group('Inputs')

    inputs_group.add_argument('-b',
                              '--bears',
                              nargs='+',
                              metavar='NAME',
                              help='Names of bears to use').completer =\
        ChoicesCompleter(get_all_bears_names())

    inputs_group.add_argument('-f',
                              '--files',
                              nargs='+',
                              metavar='FILE',
                              help='Files that should be checked')

    inputs_group.add_argument('-i',
                              '--ignore',
                              nargs='+',
                              metavar='FILE',
                              help='Files that should be ignored')

    LIMIT_FILES_HELP = ('Files that will be analyzed will be restricted to '
                        'those in the globs listed in this argument as well '
                        'the files setting')
    inputs_group.add_argument('--limit-files',
                              nargs='+',
                              metavar='FILE',
                              help=LIMIT_FILES_HELP)

    BEAR_DIRS_HELP = 'Additional directories where bears may lie'
    inputs_group.add_argument('-d',
                              '--bear-dirs',
                              nargs='+',
                              metavar='DIR',
                              help=BEAR_DIRS_HELP)

    outputs_group = arg_parser.add_argument_group('Outputs')

    LOG_LEVEL_HELP = ("Enum('ERROR','INFO','WARNING','DEBUG') to set level of "
                      "log output")
    outputs_group.add_argument('-L',
                               '--log-level',
                               nargs=1,
                               choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'],
                               metavar='ENUM',
                               help=LOG_LEVEL_HELP)

    MIN_SEVERITY_HELP = ("Enum('INFO', 'NORMAL', 'MAJOR') to set the minimal "
                         "result severity.")
    outputs_group.add_argument('-m',
                               '--min-severity',
                               nargs=1,
                               choices=('INFO', 'NORMAL', 'MAJOR'),
                               metavar='ENUM',
                               help=MIN_SEVERITY_HELP)

    # The following are "coala" specific arguments
    if parser_type == 'coala':
        SHOW_BEARS_HELP = ("Display bears and its metadata with the sections "
                           "that they belong to")
        outputs_group.add_argument('-B',
                                   '--show-bears',
                                   nargs='?',
                                   const=True,
                                   metavar='BOOL',
                                   help=SHOW_BEARS_HELP)

        outputs_group.add_argument('-A',
                                   '--show-all-bears',
                                   nargs='?',
                                   const=True,
                                   metavar='BOOL',
                                   help="Display all bears.")

        SHOW_LANGUAGE_BEARS = ("Display all bears for the given languages.")
        outputs_group.add_argument('-l',
                                   '--show-language-bears',
                                   nargs='+',
                                   metavar='LANG',
                                   help=SHOW_LANGUAGE_BEARS)

    # The following are "coala-json" specific arguments
    if parser_type == 'coala-json':
        TEXT_LOGS_HELP = ("Don't display logs as json, display them as we "
                          "normally do in the console.")
        outputs_group.add_argument('--text-logs',
                                   nargs='?',
                                   const=True,
                                   metavar='BOOL',
                                   help=TEXT_LOGS_HELP)

        OUTPUT_HELP = ('Write the logs as json to a file where filename is '
                       'specified as argument.')
        outputs_group.add_argument('-o',
                                   '--output',
                                   nargs=1,
                                   metavar='FILE',
                                   help=OUTPUT_HELP)

        outputs_group.add_argument('-r',
                                   '--relpath',
                                   nargs='?',
                                   const=True,
                                   help="Return relative paths for files")

    misc_group = arg_parser.add_argument_group('Miscellaneous')

    SETTINGS_HELP = 'Arbitrary settings in the form of section.key=value'
    misc_group.add_argument('-S',
                            '--settings',
                            nargs='+',
                            metavar='SETTING',
                            help=SETTINGS_HELP)

    misc_group.add_argument("-j",
                            "--jobs",
                            type=int,
                            help="Number of jobs to use in parallel.")

    NO_ORIG_HELP = ('Deactivate creation of .orig files and .orig backup '
                    'files before applying patches')
    misc_group.add_argument('-n',
                            '--no-orig',
                            nargs='?',
                            const=True,
                            help=NO_ORIG_HELP)

    deprecated_group = arg_parser.add_argument_group('Deprecated')

    TAG_HELP = ('Tag results with a specific name. You can access the results '
                'later with that tag.')
    deprecated_group.add_argument('-t',
                                  '--tag',
                                  nargs='?',
                                  const=True,
                                  metavar='STRING',
                                  help=TAG_HELP)

    DELETE_TAG_HELP = 'Delete pre-tagged results with tag name.'
    deprecated_group.add_argument('-g',
                                  '--dtag',
                                  nargs='?',
                                  const=True,
                                  metavar='STRING',
                                  help=DELETE_TAG_HELP)

    try:  # pragma: no cover
        # Auto completion should be optional, because of somewhat complicated
        # setup.
        import argcomplete
        argcomplete.autocomplete(arg_parser)
    except ImportError:
        pass
    return arg_parser
Esempio n. 11
0
def default_arg_parser(formatter_class=None):
    """
    This function creates an ArgParser to parse command line arguments.

    :param formatter_class: Formatting the arg_parser output into a specific
                            form. For example: In the manpage format.
    """
    formatter_class = (CustomFormatter if formatter_class is None
                       else formatter_class)

    entry_point = sys.argv[0]
    for entry in ['coala-ci', 'coala-format', 'coala-json',
                  'coala-delete-orig']:
        if entry_point.endswith(entry):
            parser_type = entry
            break
    else:
        parser_type = 'coala'

    description = """
coala provides a common command-line interface for linting and fixing all your
code, regardless of the programming languages you use.

To find out what kind of analysis coala offers for the languages you use, visit
<https://github.com/coala/bear-docs/blob/master/README.rst#supported-languages>
or run:

    $ coala --show-bears --filter-by-language C Python

To perform code analysis, simply specify the analysis routines (bears) and the
files you want it to run on, for example:

    $ coala --bears SpaceConsistencyBear --files **.py

coala can also automatically fix your code:

    $ coala --bears SpaceConsistencyBear --files **.py --apply-patches

To run coala without user interaction, check out the `coala-json` and
`coala-format` binaries.
"""

    arg_parser = argparse.ArgumentParser(
        formatter_class=formatter_class,
        prog="coala",
        description=description,
        # Use our own help so that we can put it in the group we want
        add_help=False)

    arg_parser.add_argument('TARGETS',
                            nargs='*',
                            help="sections to be executed exclusively")

    info_group = arg_parser.add_argument_group('Info')

    info_group.add_argument('-h',
                            '--help',
                            action='help',
                            help='show this help message and exit')

    info_group.add_argument('-v',
                            '--version',
                            action='version',
                            version=Constants.VERSION)

    config_group = arg_parser.add_argument_group('Configuration')

    config_group.add_argument(
        '-c', '--config', nargs=1, metavar='FILE',
        help="configuration file to be used, defaults to {}".format(
            Constants.default_coafile))

    config_group.add_argument(
        '-F', '--find-config', action='store_const', const=True,
        help="find {} in ancestors of the working directory".format(
            Constants.default_coafile))

    config_group.add_argument(
        '-I', '--no-config', const=True, action='store_const',
        help="run without using any config file")

    config_group.add_argument(
        '-s', '--save', nargs='?', const=True, metavar='FILE',
        help="save used arguments to a config file to a {}, the given path, "
             "or at the value of -c".format(Constants.default_coafile))

    config_group.add_argument(
        '--disable-caching', const=True, action='store_const',
        help='run on all files even if unchanged')
    config_group.add_argument(
        '--flush-cache', const=True, action='store_const',
        help='rebuild the file cache')

    inputs_group = arg_parser.add_argument_group('Inputs')

    inputs_group.add_argument(
        '-b', '--bears', nargs='+', metavar='NAME',
        help='names of bears to use').completer = (
            lambda *args, **kwargs: get_all_bears_names())  # pragma: no cover

    inputs_group.add_argument(
        '-f', '--files', nargs='+', metavar='FILE',
        help='files that should be checked')

    inputs_group.add_argument(
        '-i', '--ignore', nargs='+', metavar='FILE',
        help='files that should be ignored')

    inputs_group.add_argument(
        '--limit-files', nargs='+', metavar='FILE',
        help="filter the `--files` argument's matches further")

    inputs_group.add_argument(
        '-d', '--bear-dirs', nargs='+', metavar='DIR',
        help='additional directories which may contain bears')

    outputs_group = arg_parser.add_argument_group('Outputs')

    outputs_group.add_argument(
        '-V', '--verbose', action='store_const',
        dest='log_level', const='DEBUG',
        help="alias for `-L DEBUG`")

    outputs_group.add_argument(
        '-L', '--log-level', nargs=1,
        choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'], metavar='ENUM',
        help="set log output level to ERROR/INFO/WARNING/DEBUG")

    outputs_group.add_argument(
        '-m', '--min-severity', nargs=1,
        choices=('INFO', 'NORMAL', 'MAJOR'), metavar='ENUM',
        help="set minimal result severity to INFO/NORMAL/MAJOR")

    outputs_group.add_argument(
        '-N', '--no-color', const=True, action='store_const',
        help="display output without coloring (excluding logs)")

    # Specific arguments
    if parser_type in ('coala', 'coala-json'):
        outputs_group.add_argument(
            '-B', '--show-bears', const=True, action='store_const',
            help='list all bears')

        outputs_group.add_argument(
            '-l', '--filter-by-language', nargs='+', metavar='LANG',
            help="filters `--show-bears` by the given languages")

        outputs_group.add_argument(
            '-p', '--show-capabilities', nargs='+', metavar='LANG',
            help="show what coala can fix and detect for the given languages")

    if parser_type == 'coala':
        outputs_group.add_argument(
            '-D', '--show-description', const=True, action='store_const',
            help="show bear descriptions for `--show-bears`")

        outputs_group.add_argument(
            '--show-details', const=True, action='store_const',
            help='show bear details for `--show-bears`')

    # The following are "coala-json" specific arguments
    if parser_type == 'coala-json':
        outputs_group.add_argument(
            '-o', '--output', nargs=1, metavar='FILE',
            help='write JSON logs to the given file')

        outputs_group.add_argument(
            '--text-logs', nargs='?', const=True, metavar='BOOL',
            help="use regular log messages instead of JSON")

        outputs_group.add_argument(
            '-r', '--relpath', nargs='?', const=True,
            help="return relative paths for files")

    misc_group = arg_parser.add_argument_group('Miscellaneous')

    misc_group.add_argument(
        '-S', '--settings', nargs='+', metavar='SETTING',
        help="arbitrary settings in the form of section.key=value")

    misc_group.add_argument(
        '-a', '--apply-patches', action='store_const',
        dest='default_actions', const='*: ApplyPatchAction',
        help='apply all patches automatically if possible')

    misc_group.add_argument(
        "-j", "--jobs", type=int,
        help="number of jobs to use in parallel")

    misc_group.add_argument(
        '-n', '--no-orig', const=True, action='store_const',
        help="don't create .orig backup files before patching")

    try:  # pragma: no cover
        # Auto completion should be optional, because of somewhat complicated
        # setup.
        import argcomplete
        argcomplete.autocomplete(arg_parser)
    except ImportError:
        pass
    return arg_parser
Esempio n. 12
0
def default_arg_parser(formatter_class=None):
    """
    This function creates an ArgParser to parse command line arguments.

    :param formatter_class: Formatting the arg_parser output into a specific
                            form. For example: In the manpage format.
    """
    formatter_class = (CustomFormatter if formatter_class is None
                       else formatter_class)

    entry_point = sys.argv[0]
    for entry in ['coala-ci', 'coala-format', 'coala-json',
                  'coala-delete-orig']:
        if entry_point.endswith(entry):
            parser_type = entry
            break
    else:
        parser_type = 'coala'

    description = """
coala provides a common command-line interface for linting and fixing all your
code, regardless of the programming languages you use.

To find out what kind of analysis coala offers for the languages you use, visit
<https://github.com/coala/bear-docs/blob/master/README.rst#supported-languages>
or run:

    $ coala --show-bears --filter-by-language C Python

To perform code analysis, simply specify the analysis routines (bears) and the
files you want it to run on, for example:

    $ coala --bears SpaceConsistencyBear --files **.py

coala can also automatically fix your code:

    $ coala --bears SpaceConsistencyBear --files **.py --apply-patches

To run coala without user interaction, check out the `coala-json` and
`coala-format` binaries.
"""

    arg_parser = argparse.ArgumentParser(
        formatter_class=formatter_class,
        prog="coala",
        description=description,
        # Use our own help so that we can put it in the group we want
        add_help=False)

    arg_parser.add_argument('TARGETS',
                            nargs='*',
                            help="sections to be executed exclusively")

    info_group = arg_parser.add_argument_group('Info')

    info_group.add_argument('-h',
                            '--help',
                            action='help',
                            help='show this help message and exit')

    info_group.add_argument('-v',
                            '--version',
                            action='version',
                            version=Constants.VERSION)

    config_group = arg_parser.add_argument_group('Configuration')

    config_group.add_argument(
        '-c', '--config', nargs=1, metavar='FILE',
        help="configuration file to be used, defaults to {}".format(
            Constants.default_coafile))

    config_group.add_argument(
        '-F', '--find-config', action='store_const', const=True,
        help="find {} in ancestors of the working directory".format(
            Constants.default_coafile))

    config_group.add_argument(
        '-I', '--no-config', const=True, action='store_const',
        help="run without using any config file")

    config_group.add_argument(
        '-s', '--save', nargs='?', const=True, metavar='FILE',
        help="save used arguments to a config file to a {}, the given path, "
             "or at the value of -c".format(Constants.default_coafile))

    config_group.add_argument(
        '--disable-caching', const=True, action='store_const',
        help='run on all files even if unchanged')
    config_group.add_argument(
        '--flush-cache', const=True, action='store_const',
        help='rebuild the file cache')

    inputs_group = arg_parser.add_argument_group('Inputs')

    inputs_group.add_argument(
        '-b', '--bears', nargs='+', metavar='NAME',
        help='names of bears to use').completer = (
            lambda *args, **kwargs: get_all_bears_names())  # pragma: no cover

    inputs_group.add_argument(
        '-f', '--files', nargs='+', metavar='FILE',
        help='files that should be checked')

    inputs_group.add_argument(
        '-i', '--ignore', nargs='+', metavar='FILE',
        help='files that should be ignored')

    inputs_group.add_argument(
        '--limit-files', nargs='+', metavar='FILE',
        help="filter the `--files` argument's matches further")

    inputs_group.add_argument(
        '-d', '--bear-dirs', nargs='+', metavar='DIR',
        help='additional directories which may contain bears')

    outputs_group = arg_parser.add_argument_group('Outputs')

    outputs_group.add_argument(
        '-V', '--verbose', action='store_const',
        dest='log_level', const='DEBUG',
        help="alias for `-L DEBUG`")

    outputs_group.add_argument(
        '-L', '--log-level', nargs=1,
        choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'], metavar='ENUM',
        help="set log output level to ERROR/INFO/WARNING/DEBUG")

    outputs_group.add_argument(
        '-m', '--min-severity', nargs=1,
        choices=('INFO', 'NORMAL', 'MAJOR'), metavar='ENUM',
        help="set minimal result severity to INFO/NORMAL/MAJOR")

    outputs_group.add_argument(
        '-N', '--no-color', const=True, action='store_const',
        help="display output without coloring (excluding logs)")

    # Specific arguments
    if parser_type in ('coala', 'coala-json'):
        outputs_group.add_argument(
            '-B', '--show-bears', const=True, action='store_const',
            help='list all bears')

        outputs_group.add_argument(
            '-l', '--filter-by-language', nargs='+', metavar='LANG',
            help="filters `--show-bears` by the given languages")

        outputs_group.add_argument(
            '-p', '--show-capabilities', nargs='+', metavar='LANG',
            help="show what coala can fix and detect for the given languages")

    if parser_type == 'coala':
        outputs_group.add_argument(
            '-D', '--show-description', const=True, action='store_const',
            help="show bear descriptions for `--show-bears`")

        outputs_group.add_argument(
            '--show-details', const=True, action='store_const',
            help='show bear details for `--show-bears`')

    # The following are "coala-json" specific arguments
    if parser_type == 'coala-json':
        outputs_group.add_argument(
            '-o', '--output', nargs=1, metavar='FILE',
            help='write JSON logs to the given file')

        outputs_group.add_argument(
            '-r', '--relpath', nargs='?', const=True,
            help="return relative paths for files")

    misc_group = arg_parser.add_argument_group('Miscellaneous')

    misc_group.add_argument(
        '-S', '--settings', nargs='+', metavar='SETTING',
        help="arbitrary settings in the form of section.key=value")

    misc_group.add_argument(
        '-a', '--apply-patches', action='store_const',
        dest='default_actions', const='*: ApplyPatchAction',
        help='apply all patches automatically if possible')

    misc_group.add_argument(
        "-j", "--jobs", type=int,
        help="number of jobs to use in parallel")

    misc_group.add_argument(
        '-n', '--no-orig', const=True, action='store_const',
        help="don't create .orig backup files before patching")

    try:  # pragma: no cover
        # Auto completion should be optional, because of somewhat complicated
        # setup.
        import argcomplete
        argcomplete.autocomplete(arg_parser)
    except ImportError:
        pass
    return arg_parser
Esempio n. 13
0
 def test_get_all_bears_names(self):
     with bear_test_module():
         names = get_all_bears_names()
         assert isinstance(names, list)
         self.assertSetEqual(set(names), set(TEST_BEAR_NAMES))
Esempio n. 14
0
def default_arg_parser(formatter_class=None):
    """
    This function creates an ArgParser to parse command line arguments.

    :param formatter_class: Formatting the arg_parser output into a specific
                            form. For example: In the manpage format.
    """
    formatter_class = formatter_class or CustomFormatter

    entry_point = sys.argv[0]
    for entry in ['coala-ci', 'coala-dbus', 'coala-format', 'coala-json',
                  'coala-delete-orig']:
        if entry_point.endswith(entry):
            parser_type = entry
            break
    else:
        parser_type = 'coala'

    arg_parser = argparse.ArgumentParser(
        formatter_class=formatter_class,
        prog="coala",
        description="coala is a simple COde AnaLysis Application. Its goal "
                    "is to make static code analysis easy and convenient "
                    "for all languages. coala uses bears, which are analysis "
                    "routines that can be combined arbitrarily.",
        # Use our own help so that we can put it in the group we want
        add_help=False)

    arg_parser.add_argument('TARGETS',
                            nargs='*',
                            help="Sections to be executed exclusively.")

    info_group = arg_parser.add_argument_group('Info')

    info_group.add_argument('-h',
                            '--help',
                            action='help',
                            help='show this help message and exit')

    info_group.add_argument('-v',
                            '--version',
                            action='version',
                            version=Constants.VERSION)

    config_group = arg_parser.add_argument_group('Configuration')

    CONFIG_HELP = ('Configuration file to be used, defaults to '
                   + repr(Constants.default_coafile))
    config_group.add_argument('-c',
                              '--config',
                              nargs=1,
                              metavar='FILE',
                              help=CONFIG_HELP)

    FIND_CONFIG_HELP = ('Attempt to find config file by checking parent '
                        'directories of the current working directory. It is '
                        'assumed that the config file is named '
                        + repr(Constants.default_coafile) + '. This arg is '
                        'ignored if --config is also given')
    config_group.add_argument('-F',
                              '--find-config',
                              action='store_const',
                              const=True,
                              help=FIND_CONFIG_HELP)

    config_group.add_argument('-I',
                              '--no-config',
                              const=True,
                              action='store_const',
                              help="Run without using any config file")

    SAVE_HELP = ('Save the used arguments to a config file at the given path, '
                 "or at the value of -c, which is '.coafile' by default.")
    config_group.add_argument('-s',
                              '--save',
                              nargs='?',
                              const=True,
                              metavar='FILE',
                              help=SAVE_HELP)

    CACHING_HELP = ('Run coala only on files that have changed '
                    'since the last time coala was run. Note: '
                    'Caching is currently experimental and '
                    'will be enabled by default from the next '
                    'release (this option will be removed)')
    config_group.add_argument('-C',
                              '--changed-files',
                              const=True,
                              action='store_const',
                              help=CACHING_HELP)
    config_group.add_argument('--flush-cache',
                              const=True,
                              action='store_const',
                              help='Rebuild the file cache')

    inputs_group = arg_parser.add_argument_group('Inputs')

    inputs_group.add_argument('-b',
                              '--bears',
                              nargs='+',
                              metavar='NAME',
                              help='Names of bears to use').completer =\
        ChoicesCompleter(get_all_bears_names())

    inputs_group.add_argument('-f',
                              '--files',
                              nargs='+',
                              metavar='FILE',
                              help='Files that should be checked')

    inputs_group.add_argument('-i',
                              '--ignore',
                              nargs='+',
                              metavar='FILE',
                              help='Files that should be ignored')

    LIMIT_FILES_HELP = ('Files that will be analyzed will be restricted to '
                        'those in the globs listed in this argument as well '
                        'the files setting')
    inputs_group.add_argument('--limit-files',
                              nargs='+',
                              metavar='FILE',
                              help=LIMIT_FILES_HELP)

    BEAR_DIRS_HELP = 'Additional directories where bears may lie'
    inputs_group.add_argument('-d',
                              '--bear-dirs',
                              nargs='+',
                              metavar='DIR',
                              help=BEAR_DIRS_HELP)

    outputs_group = arg_parser.add_argument_group('Outputs')

    outputs_group.add_argument('-V',
                               '--verbose',
                               action='store_const',
                               dest='log_level',
                               const='DEBUG',
                               help="Alias for `-L DEBUG`.")
    LOG_LEVEL_HELP = ("Enum('ERROR','INFO','WARNING','DEBUG') to set level of "
                      "log output")
    outputs_group.add_argument('-L',
                               '--log-level',
                               nargs=1,
                               choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'],
                               metavar='ENUM',
                               help=LOG_LEVEL_HELP)

    MIN_SEVERITY_HELP = ("Enum('INFO', 'NORMAL', 'MAJOR') to set the minimal "
                         "result severity.")
    outputs_group.add_argument('-m',
                               '--min-severity',
                               nargs=1,
                               choices=('INFO', 'NORMAL', 'MAJOR'),
                               metavar='ENUM',
                               help=MIN_SEVERITY_HELP)

    # The following are "coala" specific arguments
    if parser_type == 'coala':
        SHOW_BEARS_HELP = ("Display bears and its metadata with the sections "
                           "that they belong to")
        outputs_group.add_argument('-B',
                                   '--show-bears',
                                   const=True,
                                   action='store_const',
                                   help=SHOW_BEARS_HELP)

        outputs_group.add_argument('-l',
                                   '--filter-by-language',
                                   nargs='+',
                                   metavar='LANG',
                                   help="Filters the output of `--show-bears` "
                                        "by the given languages.")

        outputs_group.add_argument('-D',
                                   '--show-description',
                                   const=True,
                                   action='store_const',
                                   help="Shows bear descriptions for the "
                                        "`--show-bears` output.")
        outputs_group.add_argument('--show-details',
                                   const=True,
                                   action='store_const',
                                   help='Shows bear details for the '
                                        '`--show-bears` output, e.g '
                                        'parameters and supported languages.')

    # The following are "coala-json" specific arguments
    if parser_type == 'coala-json':
        TEXT_LOGS_HELP = ("Don't display logs as json, display them as we "
                          "normally do in the console.")
        outputs_group.add_argument('--text-logs',
                                   nargs='?',
                                   const=True,
                                   metavar='BOOL',
                                   help=TEXT_LOGS_HELP)

        OUTPUT_HELP = ('Write the logs as json to a file where filename is '
                       'specified as argument.')
        outputs_group.add_argument('-o',
                                   '--output',
                                   nargs=1,
                                   metavar='FILE',
                                   help=OUTPUT_HELP)

        outputs_group.add_argument('-r',
                                   '--relpath',
                                   nargs='?',
                                   const=True,
                                   help="Return relative paths for files")

    misc_group = arg_parser.add_argument_group('Miscellaneous')

    SETTINGS_HELP = 'Arbitrary settings in the form of section.key=value'
    misc_group.add_argument('-S',
                            '--settings',
                            nargs='+',
                            metavar='SETTING',
                            help=SETTINGS_HELP)

    misc_group.add_argument('-a',
                            '--apply-patches',
                            action='store_const',
                            dest='default_actions',
                            const='*: ApplyPatchAction',
                            help='Applies all patches automatically if '
                                 'possible.')

    misc_group.add_argument("-j",
                            "--jobs",
                            type=int,
                            help="Number of jobs to use in parallel.")

    NO_ORIG_HELP = ('Deactivate creation of .orig files and .orig backup '
                    'files before applying patches')
    misc_group.add_argument('-n',
                            '--no-orig',
                            const=True,
                            action='store_const',
                            help=NO_ORIG_HELP)

    try:  # pragma: no cover
        # Auto completion should be optional, because of somewhat complicated
        # setup.
        import argcomplete
        argcomplete.autocomplete(arg_parser)
    except ImportError:
        pass
    return arg_parser
Esempio n. 15
0
def default_arg_parser(formatter_class=None):
    """
    This function creates an ArgParser to parse command line arguments.

    :param formatter_class: Formatting the arg_parser output into a specific
                            form. For example: In the manpage format.
    """
    formatter_class = (CustomFormatter if formatter_class is None
                       else formatter_class)

    description = """
coala provides a common command-line interface for linting and fixing all your
code, regardless of the programming languages you use.

To find out what kind of analysis coala offers for the languages you use, visit
http://coala.io/languages, or run::

    $ coala --show-bears --filter-by-language C Python

To perform code analysis, simply specify the analysis routines (bears) and the
files you want it to run on, for example:

    spaceBear::

            $ coala --bears SpaceConsistencyBear --files **.py

coala can also automatically fix your code:

    spacePatchBear::

            $ coala --bears SpaceConsistencyBear --files **.py --apply-patches

To run coala without user interaction, run the `coala --non-interactive`,
`coala --json` and `coala --format` commands.
"""

    arg_parser = argparse.ArgumentParser(
        formatter_class=formatter_class,
        prog='coala',
        description=description,
        # Use our own help so that we can put it in the group we want
        add_help=False)

    arg_parser.add_argument('TARGETS',
                            nargs='*',
                            help='sections to be executed exclusively')

    info_group = arg_parser.add_argument_group('Info')

    info_group.add_argument('-h',
                            '--help',
                            action='help',
                            help='show this help message and exit')

    info_group.add_argument('-v',
                            '--version',
                            action='version',
                            version=Constants.VERSION)

    mode_group = arg_parser.add_argument_group('Mode')

    mode_group.add_argument(
        '-C', '--non-interactive', const=True, action='store_const',
        help='run coala in non interactive mode')

    mode_group.add_argument(
        '--ci', action='store_const', dest='non_interactive', const=True,
        help='continuous integration run, alias for `--non-interactive`')

    mode_group.add_argument(
        '--json', const=True, action='store_const',
        help='mode in which coala will display output as json')

    mode_group.add_argument(
        '--format', const=True, nargs='?', metavar='STR',
        help='output results with a custom format string, e.g. '
             '"Message: {message}"; possible placeholders: '
             'id, origin, file, line, end_line, column, end_column, '
             'severity, severity_str, message, message_base, '
             'message_arguments, affected_code, source_lines')

    config_group = arg_parser.add_argument_group('Configuration')

    config_group.add_argument(
        '-c', '--config', nargs=1, metavar='FILE',
        help='configuration file to be used, defaults to {}'.format(
            Constants.default_coafile))

    config_group.add_argument(
        '-F', '--find-config', action='store_const', const=True,
        help='find {} in ancestors of the working directory'.format(
            Constants.default_coafile))

    config_group.add_argument(
        '-I', '--no-config', const=True, action='store_const',
        help='run without using any config file')

    config_group.add_argument(
        '-s', '--save', nargs='?', const=True, metavar='FILE',
        help='save used arguments to a config file to a {}, the given path, '
             'or at the value of -c'.format(Constants.default_coafile))

    config_group.add_argument(
        '--disable-caching', const=True, action='store_const',
        help='run on all files even if unchanged')
    config_group.add_argument(
        '--flush-cache', const=True, action='store_const',
        help='rebuild the file cache')
    config_group.add_argument(
        '--no-autoapply-warn', const=True, action='store_const',
        help='turn off warning about patches not being auto applicable')

    inputs_group = arg_parser.add_argument_group('Inputs')

    inputs_group.add_argument(
        '-b', '--bears', nargs='+', metavar='NAME',
        help='names of bears to use').completer = (
            lambda *args, **kwargs: get_all_bears_names())  # pragma: no cover

    inputs_group.add_argument(
        '-f', '--files', nargs='+', metavar='FILE',
        help='files that should be checked')

    inputs_group.add_argument(
        '-i', '--ignore', nargs='+', metavar='FILE',
        help='files that should be ignored')

    inputs_group.add_argument(
        '--limit-files', nargs='+', metavar='FILE',
        help="filter the `--files` argument's matches further")

    inputs_group.add_argument(
        '-d', '--bear-dirs', nargs='+', metavar='DIR',
        help='additional directories which may contain bears')

    outputs_group = arg_parser.add_argument_group('Outputs')

    outputs_group.add_argument(
        '-V', '--verbose', action='store_const',
        dest='log_level', const='DEBUG',
        help='alias for `-L DEBUG`')

    outputs_group.add_argument(
        '-L', '--log-level', nargs=1,
        choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'], metavar='ENUM',
        help='set log output level to DEBUG/INFO/WARNING/ERROR, '
             'defaults to INFO')

    outputs_group.add_argument(
        '-m', '--min-severity', nargs=1,
        choices=('INFO', 'NORMAL', 'MAJOR'), metavar='ENUM',
        help='set minimal result severity to INFO/NORMAL/MAJOR')

    outputs_group.add_argument(
        '-N', '--no-color', const=True, action='store_const',
        help='display output without coloring (excluding logs)')

    outputs_group.add_argument(
        '-B', '--show-bears', const=True, action='store_const',
        help='list all bears')

    outputs_group.add_argument(
        '-l', '--filter-by-language', nargs='+', metavar='LANG',
        help='filters `--show-bears` by the given languages')

    outputs_group.add_argument(
        '-p', '--show-capabilities', nargs='+', metavar='LANG',
        help='show what coala can fix and detect for the given languages')

    outputs_group.add_argument(
        '-D', '--show-description', const=True, action='store_const',
        help='show bear descriptions for `--show-bears`')

    outputs_group.add_argument(
        '--show-details', const=True, action='store_const',
        help='show bear details for `--show-bears`')

    outputs_group.add_argument(
        '--log-json', const=True, action='store_const',
        help='output logs as json along with results'
             ' (must be called with --json)')

    outputs_group.add_argument(
        '-o', '--output', nargs=1, metavar='FILE',
        help='write results to the given file (must be called with --json)')

    outputs_group.add_argument(
        '-r', '--relpath', nargs='?', const=True,
        help='return relative paths for files (must be called with --json)')

    misc_group = arg_parser.add_argument_group('Miscellaneous')

    misc_group.add_argument(
        '-S', '--settings', nargs='+', metavar='SETTING',
        help='arbitrary settings in the form of section.key=value')

    misc_group.add_argument(
        '-a', '--apply-patches', action='store_const',
        dest='default_actions', const='*: ApplyPatchAction',
        help='apply all patches automatically if possible')

    misc_group.add_argument(
        '-j', '--jobs', type=int,
        help='number of jobs to use in parallel')

    misc_group.add_argument(
        '-n', '--no-orig', const=True, action='store_const',
        help="don't create .orig backup files before patching")

    try:  # pragma: no cover
        # Auto completion should be optional, because of somewhat complicated
        # setup.
        import argcomplete
        argcomplete.autocomplete(arg_parser)
    except ImportError:
        pass
    return arg_parser
Esempio n. 16
0
def default_arg_parser(formatter_class=None):
    """
    This function creates an ArgParser to parse command line arguments.

    :param formatter_class: Formatting the arg_parser output into a specific
                            form. For example: In the manpage format.
    """
    formatter_class = (CustomFormatter
                       if formatter_class is None else formatter_class)

    description = """
coala provides a common command-line interface for linting and fixing all your
code, regardless of the programming languages you use.

To find out what kind of analysis coala offers for the languages you use, visit
http://coala.io/languages, or run::

    $ coala --show-bears --filter-by-language C Python

To perform code analysis, simply specify the analysis routines (bears) and the
files you want it to run on, for example:

    spaceBear::

            $ coala --bears SpaceConsistencyBear --files **.py

coala can also automatically fix your code:

    spacePatchBear::

            $ coala --bears SpaceConsistencyBear --files **.py --apply-patches

To run coala without user interaction, run the `coala --non-interactive`,
`coala --json` and `coala --format` commands.
"""

    arg_parser = argparse.ArgumentParser(
        formatter_class=formatter_class,
        prog='coala',
        description=description,
        # Use our own help so that we can put it in the group we want
        add_help=False)

    arg_parser.add_argument('TARGETS',
                            nargs='*',
                            help='sections to be executed exclusively')

    info_group = arg_parser.add_argument_group('Info')

    info_group.add_argument('-h',
                            '--help',
                            action='help',
                            help='show this help message and exit')

    info_group.add_argument('-v',
                            '--version',
                            action='version',
                            version=Constants.VERSION)

    mode_group = arg_parser.add_argument_group('Mode')

    mode_group.add_argument('-C',
                            '--non-interactive',
                            const=True,
                            action='store_const',
                            help='run coala in non interactive mode')

    mode_group.add_argument(
        '--ci',
        action='store_const',
        dest='non_interactive',
        const=True,
        help='continuous integration run, alias for `--non-interactive`')

    mode_group.add_argument(
        '--json',
        const=True,
        action='store_const',
        help='mode in which coala will display output as json')

    mode_group.add_argument(
        '--format',
        const=True,
        nargs='?',
        metavar='STR',
        help='output results with a custom format string, e.g. '
        '"Message: {message}"; possible placeholders: '
        'id, origin, file, line, end_line, column, end_column, '
        'severity, severity_str, message, message_base, '
        'message_arguments, affected_code, source_lines')

    config_group = arg_parser.add_argument_group('Configuration')

    config_group.add_argument(
        '-c',
        '--config',
        nargs=1,
        metavar='FILE',
        help='configuration file to be used, defaults to {}'.format(
            Constants.default_coafile))

    config_group.add_argument(
        '-F',
        '--find-config',
        action='store_const',
        const=True,
        help='find {} in ancestors of the working directory'.format(
            Constants.default_coafile))

    config_group.add_argument('-I',
                              '--no-config',
                              const=True,
                              action='store_const',
                              help='run without using any config file')

    config_group.add_argument(
        '-s',
        '--save',
        nargs='?',
        const=True,
        metavar='FILE',
        help='save used arguments to a config file to a {}, the given path, '
        'or at the value of -c'.format(Constants.default_coafile))

    config_group.add_argument('--disable-caching',
                              const=True,
                              action='store_const',
                              help='run on all files even if unchanged')
    config_group.add_argument('--flush-cache',
                              const=True,
                              action='store_const',
                              help='rebuild the file cache')
    config_group.add_argument(
        '--no-autoapply-warn',
        const=True,
        action='store_const',
        help='turn off warning about patches not being auto applicable')

    inputs_group = arg_parser.add_argument_group('Inputs')

    inputs_group.add_argument(
        '-b',
        '--bears',
        nargs='+',
        metavar='NAME',
        help='names of bears to use').completer = (
            lambda *args, **kwargs: get_all_bears_names())  # pragma: no cover

    inputs_group.add_argument('-f',
                              '--files',
                              nargs='+',
                              metavar='FILE',
                              help='files that should be checked')

    inputs_group.add_argument('-i',
                              '--ignore',
                              nargs='+',
                              metavar='FILE',
                              help='files that should be ignored')

    inputs_group.add_argument(
        '--limit-files',
        nargs='+',
        metavar='FILE',
        help="filter the `--files` argument's matches further")

    inputs_group.add_argument(
        '-d',
        '--bear-dirs',
        nargs='+',
        metavar='DIR',
        help='additional directories which may contain bears')

    outputs_group = arg_parser.add_argument_group('Outputs')

    outputs_group.add_argument('-V',
                               '--verbose',
                               action='store_const',
                               dest='log_level',
                               const='DEBUG',
                               help='alias for `-L DEBUG`')

    outputs_group.add_argument(
        '-L',
        '--log-level',
        nargs=1,
        choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'],
        metavar='ENUM',
        help='set log output level to DEBUG/INFO/WARNING/ERROR, '
        'defaults to INFO')

    outputs_group.add_argument(
        '-m',
        '--min-severity',
        nargs=1,
        choices=('INFO', 'NORMAL', 'MAJOR'),
        metavar='ENUM',
        help='set minimal result severity to INFO/NORMAL/MAJOR')

    outputs_group.add_argument(
        '-N',
        '--no-color',
        const=True,
        action='store_const',
        help='display output without coloring (excluding logs)')

    outputs_group.add_argument('-B',
                               '--show-bears',
                               const=True,
                               action='store_const',
                               help='list all bears')

    outputs_group.add_argument(
        '-l',
        '--filter-by-language',
        nargs='+',
        metavar='LANG',
        help='filters `--show-bears` by the given languages')

    outputs_group.add_argument(
        '--filter-by',
        action='append',
        nargs='+',
        help='filters `--show-bears` by the filter given as argument. '
        'Available filters: {}'.format(FilterHelper.get_all_filters_str()))

    outputs_group.add_argument(
        '-p',
        '--show-capabilities',
        nargs='+',
        metavar='LANG',
        help='show what coala can fix and detect for the given languages')

    outputs_group.add_argument(
        '-D',
        '--show-description',
        const=True,
        action='store_const',
        help='show bear descriptions for `--show-bears`')

    outputs_group.add_argument('--show-details',
                               const=True,
                               action='store_const',
                               help='show bear details for `--show-bears`')

    outputs_group.add_argument('--log-json',
                               const=True,
                               action='store_const',
                               help='output logs as json along with results'
                               ' (must be called with --json)')

    outputs_group.add_argument(
        '-o',
        '--output',
        nargs=1,
        metavar='FILE',
        help='write results to the given file (must be called with --json)')

    outputs_group.add_argument(
        '-r',
        '--relpath',
        nargs='?',
        const=True,
        help='return relative paths for files (must be called with --json)')

    misc_group = arg_parser.add_argument_group('Miscellaneous')

    misc_group.add_argument(
        '-S',
        '--settings',
        nargs='+',
        metavar='SETTING',
        help='arbitrary settings in the form of section.key=value')

    misc_group.add_argument('-a',
                            '--apply-patches',
                            action='store_const',
                            dest='default_actions',
                            const='*: ApplyPatchAction',
                            help='apply all patches automatically if possible')

    misc_group.add_argument('-j',
                            '--jobs',
                            type=int,
                            help='number of jobs to use in parallel')

    misc_group.add_argument(
        '-n',
        '--no-orig',
        const=True,
        action='store_const',
        help="don't create .orig backup files before patching")

    misc_group.add_argument('-A',
                            '--single-action',
                            const=True,
                            action='store_const',
                            help='apply a single action for all results')

    misc_group.add_argument('--debug',
                            const=True,
                            action='store_const',
                            help='run coala in debug mode, starting ipdb, '
                            'which must be separately installed, '
                            'on unexpected internal exceptions '
                            '(implies --verbose)')

    try:
        # Auto completion should be optional, because of somewhat complicated
        # setup.
        import argcomplete
        argcomplete.autocomplete(arg_parser)
    except ImportError:  # pragma: no cover
        pass

    return arg_parser
Esempio n. 17
0
def default_arg_parser(formatter_class=None):
    """
    This function creates an ArgParser to parse command line arguments.

    :param formatter_class: Formatting the arg_parser output into a specific
                            form. For example: In the manpage format.
    """
    formatter_class = formatter_class or argparse.RawDescriptionHelpFormatter

    entry_point = sys.argv[0]
    for entry in ['coala-ci', 'coala-dbus', 'coala-format', 'coala-json',
                  'coala-delete-orig']:
        if entry_point.endswith(entry):
            parser_type = entry
            break
    else:
        parser_type = 'coala'

    arg_parser = argparse.ArgumentParser(
        formatter_class=formatter_class,
        prog="coala",
        description="coala is a simple COde AnaLysis Application. Its goal "
                    "is to make static code analysis easy and convenient "
                    "for all languages. coala uses bears, which are analysis "
                    "routines that can be combined arbitrarily.")

    arg_parser.add_argument('TARGETS',
                            nargs='*',
                            help="Sections to be executed exclusively.")
    arg_parser.add_argument('-c',
                            '--config',
                            nargs=1,
                            metavar='FILE',
                            help='Configuration file to be used, defaults to '
                                 + repr(Constants.default_coafile))
    FIND_CONFIG_HELP = ('Attempt to find config file by checking parent '
                        'directories of the current working directory. It is '
                        'assumed that the config file is named '
                        + repr(Constants.default_coafile) + '. This arg is '
                        'ignored if --config is also given')
    arg_parser.add_argument('-F',
                            '--find-config',
                            nargs='?',
                            const=True,
                            metavar='BOOL',
                            help=FIND_CONFIG_HELP)
    arg_parser.add_argument('-I',
                            '--no-config',
                            nargs='?',
                            const=True,
                            metavar='BOOL',
                            help="Run without using any config file")
    arg_parser.add_argument('-f',
                            '--files',
                            nargs='+',
                            metavar='FILE',
                            help='Files that should be checked')
    arg_parser.add_argument('-i',
                            '--ignore',
                            nargs='+',
                            metavar='FILE',
                            help='Files that should be ignored')
    arg_parser.add_argument('--limit-files',
                            nargs='+',
                            metavar='FILE',
                            help='Files that will be analyzed will be '
                                 'restricted to those in the globs listed '
                                 'in this argument as well the files setting')
    arg_parser.add_argument('-b',
                            '--bears',
                            nargs='+',
                            metavar='NAME',
                            help='Names of bears to use').completer =\
        ChoicesCompleter(get_all_bears_names())
    BEAR_DIRS_HELP = 'Additional directories where bears may lie'
    arg_parser.add_argument('-d',
                            '--bear-dirs',
                            nargs='+',
                            metavar='DIR',
                            help=BEAR_DIRS_HELP)
    LOG_LEVEL_HELP = ("Enum('ERROR','INFO','WARNING','DEBUG') to set level of "
                      "log output")
    arg_parser.add_argument('-L',
                            '--log-level',
                            nargs=1,
                            choices=['ERROR', 'INFO', 'WARNING', 'DEBUG'],
                            metavar='ENUM',
                            help=LOG_LEVEL_HELP)
    MIN_SEVERITY_HELP = ("Enum('INFO', 'NORMAL', 'MAJOR') to set the minimal "
                         "result severity.")
    arg_parser.add_argument('-m',
                            '--min-severity',
                            nargs=1,
                            choices=('INFO', 'NORMAL', 'MAJOR'),
                            metavar='ENUM',
                            help=MIN_SEVERITY_HELP)
    SETTINGS_HELP = 'Arbitrary settings in the form of section.key=value'
    arg_parser.add_argument('-S',
                            '--settings',
                            nargs='+',
                            metavar='SETTING',
                            help=SETTINGS_HELP)
    if parser_type == 'coala-json':
        arg_parser.add_argument('--text-logs',
                                nargs='?',
                                const=True,
                                metavar='BOOL',
                                help='Don\'t display logs as json, display '
                                     'them as we normally do in the console.')
        arg_parser.add_argument('-o',
                                '--output',
                                nargs='?',
                                const=True,
                                metavar='BOOL',
                                help='Write the logs as json to a file '
                                'where filename is specified as argument.')
    if parser_type == 'coala':
        SHOW_BEARS_HELP = ("Display bears and its metadata with the sections "
                           "that they belong to")
        arg_parser.add_argument('-B',
                                '--show-bears',
                                nargs='?',
                                const=True,
                                metavar='BOOL',
                                help=SHOW_BEARS_HELP)
        arg_parser.add_argument('-A',
                                '--show-all-bears',
                                nargs='?',
                                const=True,
                                metavar='BOOL',
                                help="Display all bears.")
        arg_parser.add_argument('-l',
                                '--show-language-bears',
                                nargs='+',
                                metavar='LANG',
                                help="Display all bears for the given "
                                "languages.")
    SAVE_HELP = ('Filename of file to be saved to, if provided with no '
                 'arguments, settings will be stored back to the file given '
                 'by -c')
    arg_parser.add_argument('-s',
                            '--save',
                            nargs='?',
                            const=True,
                            metavar='FILE',
                            help=SAVE_HELP)
    TAG_HELP = ('Tag results with a specific name. You can access the results'
                ' later with that tag.')
    arg_parser.add_argument('-t',
                            '--tag',
                            nargs='?',
                            const=True,
                            metavar='STRING',
                            help=TAG_HELP)

    DELETE_TAG_HELP = 'Delete pre-tagged results with tag name.'
    arg_parser.add_argument('-g',
                            '--dtag',
                            nargs='?',
                            const=True,
                            metavar='STRING',
                            help=DELETE_TAG_HELP)

    arg_parser.add_argument("-j",
                            "--jobs",
                            type=int,
                            help="Number of jobs to use in parallel.")

    arg_parser.add_argument('-v',
                            '--version',
                            action='version',
                            version=Constants.VERSION)

    arg_parser.add_argument('-n',
                            '--no-orig',
                            nargs='?',
                            const=True,
                            help="Deactivate creation of .orig files,"
                                 ".orig backup files before applying patches")
    arg_parser.add_argument('-r',
                            '--relpath',
                            nargs='?',
                            const=True,
                            help="return relative paths for files")

    try:  # pragma: no cover
        # Auto completion should be optional, because of somewhat complicated
        # setup.
        import argcomplete
        argcomplete.autocomplete(arg_parser)
    except ImportError:
        pass
    return arg_parser