Class: EC2Mini::CLI
- Inherits:
-
Object
- Object
- EC2Mini::CLI
- Defined in:
- lib/ec2-mini/cli.rb
Instance Method Summary collapse
-
#initialize(options = nil, config_file = nil) ⇒ CLI
constructor
A new instance of CLI.
- #start(role = nil, command = nil) ⇒ Object
Constructor Details
#initialize(options = nil, config_file = nil) ⇒ CLI
Returns a new instance of CLI.
7 8 9 10 11 12 13 |
# File 'lib/ec2-mini/cli.rb', line 7 def initialize( = nil, config_file = nil) @options = || load_config_file(config_file) ['access_key_id', 'secret_access_key', 'region'].each do |attribute| error "Not set #{attribute}." unless @options[attribute] end end |
Instance Method Details
#start(role = nil, command = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ec2-mini/cli.rb', line 15 def start(role = nil, command = nil) role_regex = /^[\w\-]+$/ command_regex = /^([+-][0-9]+)|backup|count$/ error "Not set role." if !(role =~ role_regex) && !(ARGV[0] =~ role_regex) error "Not set command." if !(command =~ command_regex) && !(ARGV[1] =~ command_regex) role = role || ARGV[0] command = command || ARGV[1] case command when /^\+[0-9]+/ number = command.scan(/([0-9]+$)/)[0][0].to_i up(role, number) when /^\-[0-9]+/ number = command.scan(/([0-9]+$)/)[0][0].to_i down(role, number) when 'backup' backup(role) when 'count' count(role) else error 'Not command' end end |