#!/usr/bin/python

""" tabview -- View a tab-delimited file in a spreadsheet-like display.
  Scott Hansen <firecat four one five three at gmail dot com>
  Based on code contributed by A.M. Kuchling <amk at amk dot ca>

  Usage:
      From command line:  tabview <filename>
      From python command line to view an object:
          import tabview.tabview as t
          a = [["a","b","c"], ["d","e","f"]]
          t.view(a)
      From python command line to view a file:
          import tabview.tabview as t
          t.view(fn=<filename>[, enc=<encoding>])

"""
import argparse
from tabview.tabview import readme, view


def arg_parse():
    """Parse filename and show help. Assumes README is in the same
    directory as tabview.py

    """
    parser = argparse.ArgumentParser(formatter_class=
                                     argparse.RawDescriptionHelpFormatter,
                                     description="".join(readme()))
    parser.add_argument('filename')
    parser.add_argument('--encoding', '-e', help="Encoding, if required.  "
                        "If the file is UTF-8, Latin-1(iso8859-1) or a few "
                        "other common encodings, it should be detected "
                        "automatically. If not, you can pass "
                        "'CP720', or 'iso8859-2', for example.")
    return parser.parse_args()

if __name__ == '__main__':
    args = arg_parse()
    view(fn=args.filename, enc=args.encoding)
