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 {} } args + [options] rescue KGrader::KGraderError => err die err end task :default => :help do ; end task :help do puts %{usage: - rake list - rake roster [semester=<...>] - rake grade [semester=<...>] [students=<...>] [due=<...>] [fetch=] [regrade=] - rake commit [semester=<...>] [students=<...>] - rake clean - rake clobber} end task :list do run { |cli| cli.list } end task :roster do course, rosterfile, options = parse_args 2, { :semester => :string } run { |cli| cli.roster course, options[:semester], rosterfile } end task :grade do course, assignment, options = parse_args 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, { :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