#! /usr/bin/env python2
import subprocess
import os
import argparse
import sys

BINARY = "yapf"
DIR = os.path.dirname(os.path.realpath(__file__))
STYLE = DIR + "/.style.yapf"


def format(diff, style):
  command = [
      BINARY, '--exclude', 'test/core/program/riscv-tests', '-r', '-p',
      '--style', style, '-d' if diff else '-i', "."
  ]
  return subprocess.call(command, cwd=DIR)


def main():
  parser = argparse.ArgumentParser(description='Format source code')
  parser.add_argument('-d', '--diff', action='store_true')
  args = parser.parse_args()
  sys.exit(format(args.diff, STYLE))


if __name__ == '__main__':
  main()
