Class: Campa::Cli
- Inherits:
-
Object
- Object
- Campa::Cli
- Defined in:
- lib/campa/cli.rb
Overview
Implements the features available to the command ‘campa` shipped with this gem.
Instance Method Summary collapse
-
#execute(argv = nil, input: $stdin, out: $stdout) ⇒ Object
Execute some campa stuff depending on the options given in the command line.
-
#initialize(repl: nil, evaler: nil, context: nil, reader: Campa::Reader) ⇒ Cli
constructor
A new instance of Cli.
Constructor Details
#initialize(repl: nil, evaler: nil, context: nil, reader: Campa::Reader) ⇒ Cli
Returns a new instance of Cli.
13 14 15 16 17 18 19 |
# File 'lib/campa/cli.rb', line 13 def initialize(repl: nil, evaler: nil, context: nil, reader: Campa::Reader) @evaler = evaler || default_evaler @context = context || default_context @reader = reader @repl = repl || default_repl end |
Instance Method Details
#execute(argv = nil, input: $stdin, out: $stdout) ⇒ Object
Execute some campa stuff depending on the options given in the command line.
If no argument is given it will start a Repl session.
When first argument is an existent file then it will evaluated using Reader and Evaler.
If the CLI argument is anything else, this method tries to match it with OPTIONS and find the method to be executed. Current options for the CLI are:
campa test FILE1, FILE2 Uses Campa::Core::Test and Campa::Core::TestReport to evaluate the files given as options as Campa test code.
38 39 40 41 42 43 |
# File 'lib/campa/cli.rb', line 38 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 |