Class: Rbsh::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rbsh/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], config = {}) ⇒ CLI

Returns a new instance of CLI.



5
6
7
8
9
10
# File 'lib/rbsh/cli.rb', line 5

def initialize(args=[], config={})
  @config = config
  @args, @opts = parse(args)

  @shell = Rbsh::Shell.new
end

Class Method Details

.start(given_args = ARGV, config = {}) ⇒ Object



12
13
14
15
# File 'lib/rbsh/cli.rb', line 12

def self.start(given_args=ARGV, config={})
  instance = new(given_args, config)
  instance.run
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rbsh/cli.rb', line 17

def run
  if    @opts.has_key? :v
    puts Rbsh::VERSION
  elsif @opts.has_key? :e
    puts @shell.load_script!(@opts[:e]).run!.to_s
  else
    script_file = ARGV[0]
    script = File.open(script_file).read
    puts @shell.load_script!(script).run!.to_s
  end
end