Class: Campa::Cli

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

Instance Method Summary collapse

Constructor Details

#initialize(repl: nil, evaler: nil, context: nil, reader: nil) ⇒ Cli

Returns a new instance of Cli.



3
4
5
6
7
8
9
# File 'lib/campa/cli.rb', line 3

def initialize(repl: nil, evaler: nil, context: nil, reader: nil)
  @evaler = evaler || default_evaler
  @context = context || default_context
  @reader = reader || default_reader

  @repl = repl || default_repl
end

Instance Method Details

#execute(argv = nil, input: $stdin, out: $stdout) ⇒ Object



11
12
13
14
15
16
# File 'lib/campa/cli.rb', line 11

def execute(argv = nil, input: $stdin, out: $stdout)
  return repl.run(input, out) if argv.nil? || argv.empty?
  return evaluate(argv[0], input, out) if File.file?(argv[0])

  execute_option(argv[0].to_sym, argv[1..], input, out)
end