Class: Bixby::App::Commands::Run

Inherits:
Bixby::App::Command show all
Defined in:
lib/bixby-client/app/commands/run.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bixby::App::Command

command_name, desc, match

Class Method Details

.optionsObject



61
62
63
# File 'lib/bixby-client/app/commands/run.rb', line 61

def self.options
  nil
end

Instance Method Details

#run(global_options, argv) ⇒ Object



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
# File 'lib/bixby-client/app/commands/run.rb', line 13

def run(global_options, argv)

  str = argv.shift
  scripts = FileFinder.new(Bixby.repo).find_script(str)

  if scripts.nil? then
    $stderr.puts "Error: missing input"
    $stderr.puts "usage: #{$0} run <script> [args ...]"
    return exit 1

  elsif scripts.kind_of?(Array)

    if scripts.size > 1 then
      $stderr.puts "Found #{scripts.size} scripts matching '#{str}'. Please be more explicit"
      scripts.each do |s|
        puts " * #{s}"
      end
      return 1

    elsif scripts.empty? then
      $stderr.puts "No scripts matched '#{str}'. Try again"
      return 1
    end

    # only one match
    scripts = scripts.shift
  end

  setup_env()
  exec(scripts, *argv)
end

#setup_envObject

Setup the ENV for exec



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bixby-client/app/commands/run.rb', line 46

def setup_env
  # use the correct ruby bin
  path = ENV["PATH"].dup
  ruby_dir = RbConfig::CONFIG['bindir']
  if !path.include? ruby_dir then
    ENV["PATH"] = "#{ruby_dir}:#{path}"
  end

  # stick ourselves in RUBYLIB to speedup exec time
  ENV["RUBYLIB"] = File.expand_path("../../../..", __FILE__)

  # load helper script
  ENV["RUBYOPT"] = '-rbixby-client/script'
end