#!python

import os
# from rudaux import initialize_course, schedule_grading
from rudaux import commands
from argparse import ArgumentParser

## Initialize argument parsing

parser = ArgumentParser(
  description='Manage your JupyterHub/Canvas/nbgrader course with Rudaux.'
)

## Parameters to specify on ANY subcommand

# Actually, I've opted just to specify these for each subparser, as it makes
# more sense to run:
# command subcommand -options

# than it does to run:
# command -options subcommand

# parser.add_argument(
#   '--dir',
#   dest='directory',
#   action='store',
#   default=os.getcwd(),
#   help="Specify the directory of your instructor repository containing configuration files."
# )

# parser.add_argument(
#   '--overwrite',
#   '-o',
#   dest='overwrite',
#   action='store_true',
#   default=False,
#   help='Suppress overwrite warnings and nuke any existing directories with abandon!'
# )

# Subcommands

subparsers = parser.add_subparsers(
  title='Subcommands', dest="subparser", help='Commands rudaux can process.'
)

## Initialize Course

init_parser = subparsers.add_parser('init', help='Initialize or update the course.')
init_parser.set_defaults(func=commands.initialize_course)

init_parser.add_argument(
  '--dir',
  dest='directory',
  action='store',
  default=os.getcwd(),
  help="The directory containing configuration files."
)

init_parser.add_argument(
  '--auto',
  '-a',
  dest='auto',
  action='store_true',
  default=False,
  help='Tell rudaux this is not an interactive shell, do not prompt!'
)

init_parser.add_argument(
  '--overwrite',
  '-o',
  dest='overwrite',
  action='store_true',
  default=False,
  help='Suppress overwrite warnings and nuke any existing directories with abandon!'
)

## Grade an assignment

grade_parser = subparsers.add_parser('grade', help='Grade an assignment.')
grade_parser.set_defaults(func=commands.grade)

# Grading options

grade_parser.add_argument(
  'assignment_name',
  metavar='name',
  action='store',
  type=str,
  help="Name of the assignment to grade."
)

grade_parser.add_argument(
  '--dir',
  dest='directory',
  action='store',
  default=os.getcwd(),
  help="The directory containing configuration files."
)

grade_parser.add_argument(
  '--auto',
  '-a',
  dest='auto',
  action='store_true',
  default=False,
  help='Tell rudaux this is not an interactive shell, do not prompt!'
)

grade_parser.add_argument(
  '--manual',
  '-m',
  dest='manual',
  action='store_true',
  default=False,
  help="Manual grading is necessary."
)

## Submit an assignment

# If manual grading is required, feedback will not be generated as part of
# autograding, and the grades will not be submitted. It is therefore necessary
# to run this command after manual feedback.

submit_parser = subparsers.add_parser(
  'submit', help='Generate feedback for and submit an assignment.'
)
submit_parser.set_defaults(func=commands.submit)

# Submission options

submit_parser.add_argument(
  'assignment_name',
  metavar='name',
  action='store',
  type=str,
  help="Name of the assignment to grade."
)

submit_parser.add_argument(
  '--no-feedback',
  '-n',
  dest='no_feedback',
  action='store_true',
  default=False,
  help="Skip feedback generation."
)

submit_parser.add_argument(
  '--dir',
  dest='directory',
  action='store',
  default=os.getcwd(),
  help="The directory containing configuration files."
)

# Parse the arguments!
args = parser.parse_args()

if args.subparser is not None:
  args.func(args)
else:
  # Otherwise, no subcommand was called, so raise help
  args = parser.parse_known_args(['-h'])