Class: SRS::CLI::Schedule
- Inherits:
-
Object
- Object
- SRS::CLI::Schedule
- Defined in:
- lib/srs/cli/schedule.rb
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize ⇒ Schedule
constructor
A new instance of Schedule.
- #run!(arguments) ⇒ Object
Constructor Details
#initialize ⇒ Schedule
Returns a new instance of Schedule.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/srs/cli/schedule.rb', line 6 def initialize @options = {} @opts = OptionParser.new do |o| o. = <<-EOF.gsub /^\s+/, "" srs schedule [options] <exercise> Schedules an exercise. EOF o.on('-s', '--scheduler SCHEDULER_NAME', 'Specifies which scheduler to use') do |s| @options[:scheduler] = s end end end |
Instance Method Details
#help ⇒ Object
63 64 65 |
# File 'lib/srs/cli/schedule.rb', line 63 def help() puts @opts end |
#run!(arguments) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/srs/cli/schedule.rb', line 21 def run!(arguments) if not SRS::Workspace.initialised? then puts "Current directory is not an SRS Workspace" return 3 end begin @opts.parse!(arguments) @options[:exercise] = arguments.shift() rescue OptionParser::InvalidOption => e @options[:invalid_argument] = e. end if @options[:exercise] == nil then help() return 4 end if @options[:scheduler] == nil then puts "No scheduler specified." return 5 end t = Time.now filename = "schedule/pending/#{t.strftime("%Y%m%d%H%M%S.%L")}" if File.exists?(filename) then puts "Cannot schedule two items within a millisecond. Try again." return 6 end FileUtils::mkdir_p("schedule/pending") File.open(filename, 'w') do |f| f.puts "Exercise: #{@options[:exercise]}" f.puts "Scheduler: #{@options[:scheduler]}" end puts filename return 0 end |