application: Return namespace and args from preliminary arg parsing

This is the initial step towards removing state from the `Application`
object during argument parsing and handling.  The goal is to remove
`Application.prelim_opts` and `Application.prelim_args`.
This commit is contained in:
Eric N. Vander Weele 2019-10-01 08:48:18 +02:00
parent 6bae5f7ef6
commit 6043e90855
2 changed files with 13 additions and 4 deletions

View file

@ -5,7 +5,7 @@ import argparse
import logging
import sys
import time
from typing import Dict, List, Optional, Set
from typing import Dict, List, Optional, Set, Tuple
import flake8
from flake8 import checker
@ -98,7 +98,7 @@ class Application(object):
self.parsed_diff = {} # type: Dict[str, Set[int]]
def parse_preliminary_options_and_args(self, argv):
# type: (List[str]) -> None
# type: (List[str]) -> Tuple[argparse.Namespace, List[str]]
"""Get preliminary options and args from CLI, pre-plugin-loading.
We need to know the values of a few standard options and args now, so
@ -112,6 +112,10 @@ class Application(object):
:param list argv:
Command-line arguments passed in directly.
:returns:
Populated namespace and list of remaining argument strings.
:rtype:
(argparse.Namespace, list)
"""
# We haven't found or registered our plugins yet, so let's defer
# printing the version until we aggregate options from config files
@ -139,6 +143,7 @@ class Application(object):
# parse_known_args includes unknown options as args
args = [a for a in args if not a.startswith("-")]
self.prelim_opts, self.prelim_args = opts, args
return opts, args
def exit(self):
# type: () -> None