class Bixby::App::Commands::Run

Public Class Methods

options() click to toggle source
# File lib/bixby-client/app/commands/run.rb, line 61
def self.options
  nil
end

Public Instance Methods

run(global_options, argv) click to toggle source
# 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: bixby 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_env() click to toggle source

Setup the ENV for exec

# 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