Class: Daigaku::Terminal::Solutions

Inherits:
Thor
  • Object
show all
Includes:
Output
Defined in:
lib/daigaku/terminal/solutions.rb

Instance Method Summary collapse

Instance Method Details

#open(course_name = '') ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/daigaku/terminal/solutions.rb', line 11

def open(course_name = '')
  begin
    path = File.join(Daigaku.config.solutions_path, course_name)

    unless Dir.exist?(path)
      text = [
        "The course directory \"#{File.basename(path)}\" is not available in",
        "\"#{File.dirname(path)}\".\n",
        'Hint:',
        'Run "daigaku scaffold" to create empty solution files for all courses.'
      ]
      say_warning text.join("\n")

      unless Loading::Courses.load(Daigaku.config.courses_path).empty?
        Terminal::Courses.new.list
      end

      return
    end

    if OS.windows?
      system "explorer '#{path}'"
    elsif OS.mac?
      system "open '#{path}'"
    elsif OS.linux?
      system "xdg-open '#{path}'"
    end
  rescue ConfigurationError => e
    say_warning e.message
  end
end