#!/usr/bin/env python

import sys
import os
import fileinput
from comment_filter import language
import comment_filter
import argparse
from comment_filter import _version


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--onlycode', help='filter out comments', action='store_true')
    parser.add_argument('--notokens', help='filter out comment tokens', action='store_true')
    parser.add_argument('--version', action='version', version=_version.__version__)
    parser.add_argument('path', help='path to file to parse')
    args = parser.parse_args()

    _, ext = os.path.splitext(args.path)
    lang = language.extension_to_lang_map.get(ext, language.c)
    input_stream = fileinput.input(args.path)
    keep_tokens = not args.notokens
    for line in comment_filter.parse_file(lang, input_stream, code_only=args.onlycode, keep_tokens=keep_tokens):
        sys.stdout.write(line)
