'xb format' helper.

This commit is contained in:
Ben Vanik
2015-02-21 14:45:23 -08:00
parent 0f1e870d99
commit 4a211a4195
6 changed files with 706 additions and 0 deletions

View File

@@ -139,6 +139,7 @@ def discover_commands():
'test': TestCommand(),
'clean': CleanCommand(),
'nuke': NukeCommand(),
'format': FormatCommand(),
}
return commands
@@ -523,5 +524,38 @@ class NukeCommand(Command):
return 0
class FormatCommand(Command):
"""'format' command."""
def __init__(self, *args, **kwargs):
super(FormatCommand, self).__init__(
name='format',
help_short='Reformats staged code with clang-format.',
*args, **kwargs)
def execute(self, args, cwd):
print('Formatting staged code...')
print('')
binary = 'clang-format'
win32_binary = 'C:\\Program Files (x86)\\LLVM\\bin\\clang-format.exe'
if os.path.exists(win32_binary):
binary = win32_binary
if not has_bin(binary):
print 'ERROR: clang-format is not on PATH'
print 'LLVM is available from http://llvm.org/releases/download.html'
print 'See docs/style_guide.md for instructions on how to get it'
return 1
shell_call(' '.join([
'python third_party/clang-format/git-clang-format',
'--binary="%s"' % (binary),
'--commit=HEAD',
]))
return 0
if __name__ == '__main__':
main()