#!/usr/bin/python3

import sys
import os
from   argparse            import ArgumentParser
from   sudokumaker.sudoku  import Puzzle
from   sudokumaker.Version import VERSION

cmd    = ArgumentParser ()

cmd.add_argument \
    ( "file"
    , help    = "File name of sudoku file, default stdin"
    , nargs   = '?'
    )
cmd.add_argument \
    ( "-a", "--author"
    , dest    = "author"
    , help    = "Change default author info"
    )
cmd.add_argument \
    ( "-c", "--colorconstrained"
    , dest    = "colorconstrained"
    , help    = "Add color constraint"
    , action  = "store_true"
    )
cmd.add_argument \
    ( "-d", "--diagonal"
    , dest    = "diagonal"
    , help    = "Add diagonality coloring"
    , action  = "store_true"
    )
cmd.add_argument \
    ( "-k", "--kikagaku"
    , dest    = "kikagaku"
    , help    = "Kikagaku with color areas, read additional color defs"
    , action  = "store_true"
    )
cmd.add_argument \
    ( "-t", "--title"
    , dest    = "title"
    , help    = "Change default title info (defaults to given filename)"
    , default = ''
    )
cmd.add_argument \
    ( "-v", "--version"
    , help    = "Display version"
    , action  = "version"
    , version = "%%(prog)s %s" % VERSION
    )
args = cmd.parse_args ()
file = sys.stdin
name = ''
if args.file :
    file = open (args.file)
    name = args.file
if args.title :
    name = args.title

x = Puzzle  \
    ( diagonal         = args.diagonal
    , colorconstrained = args.colorconstrained
    , kikagaku         = args.kikagaku
    )
x.from_file (file)
x.as_tex    (title = name, author = args.author)

