Sha256: c5a0b13efd6f3f4c04a65e5b41ac3d1ff6d21d649253f3cc15f5ee32653cfd61
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
module MyScripts # 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 class CLI class ScriptNameError < NameError # :nodoc: def initialize(message=nil) message ? super(message) : super end end attr_accessor :stdout, :stdin, :kernel # Instantiates new CLI(command line interface) and runs script with given name (token) # and argv inside new CLI instance def self.run( script_name, argv ) new.run script_name, argv end # Creates new command line interface def initialize( stdin=$stdin, stdout=$stdout, kernel = Kernel ) @stdin = stdin @stdout = stdout @kernel = kernel end # Runs a script with given name (token) and argv inside this CLI instance def run( script_name, argv ) 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, argv, self).run end private def script_class_name(script_name) "MyScripts::#{script_name.to_s.camel_case}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
my_scripts-0.1.5 | lib/my_scripts/cli.rb |
my_scripts-0.1.3 | lib/my_scripts/cli.rb |