diff options
| author | Eric N. Vander Weele <ericvw@gmail.com> | 2019-10-25 15:01:30 -0400 |
|---|---|---|
| committer | Eric N. Vander Weele <ericvw@gmail.com> | 2019-10-25 17:07:43 -0400 |
| commit | a90200353edb3d605e16e9ea852fe33f22f8d7a6 (patch) | |
| tree | f09524ab23f3ee38f457e4d75dfc7c3ebae6fa5f /src/flake8 | |
| parent | 1d7558f7da77d67272352d6ab8ca8a476cf80411 (diff) | |
| download | flake8-a90200353edb3d605e16e9ea852fe33f22f8d7a6.tar.gz | |
application: Register preliminary options on a separate argument parser
We introduce a new `ArgumentParser` for registering the preliminary
options to be inherited by the `Application.option_manager`. The next
step will be to use the `Application.prelim_arg_parser` for parsing and
handling preliminary options and arguments.
Note that we prevent the preliminary parser from handling `-h/--help`
and defer to that to the primary parser.
Diffstat (limited to 'src/flake8')
| -rw-r--r-- | src/flake8/main/application.py | 9 | ||||
| -rw-r--r-- | src/flake8/main/options.py | 16 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 5037293..e183351 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -45,12 +45,17 @@ class Application(object): self.program = program #: The version of the program being run self.version = version + #: The prelimary argument parser for handling options required for + #: obtaining and parsing the configuration file. + self.prelim_arg_parser = argparse.ArgumentParser(add_help=False) + options.register_preliminary_options(self.prelim_arg_parser) #: The instance of :class:`flake8.options.manager.OptionManager` used #: to parse and handle the options and arguments passed by the user self.option_manager = manager.OptionManager( - prog="flake8", version=flake8.__version__ + prog="flake8", + version=flake8.__version__, + parents=[self.prelim_arg_parser], ) - options.register_preliminary_options(self.option_manager) options.register_default_options(self.option_manager) #: The instance of :class:`flake8.options.config.ConfigFileFinder` self.config_finder = None # type: config.ConfigFileFinder diff --git a/src/flake8/main/options.py b/src/flake8/main/options.py index ad37660..ba1f1c2 100644 --- a/src/flake8/main/options.py +++ b/src/flake8/main/options.py @@ -1,4 +1,5 @@ """Contains the logic for all of the default options for Flake8.""" +import argparse import functools from flake8 import defaults @@ -6,7 +7,8 @@ from flake8.main import debug from flake8.main import vcs -def register_preliminary_options(option_manager): +def register_preliminary_options(parser): + # type: (argparse.ArgumentParser) -> None """Register the preliminary options on our OptionManager. The preliminary options include: @@ -17,9 +19,9 @@ def register_preliminary_options(option_manager): - ``--config`` - ``--isolated`` """ - add_option = option_manager.add_option + add_argument = parser.add_argument - add_option( + add_argument( "-v", "--verbose", default=0, @@ -29,13 +31,13 @@ def register_preliminary_options(option_manager): "time it is repeated.", ) - add_option( + add_argument( "--output-file", default=None, help="Redirect report to a file." ) # Config file options - add_option( + add_argument( "--append-config", action="append", help="Provide extra config files to parse in addition to the files " @@ -44,7 +46,7 @@ def register_preliminary_options(option_manager): "provide the same option.", ) - add_option( + add_argument( "--config", default=None, help="Path to the config file that will be the authoritative config " @@ -52,7 +54,7 @@ def register_preliminary_options(option_manager): "configuration files.", ) - add_option( + add_argument( "--isolated", default=False, action="store_true", |
