Module: SrbcCommand

Included in:
SRBC
Defined in:
lib/srbc/srbc_command.rb

Instance Method Summary collapse

Instance Method Details

#run_file(name, args = "") ⇒ Object



75
76
77
78
# File 'lib/srbc/srbc_command.rb', line 75

def run_file(name, args="")
  #puts "RUNN: ruby #{name} #{args}"
  system "#{@executor} #{name} #{args}"
end

#run_program(name) ⇒ Object



68
69
70
71
72
73
# File 'lib/srbc/srbc_command.rb', line 68

def run_program(name)
  system "#{name}"
  if $?.pid == 0
    puts "#{name} not found"
  end
end

#srbc_command(command) ⇒ Object

method to execute command sterst with @



6
7
8
9
10
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/srbc/srbc_command.rb', line 6

def srbc_command(command)

  case command.downcase
    when 'e','exit'
      self.lunched = false
      puts 'Exiting Smart Ruby Console'

    when 'h','help'
      puts "Smart Ruby Console help SRBC #{SrbcVersion::VERSION}"
      File.open("#{@gem_root}/help", 'r') do |helpfile|
        while line=helpfile.gets
          puts line
        end
      end

    #hot change executor
    when /^#/
    @executor = command.gsub(' ','').gsub '#', ''
      @ext = @settings[@executor]
      if @ext.nil?
        puts "You use #{@executor} first time. Please add extension!"
        ext = gets.chomp
        set_settings @executor, ext
      end

    when 'l','list'
      puts "Current [#{@executor}]:"
      puts @ext
      @settings.each do |executor, extensions|
        unless executor == @executor
          puts "\n"
          puts "[#{executor}]"
          puts extensions
        end
      end

    when /^add/
      new_ext = command.gsub 'add ', ''

      set_settings @executor, new_ext
    when 'c','current'
      puts "\nCurrent executor: #{@executor}"

    when /^delete/
      executor_to_delete = command.gsub 'delete ', ''
      if @settings[executor_to_delete].nil?
        puts "Can't find #{executor_to_delete}"
      else
      if @executor == executor_to_delete
        @executor = 'ruby'
      end
      @settings.delete (executor_to_delete)
      save_settings
      puts "#{executor_to_delete} deleted"
      end

    else
      puts "Unknow SRBC command. Use @help for help"
  end

end