#!/usr/bin/env python3

import sys
import argparse
import logging
from tokenize_output import __version__
from tokenize_output.tokenize_output import tokenize_output_sorted

if __name__ == '__main__':
    argp = argparse.ArgumentParser(description="Tokenize output.")
    argp.add_argument('-p', '--pipe', action='store_true', help="Read from pipe.")
    argp.add_argument('-v', '--verbose', action='store_true', help="Verbose mode.")
    argp.add_argument('--version', '-V', action='version', version=f"tokenize-output/{__version__}")
    args = argp.parse_args()

    if args.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    if args.pipe:
        stdin = '\n'.join(sys.stdin.readlines())
    else:
        argp.print_help()
        sys.exit()

    tokens = tokenize_output_sorted(stdin.strip())
    for t in tokens:
        print(t)
