Class: MyScripts::CLI
- Inherits:
-
Object
- Object
- MyScripts::CLI
- Defined in:
- lib/my_scripts/cli.rb
Overview
This class encapsulates Command Line Interface for running scripts. It can be instantiated with stubbed stdin and stdout if you want to run tests on your scripts
Defined Under Namespace
Classes: ScriptNameError
Instance Attribute Summary collapse
-
#kernel ⇒ Object
Returns the value of attribute kernel.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Class Method Summary collapse
-
.run(script_name, argv, argf = ARGF) ⇒ Object
Instantiates new CLI(command line interface) and runs script with given name (token) and argv inside new CLI instance.
Instance Method Summary collapse
-
#initialize(stdin = $stdin, stdout = $stdout, kernel = Kernel) ⇒ CLI
constructor
Creates new command line interface.
-
#run(script_name, argv, argf = ARGF) ⇒ Object
Runs a script with given name (token) and argv inside this CLI instance.
Constructor Details
#initialize(stdin = $stdin, stdout = $stdout, kernel = Kernel) ⇒ CLI
Creates new command line interface
20 21 22 23 24 |
# File 'lib/my_scripts/cli.rb', line 20 def initialize( stdin=$stdin, stdout=$stdout, kernel = Kernel ) @stdin = stdin @stdout = stdout @kernel = kernel end |
Instance Attribute Details
#kernel ⇒ Object
Returns the value of attribute kernel.
11 12 13 |
# File 'lib/my_scripts/cli.rb', line 11 def kernel @kernel end |
#stdin ⇒ Object
Returns the value of attribute stdin.
11 12 13 |
# File 'lib/my_scripts/cli.rb', line 11 def stdin @stdin end |
#stdout ⇒ Object
Returns the value of attribute stdout.
11 12 13 |
# File 'lib/my_scripts/cli.rb', line 11 def stdout @stdout end |
Class Method Details
.run(script_name, argv, argf = ARGF) ⇒ Object
Instantiates new CLI(command line interface) and runs script with given name (token) and argv inside new CLI instance
15 16 17 |
# File 'lib/my_scripts/cli.rb', line 15 def self.run( script_name, argv, argf=ARGF ) new.run script_name, argv, argf end |
Instance Method Details
#run(script_name, argv, argf = ARGF) ⇒ Object
Runs a script with given name (token) and argv inside this CLI instance
27 28 29 30 31 32 |
# File 'lib/my_scripts/cli.rb', line 27 def run( script_name, argv, argf=ARGF ) script = script_class_name(script_name).to_class raise ScriptNameError.new("Script #{script_class_name(script_name)} not found") unless script script.new(script_name, self, argv, argf).run end |