From 3dae85e141107111d455ca2de2f334e6f8bc5846 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 31 Mar 2016 01:41:31 -0500 Subject: [PATCH] Extend list, improve arg parsing for roster. --- README.md | 16 ++++++++-------- lib/kgrader/cli.rb | 37 ++++++++++++++++++++++++------------- lib/kgrader/util.rb | 7 ++++--- rakefile | 17 +++++++++-------- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index be6695d..846b88e 100644 --- a/README.md +++ b/README.md @@ -31,18 +31,18 @@ To show all known classes, semesters, and assignments: rake list -To load a roster (a newline-delimited list of student identifiers) for a -specific semester: +To load a roster (a newline-delimited list of student identifiers) for the +current semester of a particular course (e.g. "cs123"): - rake roster cs123 myroster.csv semester=sp16 + rake roster cs123 myroster.csv -To load a roster for the current semester: +You can also specify the semester: - rake roster cs123 myroster.csv + rake roster cs123 myroster.csv sp16 ### Grading -To grade a particular assignment (e.g., "mp1" for the "cs123" course): +To grade a particular assignment (e.g., "mp1" for "cs123"): rake grade cs123 mp1 @@ -88,5 +88,5 @@ repo has changed since the last run. To forcibly regrade: rake grade cs123 mp1 regrade=yes -You can combine these arguments in any meaningful way. `semester` is available -for `roster` and `commit`, and and `students` is available for `commit`. +You can combine these arguments in any meaningful way. `semester` and +`students` are also available options for `commit`. diff --git a/lib/kgrader/cli.rb b/lib/kgrader/cli.rb index b385e0c..9ab35e5 100644 --- a/lib/kgrader/cli.rb +++ b/lib/kgrader/cli.rb @@ -8,19 +8,15 @@ module KGrader @fs = Filesystem.new dir end - def list - @fs.courses.each do |name| - puts "course: #{name}" - course = Course.new(@fs, name) - - puts " rosters:" - course.rosters.each do |roster| - puts " - #{roster.semester} (#{roster.students.size} students)" - end - - puts " assignments:" - course.assignments.each do |assignment| - puts " - #{assignment}" + def list(course, semester) + if semester + puts Course.new(@fs, course).roster(semester).students + elsif course + list_course course, 0 + else + @fs.courses.each do |name| + puts "course: #{name}" + list_course name, 1 end end end @@ -58,6 +54,21 @@ module KGrader end private + def list_course(name, indent = 0) + course = Course.new(@fs, name) + pad = ' ' * indent + + puts "#{pad}rosters:" + course.rosters.each do |roster| + puts "#{pad} - #{roster.semester} (#{roster.students.size} students)" + end + + puts "#{pad}assignments:" + course.assignments.each do |assignment| + puts "#{pad} - #{assignment}" + end + end + def reset_jail FileUtils.rm_rf @fs.jail FileUtils.mkdir @fs.jail diff --git a/lib/kgrader/util.rb b/lib/kgrader/util.rb index 1f86683..0280377 100644 --- a/lib/kgrader/util.rb +++ b/lib/kgrader/util.rb @@ -1,7 +1,7 @@ require 'time' module KGrader - def self.parse_args(raw, num, keywords) + def self.parse_args(raw, range, keywords) args = [] options = {} @@ -27,8 +27,9 @@ module KGrader end end - raise ArgumentError, "too few arguments" if args.size < num - raise ArgumentError, "too many arguments" if args.size > num + raise ArgumentError, "too few arguments" if args.size < range.begin + raise ArgumentError, "too many arguments" if args.size > range.end + args[range.end - 1] = nil unless args.size == range.end return args, options end diff --git a/rakefile b/rakefile index dd4af74..dbb412b 100644 --- a/rakefile +++ b/rakefile @@ -12,7 +12,7 @@ end def parse_args(num, keywords = {}) args, options = KGrader::parse_args ARGV.drop(1), num, keywords - args.each { |arg| task arg.to_sym {} } + args.each { |arg| task arg.to_sym {} unless arg.nil? } args + [options] rescue KGrader::KGraderError => err die err @@ -22,8 +22,8 @@ task :default => :help do ; end task :help do puts %{usage: -- rake list -- rake roster [semester=<...>] +- rake list [] [] +- rake roster [] - rake grade [semester=<...>] [students=<...>] [due=<...>] [fetch=] [regrade=] - rake commit [semester=<...>] [students=<...>] @@ -32,23 +32,24 @@ task :help do end task :list do - run { |cli| cli.list } + course, semester = parse_args 0..2 + run { |cli| cli.list course, semester } end task :roster do - course, rosterfile, options = parse_args 2, { :semester => :string } - run { |cli| cli.roster course, options[:semester], rosterfile } + course, rosterfile, semester = parse_args 2..3 + run { |cli| cli.roster course, semester, rosterfile } end task :grade do - course, assignment, options = parse_args 2, + 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, + course, assignment, options = parse_args 2..2, { :semester => :string, :students => :array } run { |cli| cli.commit course, options[:semester], assignment, options } end