def cmd_course_archive(course_code: str): """Move a course into archive folder.""" course_code = _validate_course_code(course_code) check_course_exists(course_code) course_helper.archive_course(course_code) click.echo(f'The course with code {course_code} is moved into archive.')
def _check_project_exists(course_code: str, project_id: str): """Check that the course with <course_code> exists, and it has a project with id <project_id>. If either is False, then display message and exit with status code 1. """ check_course_exists(course_code) if not project_helper.project_exists(course_code, project_id): click.echo(f'The project with id "{project_id} does not exist in "{course_code}".') sys.exit(1)
def cmd_template_create(template: str, course_code: Optional[str]): """Create a new template. If course_code is given, create template for that specific course. """ # TODO: add base template option _validate_template_name(template) if template_helper.template_exists(template, course_code): click.echo(f'Template with name "{template}" already exists.') sys.exit(1) if course_code is not None: check_course_exists(course_code) template_helper.create_template(template, course_code)
def cmd_course_remove(course_code: str): """Remove a course.""" course_code = _validate_course_code(course_code) check_course_exists(course_code) msg = ( f'Are you sure you want to remove "{course_code}"?\n' 'All of its contents will be permanently deleted and cannot be restored.\n' ) # Repeats prompt 2 times in case of error click.confirm(msg, abort=True) click.confirm(msg, abort=True) course_helper.remove_course(course_code) click.echo(f'"{course_code}" is removed from courses.')
def _get_todo_scope(course_code: Optional[str], project_id: Optional[str]) -> todo_helper.TodoScope: """Get the TodoScope given <course_code> and <project_id>. If any of the two are invalid, display a message and exit with status code 1. """ scope = None if course_code is not None: check_course_exists(course_code) scope = course_code if project_id is not None: check_project_exists(course_code, project_id) scope = (course_code, project_id) return scope
def cmd_project_add(course_code: str, template: Optional[str]): """Add a project to the course with given course code. User will be prompted with options. If template is given, will create the project with template. """ check_course_exists(course_code) # TODO: Should adjust based on template? project_id = repeat_prompt('Project id', _get_project_id_validator(course_code)) name = repeat_prompt('Name', _project_name_validator, default=project_id) due_date = repeat_prompt('Due date', repeat_prompt.date_validator) open_method = click.prompt('Open method', default='open .', type=str) # Create settings based on given options settings = ProjectSettings(name, project_id, due_date, open_method) # Create project project_helper.create_project(course_code, settings) click.echo(f'Project "{project_id}" created successfully!')
def cmd_template_delete(template: str, course_code: Optional[str]): """Delete an existing template. If course_code is given, delete the template from that course. """ _validate_template_name(template) if not template_helper.template_exists(template): click.echo(f'Template with name "{template}" does not exist.') sys.exit(1) if course_code is not None: check_course_exists(course_code) msg = (f'Are you sure you want to delete the template "{template}"?\n' 'All of its contents will be permanently deleted and cannot be restored.\n') click.confirm(msg, abort=True) click.confirm(msg, abort=True) template_helper.delete_template(template, course_code)