Permalink
Browse files

moved options parser into the class that was not being used before

  • Loading branch information...
1 parent 5c43924 commit 2e3b1bfee7bc50f8cb13efc037ffde8d908ec586 @wbailey committed May 27, 2012
Showing with 28 additions and 48 deletions.
  1. +1 −29 bin/claws
  2. +22 −10 lib/claws/options.rb
  3. BIN pkg/claws-1.1.0.gem
  4. +5 −9 spec/options_spec.rb
View
@@ -4,35 +4,7 @@ require 'optparse'
require 'ostruct'
require 'yaml'
-options = OpenStruct.new(
- {
- :config_file => nil,
- :connect => true,
- :initialize => false,
- :version => false,
- :selection => nil,
- }
-)
-
-OptionParser.new do |opts|
- opts.banner = 'Usage: claws [options]'
-
- opts.on('-s', '--status-only', 'Display host status only and exit') do
- options.connect = false
- end
-
- opts.on('-c', '--choice N', Float, 'Enter the number of the host to automatically connect to') do |n|
- options.selection = n.to_i
- end
-
- opts.on('-i', '--init', 'Install the default configuration file for the application') do
- options.initialize = true
- end
-
- opts.on('-v', '--version', 'Display the version number and exit') do
- options.version = true
- end
-end.parse!
+options = Claws::Options.parse
Claws::Command::Initialize.exec if options.initialize
View
@@ -5,31 +5,43 @@ class Options
def self.parse
options = OpenStruct.new(
{
+ :config_file => nil,
:connect => true,
+ :initialize => false,
+ :version => false,
+ :selection => nil,
:source => 'ec2',
- :choice => nil,
}
)
OptionParser.new do |opts|
- opts.banner = "Usage: script/aws [options] [environment] [role]"
+ opts.banner = 'Usage: claws [options]'
- opts.on('-d', '--display-only', 'display host information only and exit') do
+ opts.on('-d', '--display-only', 'Display host status only and exit') do
options.connect = false
end
- opts.on('-c', '--choice N', Float, 'enter the identity number of the host to automatically connect to') do |n|
- options.choice = n.to_i
+ opts.on('-c', '--choice N', Float, 'Enter the number of the host to automatically connect to') do |n|
+ options.selection = n.to_i
end
- opts.on('-s', '--source', 'define the AWS source - default is ec2') do
- options.source = 'elb'
- options.connect = false
+ opts.on('-i', '--init', 'Install the default configuration file for the application') do
+ options.initialize = true
+ end
+
+ opts.on('-s', '--source S', String, 'define the AWS source - default is ec2') do |source|
+ options.source = source
+ end
+
+ opts.on('-v', '--version', 'Display the version number and exit') do
+ options.version = true
end
end.parse!
- options.environment = ARGV.shift
- options.role = ARGV.shift
+ unless ARGV.empty?
+ options.environment = ARGV.shift
+ options.role = ARGV.shift
+ end
options
end
View
Binary file not shown.
View
@@ -1,8 +1,6 @@
require 'spec_helper'
require 'claws/options'
-ARGV.clear
-
def cli(args)
ARGV.push(*args)
yield
@@ -15,7 +13,7 @@ def cli(args)
options = Claws::Options.parse
options.connect.should be_true
options.source.should == 'ec2'
- options.choice.should be_nil
+ options.selection.should be_nil
end
end
@@ -35,37 +33,35 @@ def cli(args)
it 'accepts a choice flag' do
cli %w{-c 10} do
- Claws::Options.parse.choice.should == 10
+ Claws::Options.parse.selection.should == 10
end
cli %w{--choice 10} do
- Claws::Options.parse.choice.should == 10
+ Claws::Options.parse.selection.should == 10
end
end
it 'accepts a source flag' do
cli %w{-s elb} do
options = Claws::Options.parse
options.source.should == 'elb'
- options.connect.should be_false
end
cli %w{--source elb} do
options = Claws::Options.parse
options.source.should == 'elb'
- options.connect.should be_false
end
end
context 'capistrano' do
it 'defines the environment' do
- cli %w{-s production app} do
+ cli %w{production app} do
Claws::Options.parse.environment.should == 'production'
end
end
it 'defines the role' do
- cli %w{-s production app} do
+ cli %w{production app} do
Claws::Options.parse.role.should == 'app'
end
end

0 comments on commit 2e3b1bf

Please sign in to comment.