# system
from io import IOBase, StringIO
import os


# 3rd party
import click

# internal
from days import DayFactory

# import logging
# logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)
# ch = logging.StreamHandler()
# logger.addHandler(ch)


@click.group(invoke_without_command=True)
@click.option('-d', '--day', required=True, type=click.IntRange(1, 31), metavar="<1..31>", help="Day you want to select.")
@click.option('-p', '--puzzle', required=True, type=click.IntRange(1, 2), metavar="<1|2>", help="Puzzle you want to run.")
@click.option('-i', '--input', required=True, type=click.Path(exists=True), help="Path to puzzle data.")
def cli(day: int, puzzle: int, input: str):
  filename = os.path.join(input, f"{day:02}_puzzle_{puzzle}.txt")
  if os.path.exists(filename):
    input_stream = open(filename, "r")
  else:
    input_stream = StringIO('')
  avocd = DayFactory(day, input_stream)

  try:
    print(avocd.run(puzzle))
  except NotImplementedError:
    print(f"Puzzle {puzzle} for day {day} not implemented.")


if __name__ == "__main__":
  # pylint: disable=no-value-for-parameter
  cli()

[((266, 306), 'click.group', 'click.group', ([], {'invoke_without_command': '(True)'}), '(invoke_without_command=True)\n', (277, 306), False, 'import click\n'), ((715, 767), 'os.path.join', 'os.path.join', (['input', 'f"""{day:02}_puzzle_{puzzle}.txt"""'], {}), "(input, f'{day:02}_puzzle_{puzzle}.txt')\n", (727, 767), False, 'import os\n'), ((773, 797), 'os.path.exists', 'os.path.exists', (['filename'], {}), '(filename)\n', (787, 797), False, 'import os\n'), ((888, 917), 'days.DayFactory', 'DayFactory', (['day', 'input_stream'], {}), '(day, input_stream)\n', (898, 917), False, 'from days import DayFactory\n'), ((865, 877), 'io.StringIO', 'StringIO', (['""""""'], {}), "('')\n", (873, 877), False, 'from io import IOBase, StringIO\n'), ((356, 377), 'click.IntRange', 'click.IntRange', (['(1)', '(31)'], {}), '(1, 31)\n', (370, 377), False, 'import click\n'), ((482, 502), 'click.IntRange', 'click.IntRange', (['(1)', '(2)'], {}), '(1, 2)\n', (496, 502), False, 'import click\n'), ((604, 627), 'click.Path', 'click.Path', ([], {'exists': '(True)'}), '(exists=True)\n', (614, 627), False, 'import click\n')]