#!/usr/bin/env python
"""
Small script to pretty print the delimited fields of the first line of a file.
"""
import optparse
import fileinput


def print_header(file="-", delim="\t"):
    """
    Numbers and prints the fields of the first line in the file.
    @param file  the file to read from.  Defaults to stdin
    @param delim the field separator.  Defaults to tab
    @return nothing (results are printed to stdout)
    """
    ln = fileinput.input(file).readline().rstrip("\n")
    field_num = 1
    for field in ln.split(delim):
        print("%d:\t%s" % (field_num, field))
        field_num += 1


def parse_arguments():
    p = optparse.OptionParser()
    p.add_option("-d", "--delimiter", dest="delim",
                 help=r"use DELIMITER as field separator (instead of \t)",
                 default="\t")
    p.add_option("-f", "--file", dest="file",
                 help="read input from FILENAME (instead of stdin)",
                 default="-")
    (opts, args) = p.parse_args()
    return opts


def main():
    opts = parse_arguments()
    print_header(opts.file, opts.delim)


if __name__ == '__main__':
    main()
