require_relative 'lib/kgrader' def die(error) abort "fatal: [#{error.class}] #{error}" end def run yield KGrader::CLI.new Rake.application.original_dir rescue KGrader::KGraderError => err die err end def parse_args(num, keywords = {}) args, options = KGrader::parse_args ARGV.drop(1), num, keywords args.each { |arg| task arg.to_sym {} unless arg.nil? } args + [options] rescue KGrader::KGraderError => err die err end task :default => :help do ; end task :help do puts %{usage: - rake list [] [] - rake roster [] - rake grade [semester=<...>] [students=<...>] [due=<...>] [fetch=] [regrade=] - rake commit [semester=<...>] [students=<...>] - rake clean - rake clobber} end task :list do course, semester = parse_args 0..2 run { |cli| cli.list course, semester } end task :roster do course, rosterfile, semester = parse_args 2..3 run { |cli| cli.roster course, semester, rosterfile } end task :grade do course, assignment, options = parse_args 2..2, { :semester => :string, :students => :array, :due => :time, :fetch => :bool, :regrade => :bool } run { |cli| cli.grade course, options[:semester], assignment, options } end task :commit do course, assignment, options = parse_args 2..2, { :semester => :string, :students => :array } run { |cli| cli.commit course, options[:semester], assignment, options } end task :clean do run { |cli| cli.clean } end task :clobber do run { |cli| cli.clobber } end