def main(argv=None):
  """Validate text parsed with FSM or validate an FSM via command line."""

  if argv is None:
    argv = sys.argv

  try:
    opts, args = getopt.getopt(argv[1:], 'h', ['help'])
  except getopt.error, msg:
    raise Usage(msg)

  for opt, _ in opts:
    if opt in ('-h', '--help'):
      print __doc__
      print help_msg
      return 0

  if not args or len(args) > 4:
    raise Usage('Invalid arguments.')

  # If we have an argument, parse content of file and display as a template.
  # Template displayed will match input template, minus any comment lines.
  template = open(args[0], 'r')
  fsm = TextFSM(template)
  print 'FSM Template:\n%s\n' % fsm

  if len(args) > 1:
    # Second argument is file with example cli input.
    # Prints parsed tabular result.
    cli_input = open(args[1], 'r').read()
    table = fsm.ParseText(cli_input)
    print 'FSM Table:'
    result = str(fsm.header) + '\n'
    for line in table:
      result += str(line) + '\n'
    print result,

  if len(args) > 2:
    # Compare tabular result with data in third file argument.
    # Exit value indicates if processed data matched expected result.
    ref_table = open(args[2], 'r').read()
    if ref_table != result:
      print 'Data mis-match!'
      return 1
    else:
      print 'Data match!'
dataset/ETHPy150Open google/textfsm/textfsm.py/main/original