Bug 965120 - Add --show option to mach clang-format; r=gps
authorAnthony Jones <ajones@mozilla.com>
Thu, 30 Jan 2014 14:27:44 +1300
changeset 181932 d44de38ad97f2aaeb289ca3d90cd956845d39c4c
parent 181931 f6395f80b24fa7235fbfbf64f13d67339e74518a
child 181933 4a77a99c84d52788958b2647d82b8bd8bc010cdb
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs965120
milestone29.0a1
Bug 965120 - Add --show option to mach clang-format; r=gps
tools/mach_commands.py
--- a/tools/mach_commands.py
+++ b/tools/mach_commands.py
@@ -313,23 +313,21 @@ class ReviewboardToolsProvider(MachComma
 
         # main() doesn't accept arguments and instead reads from sys.argv. So,
         # we fake it out.
         sys.argv = ['rbt'] + args
         return main()
 
 @CommandProvider
 class FormatProvider(MachCommandBase):
-    @Command('clang-format', category='devenv', allow_all_args=True,
+    @Command('clang-format', category='misc',
         description='Run clang-format on current changes')
-    @CommandArgument('args', nargs='...', help='Arguments to clang-format tool')
-    def clang_format(self, args):
-        if not args:
-            args = ['help']
-
+    @CommandArgument('--show', '-s', action = 'store_true',
+        help = 'Show diff output on instead of applying changes')
+    def clang_format(self, show=False):
         plat = platform.system()
         fmt = plat.lower() + "/clang-format-3.5"
         fmt_diff = "clang-format-diff-3.5"
 
         # We are currently using a modified verion of clang-format hosted on people.mozilla.org.
         # This is a temporary work around until we upstream the necessary changes and we can use
         # a system version of clang-format. See bug 961541.
         if plat == "Windows":
@@ -353,17 +351,20 @@ class FormatProvider(MachCommandBase):
 
         except urllib2.HTTPError as e:
             print("HTTP error {0}: {1}".format(e.code, e.reason))
             return 1
 
         from subprocess import Popen, PIPE
         p1 = Popen(["hg", "diff", "-U0", "-r", "tip^", "--include", "glob:**.c", "--include", "glob:**.cpp",
                    "--include", "glob:**.h", "--exclude", "listfile:.clang-format-ignore"], stdout=PIPE)
-        p2 = Popen([sys.executable, clang_format_diff, "-i", "-p1", "-style=Mozilla"], stdin=p1.stdout)
+        args = [sys.executable, clang_format_diff, "-p1", "-style=Mozilla"]
+        if not show:
+           args.append("-i")
+        p2 = Popen(args, stdin=p1.stdout)
         return p2.communicate()[0]
 
     def locate_or_fetch(self, root):
         target = os.path.join(self._mach_context.state_dir, os.path.basename(root))
         if not os.path.exists(target):
             site = "https://people.mozilla.org/~ajones/clang-format/"
             if self.prompt and raw_input("Download clang-format executables from {0} (yN)? ".format(site)).lower() != 'y':
                 print("Download aborted.")