summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-05-10 14:23:16 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-05-10 14:23:16 -0500
commitf20d44565b32a0396be8e281a4ec723172df0655 (patch)
tree2ad29849c74ba5522ab2339e76bced55437976e0
parentdd0c50dbcea017a5d5483dc784df81e33b644c17 (diff)
downloadflake8-f20d44565b32a0396be8e281a4ec723172df0655.tar.gz
Ignore --help/-h until later as well
Explain why we remove --version, --help, and -h
-rw-r--r--flake8/main/cli.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/flake8/main/cli.py b/flake8/main/cli.py
index 6991fb0..ef9b328 100644
--- a/flake8/main/cli.py
+++ b/flake8/main/cli.py
@@ -212,10 +212,30 @@ class Application(object):
)
register_default_options(self.option_manager)
- # Set the verbosity of the program
+ # We haven't found or registered our plugins yet, so let's defer
+ # printing the version until we aggregate options from config files
+ # and the command-line. First, let's clone our arguments on the CLI,
+ # then we'll attempt to remove ``--version`` so that we can avoid
+ # triggering the "version" action in optparse. If it's not there, we
+ # do not need to worry and we can continue. If it is, we successfully
+ # defer printing the version until just a little bit later.
+ # Similarly we have to defer printing the help text until later.
args = sys.argv[:]
- args.remove('--version')
+ try:
+ args.remove('--version')
+ except ValueError:
+ pass
+ try:
+ args.remove('--help')
+ except ValueError:
+ pass
+ try:
+ args.remove('-h')
+ except ValueError:
+ pass
+
preliminary_opts, _ = self.option_manager.parse_args(args)
+ # Set the verbosity of the program
flake8.configure_logging(preliminary_opts.verbose,
preliminary_opts.output_file)