Sha256: fcd6025fa9228e2d726b0d39aad647a699f943a38e4ea6f38e5de9e70db410de

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Belajar
  module Terminal

    require 'os'
    require_relative 'output'

    class Solutions < Thor
      include Terminal::Output

      desc 'solutions open [COURSE NAME]', 'Open the solutions folder of a course in a GUI window'
      def open(course_name = '')
        begin
          path = File.join(Belajar.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 "belajar scaffold" to create empty solution files for all courses.'
            ]
            say_warning text.join("\n")

            unless Loading::Courses.load(Belajar.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

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
belajar-0.1.1 lib/belajar/terminal/solutions.rb