Bug 1258341 - [mozlint] Add ability to forward miscellaneous command line arguments to the underlying linter, r?smacleod draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 25 Aug 2016 09:52:50 -0400
changeset 407661 f34811f5e3f54302644f9a0a93d447bface9c34b
parent 407496 b18c8bcdc116eef8799880b7c50317bf54218474
child 407662 5968b4a93d00aba2369a65331e3c0f97955b9e94
push id28003
push userahalberstadt@mozilla.com
push dateTue, 30 Aug 2016 18:31:07 +0000
reviewerssmacleod
bugs1258341
milestone51.0a1
Bug 1258341 - [mozlint] Add ability to forward miscellaneous command line arguments to the underlying linter, r?smacleod This is mostly to maintain backwards compatibility with the |mach eslint| command. But it's also going to be used in automation. The 'mozlint-eslint' task will need to pass in --quiet to eslint. Maybe in the future we should remove this ability and only allow well-defined arguments in mozlint. But for now it's convenient and allows us to land the eslint->mozlint patch series quicker. MozReview-Commit-ID: KYhC6SEySC3
python/mozlint/mozlint/cli.py
--- a/python/mozlint/mozlint/cli.py
+++ b/python/mozlint/mozlint/cli.py
@@ -1,17 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import print_function, unicode_literals
 
 import os
 import sys
-from argparse import ArgumentParser
+from argparse import ArgumentParser, REMAINDER
 
 
 SEARCH_PATHS = []
 
 
 class MozlintParser(ArgumentParser):
     arguments = [
         [['paths'],
@@ -47,24 +47,35 @@ class MozlintParser(ArgumentParser):
                   "mercurial or git."
           }],
         [['-w', '--workdir'],
          {'default': False,
           'action': 'store_true',
           'help': "Lint files touched by changes in the working directory "
                   "(i.e haven't been committed yet). Works with mercurial or git.",
           }],
+        [['extra_args'],
+         {'nargs': REMAINDER,
+          'help': "Extra arguments that will be forwarded to the underlying linter.",
+          }],
     ]
 
     def __init__(self, **kwargs):
         ArgumentParser.__init__(self, usage=self.__doc__, **kwargs)
 
         for cli, args in self.arguments:
             self.add_argument(*cli, **args)
 
+    def parse_known_args(self, *args, **kwargs):
+        # This is here so the eslint mach command doesn't lose 'extra_args'
+        # when using mach's dispatch functionality.
+        args, extra = ArgumentParser.parse_known_args(self, *args, **kwargs)
+        args.extra_args = extra
+        return args, extra
+
 
 def find_linters(linters=None):
     lints = []
     for search_path in SEARCH_PATHS:
         if not os.path.isdir(search_path):
             continue
 
         files = os.listdir(search_path)