bbcloud 0.11.2 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -2
- data/Gemfile +3 -0
- data/README +11 -1
- data/README.rdoc +11 -1
- data/Rakefile +12 -0
- data/bbcloud.gemspec +10 -10
- data/bin/brightbox-accounts +7 -2
- data/bin/brightbox-cloudips +7 -2
- data/bin/brightbox-config +7 -2
- data/bin/brightbox-images +7 -2
- data/bin/brightbox-lbs +7 -2
- data/bin/brightbox-servers +7 -2
- data/bin/brightbox-types +7 -2
- data/bin/brightbox-users +7 -2
- data/bin/brightbox-zones +7 -2
- data/lib/bbcloud.rb +43 -0
- data/lib/bbcloud/accounts.rb +5 -3
- data/lib/bbcloud/command_generator.rb +50 -0
- data/lib/bbcloud/commands/accounts-list.rb +13 -11
- data/lib/bbcloud/commands/accounts-reset-ftp-password.rb +26 -23
- data/lib/bbcloud/commands/accounts-show.rb +20 -16
- data/lib/bbcloud/commands/cloudips-create.rb +16 -14
- data/lib/bbcloud/commands/cloudips-destroy.rb +29 -26
- data/lib/bbcloud/commands/cloudips-list.rb +13 -11
- data/lib/bbcloud/commands/cloudips-map.rb +48 -46
- data/lib/bbcloud/commands/cloudips-show.rb +15 -12
- data/lib/bbcloud/commands/cloudips-unmap.rb +28 -25
- data/lib/bbcloud/commands/config-client-add.rb +33 -31
- data/lib/bbcloud/commands/config-client-default.rb +18 -16
- data/lib/bbcloud/commands/config-client-list.rb +19 -16
- data/lib/bbcloud/commands/config-client-remove.rb +18 -16
- data/lib/bbcloud/commands/images-destroy.rb +18 -16
- data/lib/bbcloud/commands/images-list.rb +20 -18
- data/lib/bbcloud/commands/images-register.rb +21 -19
- data/lib/bbcloud/commands/images-show.rb +17 -15
- data/lib/bbcloud/commands/lbs-add-nodes.rb +15 -13
- data/lib/bbcloud/commands/lbs-create.rb +65 -63
- data/lib/bbcloud/commands/lbs-destroy.rb +13 -11
- data/lib/bbcloud/commands/lbs-list.rb +13 -11
- data/lib/bbcloud/commands/lbs-remove-nodes.rb +15 -13
- data/lib/bbcloud/commands/lbs-show.rb +15 -13
- data/lib/bbcloud/commands/lbs-update.rb +59 -57
- data/lib/bbcloud/commands/servers-activate-cloud.rb +18 -16
- data/lib/bbcloud/commands/servers-create.rb +80 -77
- data/lib/bbcloud/commands/servers-destroy.rb +17 -15
- data/lib/bbcloud/commands/servers-list.rb +14 -14
- data/lib/bbcloud/commands/servers-show.rb +39 -37
- data/lib/bbcloud/commands/servers-shutdown.rb +14 -12
- data/lib/bbcloud/commands/servers-snapshot.rb +14 -12
- data/lib/bbcloud/commands/servers-start.rb +15 -13
- data/lib/bbcloud/commands/servers-stop.rb +14 -12
- data/lib/bbcloud/commands/types-list.rb +13 -11
- data/lib/bbcloud/commands/types-show.rb +18 -16
- data/lib/bbcloud/commands/users-list.rb +13 -11
- data/lib/bbcloud/commands/users-show.rb +17 -15
- data/lib/bbcloud/commands/users-update.rb +27 -25
- data/lib/bbcloud/commands/zones-list.rb +13 -11
- data/lib/bbcloud/config.rb +125 -111
- data/lib/bbcloud/error_parser.rb +34 -0
- data/lib/bbcloud/fog_extensions.rb +19 -0
- data/lib/bbcloud/gli_global_hooks.rb +56 -0
- data/lib/bbcloud/logging.rb +40 -0
- data/lib/bbcloud/ruby_core_ext.rb +9 -0
- data/lib/bbcloud/servers.rb +7 -2
- data/lib/bbcloud/tables.rb +78 -73
- data/lib/bbcloud/vendor/gli/.gitignore +10 -0
- data/lib/bbcloud/vendor/gli/.rvmrc +1 -0
- data/lib/bbcloud/vendor/gli/Gemfile +5 -0
- data/lib/bbcloud/vendor/gli/LICENSE.txt +201 -0
- data/lib/bbcloud/vendor/gli/README.rdoc +54 -0
- data/lib/bbcloud/vendor/gli/Rakefile +84 -0
- data/lib/bbcloud/vendor/gli/bin/gli +72 -0
- data/lib/bbcloud/vendor/gli/bin/report_on_rake_results +10 -0
- data/lib/bbcloud/vendor/gli/bin/test_all_rubies.sh +2 -0
- data/lib/bbcloud/vendor/gli/features/gli_executable.feature +88 -0
- data/lib/bbcloud/vendor/gli/features/gli_init.feature +122 -0
- data/lib/bbcloud/vendor/gli/features/step_definitions/gli_executable_steps.rb +12 -0
- data/lib/bbcloud/vendor/gli/features/step_definitions/gli_init_steps.rb +4 -0
- data/lib/bbcloud/vendor/gli/features/support/env.rb +21 -0
- data/lib/bbcloud/vendor/gli/gli.cheat +80 -0
- data/lib/bbcloud/vendor/gli/gli.gemspec +46 -0
- data/lib/bbcloud/vendor/gli/gli.rdoc +51 -0
- data/lib/bbcloud/vendor/gli/lib/gli.rb +560 -0
- data/lib/bbcloud/vendor/gli/lib/gli/command.rb +124 -0
- data/lib/bbcloud/vendor/gli/lib/gli/command_line_token.rb +58 -0
- data/lib/bbcloud/vendor/gli/lib/gli/copy_options_to_aliases.rb +33 -0
- data/lib/bbcloud/vendor/gli/lib/gli/exceptions.rb +45 -0
- data/lib/bbcloud/vendor/gli/lib/gli/flag.rb +67 -0
- data/lib/bbcloud/vendor/gli/lib/gli/options.rb +19 -0
- data/lib/bbcloud/vendor/gli/lib/gli/switch.rb +63 -0
- data/lib/bbcloud/vendor/gli/lib/gli/terminal.rb +79 -0
- data/lib/bbcloud/vendor/gli/lib/gli_version.rb +3 -0
- data/lib/bbcloud/vendor/gli/lib/support/help.rb +180 -0
- data/lib/bbcloud/vendor/gli/lib/support/initconfig.rb +34 -0
- data/lib/bbcloud/vendor/gli/lib/support/rdoc.rb +119 -0
- data/lib/bbcloud/vendor/gli/lib/support/scaffold.rb +284 -0
- data/lib/bbcloud/vendor/gli/test/config.yaml +9 -0
- data/lib/bbcloud/vendor/gli/test/gli.reek +116 -0
- data/lib/bbcloud/vendor/gli/test/roodi.yaml +9 -0
- data/lib/bbcloud/vendor/gli/test/tc_command.rb +329 -0
- data/lib/bbcloud/vendor/gli/test/tc_flag.rb +67 -0
- data/lib/bbcloud/vendor/gli/test/tc_gli.rb +429 -0
- data/lib/bbcloud/vendor/gli/test/tc_options.rb +31 -0
- data/lib/bbcloud/vendor/gli/test/tc_parsing.rb +279 -0
- data/lib/bbcloud/vendor/gli/test/tc_switch.rb +80 -0
- data/lib/bbcloud/vendor/gli/test/tc_terminal.rb +91 -0
- data/lib/bbcloud/version.rb +1 -1
- data/pkg/bbcloud-0.12.0.gem +0 -0
- data/spec/fixtures/vcr_cassettes/server_list.yml +117 -0
- data/spec/servers_spec.rb +36 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/common_helpers.rb +47 -0
- metadata +129 -135
- data/lib/bbcloud/cli.rb +0 -160
- data/lib/bbcloud/vendor/fog/lib/fog.rb +0 -14
- data/lib/bbcloud/vendor/fog/lib/fog/compute.rb +0 -43
- data/lib/bbcloud/vendor/fog/lib/fog/compute/brightbox.rb +0 -162
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/account.rb +0 -51
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ip.rb +0 -47
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ips.rb +0 -34
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavor.rb +0 -33
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavors.rb +0 -28
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/image.rb +0 -56
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/images.rb +0 -28
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancer.rb +0 -50
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancers.rb +0 -28
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/server.rb +0 -108
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/servers.rb +0 -29
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/user.rb +0 -39
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/users.rb +0 -29
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zone.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zones.rb +0 -29
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/activate_console_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_api_client.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_cloud_ip.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_image.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_load_balancer.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_server.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_api_client.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_image.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_account.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_api_client.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_image.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_interface.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server_type.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_user.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_zone.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_api_clients.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_cloud_ips.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_images.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_load_balancers.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_server_types.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_servers.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_users.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_zones.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/map_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/resize_server.rb +0 -19
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/shutdown_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/snapshot_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/start_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/stop_server.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_account.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_api_client.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_image.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_load_balancer.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_server.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_user.rb +0 -21
- data/lib/bbcloud/vendor/fog/lib/fog/core.rb +0 -32
- data/lib/bbcloud/vendor/fog/lib/fog/core/attributes.rb +0 -178
- data/lib/bbcloud/vendor/fog/lib/fog/core/collection.rb +0 -127
- data/lib/bbcloud/vendor/fog/lib/fog/core/connection.rb +0 -35
- data/lib/bbcloud/vendor/fog/lib/fog/core/credentials.rb +0 -92
- data/lib/bbcloud/vendor/fog/lib/fog/core/deprecation.rb +0 -23
- data/lib/bbcloud/vendor/fog/lib/fog/core/errors.rb +0 -20
- data/lib/bbcloud/vendor/fog/lib/fog/core/hmac.rb +0 -48
- data/lib/bbcloud/vendor/fog/lib/fog/core/mock.rb +0 -68
- data/lib/bbcloud/vendor/fog/lib/fog/core/model.rb +0 -57
- data/lib/bbcloud/vendor/fog/lib/fog/core/parser.rb +0 -99
- data/lib/bbcloud/vendor/fog/lib/fog/core/provider.rb +0 -18
- data/lib/bbcloud/vendor/fog/lib/fog/core/scp.rb +0 -67
- data/lib/bbcloud/vendor/fog/lib/fog/core/service.rb +0 -175
- data/lib/bbcloud/vendor/fog/lib/fog/core/ssh.rb +0 -120
- data/lib/bbcloud/vendor/fog/lib/fog/core/time.rb +0 -27
- data/lib/bbcloud/vendor/fog/lib/fog/core/wait_for.rb +0 -17
- data/lib/bbcloud/vendor/fog/lib/fog/providers.rb +0 -9
- data/lib/bbcloud/vendor/fog/lib/fog/providers/brightbox.rb +0 -9
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'gli.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
include GLI
|
5
|
+
class TC_testFlag < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_basics_simple
|
8
|
+
flag = Flag.new(:f,'Filename','file','~/.blah.rc')
|
9
|
+
do_basic_asserts(flag,:f,nil,'Filename','file','~/.blah.rc')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_basics_kinda_complex
|
13
|
+
flag = Flag.new([:f],'Filename','file','~/.blah.rc')
|
14
|
+
do_basic_asserts(flag,:f,nil,'Filename','file','~/.blah.rc')
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_basics_complex
|
18
|
+
flag = Flag.new([:f,:file,:filename],'Filename','file','~/.blah.rc')
|
19
|
+
do_basic_asserts(flag,:f,[:file,:filename],'Filename','file','~/.blah.rc')
|
20
|
+
end
|
21
|
+
|
22
|
+
def do_basic_asserts(flag,name,aliases,desc,arg_name,default)
|
23
|
+
assert_equal(name,flag.name)
|
24
|
+
assert_equal(aliases,flag.aliases)
|
25
|
+
assert_equal(desc,flag.description)
|
26
|
+
assert(flag.usage != nil)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_find_one_flag
|
30
|
+
args = %w(foo bar -f crud)
|
31
|
+
flag = Flag.new(:f,'Filename')
|
32
|
+
args_size = args.length
|
33
|
+
val = flag.get_value!(args)
|
34
|
+
assert_equal('crud',val)
|
35
|
+
assert_equal(args_size - 2,args.size)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_find_flag_compact
|
39
|
+
do_test_find_flag_compact(%w(foo bar --f blah --filename=bleorgh -lfilename crud),'bleorgh',6)
|
40
|
+
do_test_find_flag_compact(%w(foo bar --f blah -f bleorgh -lfilename crud),'bleorgh',6)
|
41
|
+
end
|
42
|
+
|
43
|
+
def do_test_find_flag_compact(args,expected,expected_size)
|
44
|
+
flag = Flag.new([:f,:filename],'Filename')
|
45
|
+
val = flag.get_value!(args)
|
46
|
+
assert_equal(expected,val)
|
47
|
+
assert_equal(expected_size,args.size)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_find_flag_not_present
|
51
|
+
args = %w(foo bar --f blah -lfilename bleorgh -lfilename crud)
|
52
|
+
flag = Flag.new([:f,:filename],'Filename')
|
53
|
+
args_size = args.length
|
54
|
+
val = flag.get_value!(args)
|
55
|
+
assert_equal(nil,val)
|
56
|
+
assert_equal(args_size,args.size)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_bad_command_line
|
60
|
+
flag = Flag.new([:f,:filename],'Filename')
|
61
|
+
assert_raises(BadCommandLine) { flag.get_value!(%w(foo bar --f blah -f)) }
|
62
|
+
assert_raises(BadCommandLine) { flag.get_value!(%w(foo bar --f blah --filename)) }
|
63
|
+
assert_raises(BadCommandLine) { flag.get_value!(%w(foo bar --f blah --filename=)) }
|
64
|
+
assert_raises(BadCommandLine) { flag.get_value!(%w(foo bar --f blah --filename bleorgh -lfilename crud)) }
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,429 @@
|
|
1
|
+
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
|
2
|
+
# have this method, so we add it so we get resolved symlinks
|
3
|
+
# and compatibility
|
4
|
+
unless File.respond_to? :realpath
|
5
|
+
class File
|
6
|
+
def self.realpath path
|
7
|
+
return realpath(File.readlink(path)) if symlink?(path)
|
8
|
+
path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'gli.rb'
|
14
|
+
require 'support/initconfig.rb'
|
15
|
+
require 'test/unit'
|
16
|
+
|
17
|
+
include GLI
|
18
|
+
class TC_testGLI < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/new_config.yaml')
|
22
|
+
@gli_debug = ENV['GLI_DEBUG']
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
File.delete(@config_file) if File.exist?(@config_file)
|
27
|
+
ENV['GLI_DEBUG'] = @gli_debug
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_flag_create
|
31
|
+
GLI.reset
|
32
|
+
do_test_flag_create(GLI)
|
33
|
+
do_test_flag_create(Command.new(:f,'Some command'))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_create_commands_using_strings
|
37
|
+
GLI.reset
|
38
|
+
GLI.flag ['f','flag']
|
39
|
+
GLI.switch ['s','some-switch']
|
40
|
+
GLI.command 'command','command-with-dash' do |c|
|
41
|
+
end
|
42
|
+
assert GLI.commands.include? :command
|
43
|
+
assert GLI.flags.include? :f
|
44
|
+
assert GLI.switches.include? :s
|
45
|
+
assert GLI.commands[:command].aliases.include? :'command-with-dash'
|
46
|
+
assert GLI.flags[:f].aliases.include? :flag
|
47
|
+
assert GLI.switches[:s].aliases.include? :'some-switch'
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_flag_with_space_barfs
|
51
|
+
GLI.reset
|
52
|
+
assert_raises(ArgumentError) { GLI.flag ['some flag'] }
|
53
|
+
assert_raises(ArgumentError) { GLI.flag ['f','some flag'] }
|
54
|
+
assert_raises(ArgumentError) { GLI.switch ['some switch'] }
|
55
|
+
assert_raises(ArgumentError) { GLI.switch ['f','some switch'] }
|
56
|
+
assert_raises(ArgumentError) { GLI.command ['some command'] }
|
57
|
+
assert_raises(ArgumentError) { GLI.command ['f','some command'] }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_init_from_config
|
61
|
+
failure = nil
|
62
|
+
GLI.reset
|
63
|
+
GLI.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/config.yaml'))
|
64
|
+
GLI.flag :f
|
65
|
+
GLI.switch :s
|
66
|
+
GLI.flag :g
|
67
|
+
called = false
|
68
|
+
GLI.command :command do |c|
|
69
|
+
c.flag :f
|
70
|
+
c.switch :s
|
71
|
+
c.flag :g
|
72
|
+
c.action do |g,o,a|
|
73
|
+
begin
|
74
|
+
called = true
|
75
|
+
assert_equal "foo",g[:f]
|
76
|
+
assert_equal "bar",o[:g]
|
77
|
+
assert !g[:g]
|
78
|
+
assert !o[:f]
|
79
|
+
assert !g[:s]
|
80
|
+
assert o[:s]
|
81
|
+
rescue Exception => ex
|
82
|
+
failure = ex
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
GLI.run(['command'])
|
87
|
+
assert called
|
88
|
+
raise failure if !failure.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_command_line_overrides_config
|
92
|
+
failure = nil
|
93
|
+
GLI.reset
|
94
|
+
GLI.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/config.yaml'))
|
95
|
+
GLI.flag :f
|
96
|
+
GLI.switch :s
|
97
|
+
GLI.flag :g
|
98
|
+
called = false
|
99
|
+
GLI.command :command do |c|
|
100
|
+
c.flag :f
|
101
|
+
c.switch :s
|
102
|
+
c.flag :g
|
103
|
+
c.action do |g,o,a|
|
104
|
+
begin
|
105
|
+
called = true
|
106
|
+
assert_equal "baaz",o[:g]
|
107
|
+
assert_equal "bar",g[:f]
|
108
|
+
assert !g[:g]
|
109
|
+
assert !o[:f]
|
110
|
+
assert !g[:s]
|
111
|
+
assert o[:s]
|
112
|
+
rescue Exception => ex
|
113
|
+
failure = ex
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
GLI.run %w(-f bar command -g baaz)
|
118
|
+
assert called
|
119
|
+
raise failure if !failure.nil?
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_no_overwrite_config
|
123
|
+
config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/config.yaml')
|
124
|
+
config_file_contents = read_file_contents(config_file)
|
125
|
+
GLI.reset
|
126
|
+
GLI.config_file(config_file)
|
127
|
+
ex = assert_raises RuntimeError do
|
128
|
+
GLI.run(['initconfig'])
|
129
|
+
end
|
130
|
+
assert_match /--force/,ex.to_s,"Error message didn't mention --force option"
|
131
|
+
config_file_contents_after = read_file_contents(config_file)
|
132
|
+
assert_equal(config_file_contents,config_file_contents_after)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_config_file_name
|
136
|
+
GLI.reset
|
137
|
+
file = GLI.config_file("foo")
|
138
|
+
assert_equal(Etc.getpwuid.dir + "/foo",file)
|
139
|
+
file = GLI.config_file("/foo")
|
140
|
+
assert_equal "/foo",file
|
141
|
+
init_command = GLI.commands[:initconfig]
|
142
|
+
assert init_command
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_initconfig_command
|
146
|
+
GLI.reset
|
147
|
+
GLI.config_file(@config_file)
|
148
|
+
GLI.flag :f
|
149
|
+
GLI.switch :s
|
150
|
+
GLI.switch :w
|
151
|
+
GLI.flag :bigflag
|
152
|
+
GLI.flag :biggestflag
|
153
|
+
GLI.command :foo do |c|
|
154
|
+
end
|
155
|
+
GLI.command :bar do |c|
|
156
|
+
end
|
157
|
+
GLI.command :blah do |c|
|
158
|
+
end
|
159
|
+
GLI.on_error do |ex|
|
160
|
+
raise ex
|
161
|
+
end
|
162
|
+
GLI.run(['-f','foo','-s','--bigflag=bleorgh','initconfig'])
|
163
|
+
|
164
|
+
written_config = File.open(@config_file) { |f| YAML::load(f) }
|
165
|
+
|
166
|
+
assert_equal 'foo',written_config[:f]
|
167
|
+
assert_equal 'bleorgh',written_config[:bigflag]
|
168
|
+
assert written_config[:s]
|
169
|
+
assert !written_config[:w]
|
170
|
+
assert_nil written_config[:biggestflag]
|
171
|
+
assert written_config[GLI::InitConfig::COMMANDS_KEY]
|
172
|
+
assert written_config[GLI::InitConfig::COMMANDS_KEY][:foo]
|
173
|
+
assert written_config[GLI::InitConfig::COMMANDS_KEY][:bar]
|
174
|
+
assert written_config[GLI::InitConfig::COMMANDS_KEY][:blah]
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
def do_test_flag_create(object)
|
179
|
+
description = 'this is a description'
|
180
|
+
long_desc = 'this is a very long description'
|
181
|
+
object.desc description
|
182
|
+
object.long_desc long_desc
|
183
|
+
object.arg_name 'filename'
|
184
|
+
object.default_value '~/.blah.rc'
|
185
|
+
object.flag :f
|
186
|
+
assert (object.flags[:f] )
|
187
|
+
assert_equal(description,object.flags[:f].description)
|
188
|
+
assert_equal(long_desc,object.flags[:f].long_description)
|
189
|
+
assert(nil != object.flags[:f].usage)
|
190
|
+
assert(object.usage != nil) if object.respond_to? :usage;
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_switch_create
|
194
|
+
GLI.reset
|
195
|
+
do_test_switch_create(GLI)
|
196
|
+
do_test_switch_create(Command.new(:f,'Some command'))
|
197
|
+
end
|
198
|
+
|
199
|
+
def do_test_switch_create(object)
|
200
|
+
description = 'this is a description'
|
201
|
+
long_description = 'this is a very long description'
|
202
|
+
object.desc description
|
203
|
+
object.long_desc long_description
|
204
|
+
object.switch :f
|
205
|
+
assert (object.switches[:f] )
|
206
|
+
assert_equal(description,object.switches[:f].description)
|
207
|
+
assert_equal(long_description,object.switches[:f].long_description)
|
208
|
+
assert(object.usage != nil) if object.respond_to? :usage;
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_switch_create_twice
|
212
|
+
GLI.reset
|
213
|
+
do_test_switch_create_twice(GLI)
|
214
|
+
do_test_switch_create_twice(Command.new(:f,'Some command'))
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_all_aliases_in_options
|
218
|
+
GLI.reset
|
219
|
+
GLI.on_error { |ex| raise ex }
|
220
|
+
GLI.flag [:f,:flag,:'big-flag-name']
|
221
|
+
GLI.switch [:s,:switch,:'big-switch-name']
|
222
|
+
GLI.command [:com,:command] do |c|
|
223
|
+
c.flag [:g,:gflag]
|
224
|
+
c.switch [:h,:hswitch]
|
225
|
+
c.action do |global,options,args|
|
226
|
+
assert_equal 'foo',global[:f]
|
227
|
+
assert_equal global[:f],global[:flag]
|
228
|
+
assert_equal global[:f],global[:'big-flag-name']
|
229
|
+
|
230
|
+
assert global[:s]
|
231
|
+
assert global[:switch]
|
232
|
+
assert global[:'big-switch-name']
|
233
|
+
|
234
|
+
assert_equal 'bar',options[:g]
|
235
|
+
assert_equal options[:g],options[:gflag]
|
236
|
+
|
237
|
+
assert options[:h]
|
238
|
+
assert options[:hswitch]
|
239
|
+
end
|
240
|
+
end
|
241
|
+
GLI.run(%w(-f foo -s command -g bar -h some_arg))
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_use_hash_by_default
|
245
|
+
GLI.reset
|
246
|
+
GLI.switch :g
|
247
|
+
GLI.command :command do |c|
|
248
|
+
c.switch :f
|
249
|
+
c.action do |global,options,args|
|
250
|
+
assert_equal Hash,global.class
|
251
|
+
assert_equal Hash,options.class
|
252
|
+
end
|
253
|
+
end
|
254
|
+
GLI.run(%w(-g command -f))
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_use_openstruct
|
258
|
+
GLI.reset
|
259
|
+
GLI.switch :g
|
260
|
+
GLI.use_openstruct true
|
261
|
+
GLI.command :command do |c|
|
262
|
+
c.switch :f
|
263
|
+
c.action do |global,options,args|
|
264
|
+
assert_equal GLI::Options,global.class
|
265
|
+
assert_equal GLI::Options,options.class
|
266
|
+
end
|
267
|
+
end
|
268
|
+
GLI.run(%w(-g command -f))
|
269
|
+
end
|
270
|
+
|
271
|
+
def do_test_switch_create_twice(object)
|
272
|
+
description = 'this is a description'
|
273
|
+
object.desc description
|
274
|
+
object.switch :f
|
275
|
+
assert (object.switches[:f] )
|
276
|
+
assert_equal(description,object.switches[:f].description)
|
277
|
+
object.switch :g
|
278
|
+
assert (object.switches[:g])
|
279
|
+
assert_equal(nil,object.switches[:g].description)
|
280
|
+
assert(object.usage != nil) if object.respond_to? :usage;
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_repeated_option_names
|
284
|
+
GLI.reset
|
285
|
+
GLI.on_error { |ex| raise ex }
|
286
|
+
GLI.flag [:f,:flag]
|
287
|
+
assert_raises(ArgumentError) { GLI.switch [:foo,:flag] }
|
288
|
+
assert_raises(ArgumentError) { GLI.switch [:f] }
|
289
|
+
|
290
|
+
GLI.switch [:x,:y]
|
291
|
+
assert_raises(ArgumentError) { GLI.flag [:x] }
|
292
|
+
assert_raises(ArgumentError) { GLI.flag [:y] }
|
293
|
+
end
|
294
|
+
|
295
|
+
def test_repeated_option_names_on_command
|
296
|
+
GLI.reset
|
297
|
+
GLI.on_error { |ex| raise ex }
|
298
|
+
GLI.command :command do |c|
|
299
|
+
c.flag [:f,:flag]
|
300
|
+
assert_raises(ArgumentError) { c.switch [:foo,:flag] }
|
301
|
+
assert_raises(ArgumentError) { c.switch [:f] }
|
302
|
+
assert_raises(ArgumentError) { c.flag [:foo,:flag] }
|
303
|
+
assert_raises(ArgumentError) { c.flag [:f] }
|
304
|
+
end
|
305
|
+
GLI.command :command3 do |c|
|
306
|
+
c.switch [:s,:switch]
|
307
|
+
assert_raises(ArgumentError) { c.switch [:switch] }
|
308
|
+
assert_raises(ArgumentError) { c.switch [:s] }
|
309
|
+
assert_raises(ArgumentError) { c.flag [:switch] }
|
310
|
+
assert_raises(ArgumentError) { c.flag [:s] }
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_two_flags
|
315
|
+
GLI.reset
|
316
|
+
GLI.on_error do |ex|
|
317
|
+
raise ex
|
318
|
+
end
|
319
|
+
GLI.command [:foo] do |c|
|
320
|
+
c.flag :i
|
321
|
+
c.flag :s
|
322
|
+
c.action do |g,o,a|
|
323
|
+
assert_equal "5", o[:i]
|
324
|
+
assert_equal "a", o[:s]
|
325
|
+
end
|
326
|
+
end
|
327
|
+
GLI.run(['foo', '-i','5','-s','a'])
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_two_flags_with_a_default
|
331
|
+
GLI.reset
|
332
|
+
GLI.on_error do |ex|
|
333
|
+
raise ex
|
334
|
+
end
|
335
|
+
GLI.command [:foo] do |c|
|
336
|
+
c.default_value "1"
|
337
|
+
c.flag :i
|
338
|
+
c.flag :s
|
339
|
+
c.action do |g,o,a|
|
340
|
+
assert_equal "5", o[:i]
|
341
|
+
assert_equal "a", o[:s]
|
342
|
+
end
|
343
|
+
end
|
344
|
+
GLI.run(['foo', '-i','5','-s','a'])
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_two_flags_using_equals_with_a_default
|
348
|
+
GLI.reset
|
349
|
+
GLI.on_error do |ex|
|
350
|
+
raise ex
|
351
|
+
end
|
352
|
+
GLI.command [:foo] do |c|
|
353
|
+
c.default_value "1"
|
354
|
+
c.flag :i
|
355
|
+
c.flag :s
|
356
|
+
c.action do |g,o,a|
|
357
|
+
assert_equal "5", o[:i]
|
358
|
+
assert_equal "a", o[:s]
|
359
|
+
end
|
360
|
+
end
|
361
|
+
GLI.run(['foo', '-i=5','-s=a'])
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_exits_zero_on_success
|
365
|
+
assert_equal 0,GLI.run([])
|
366
|
+
end
|
367
|
+
|
368
|
+
def test_exits_nonzero_on_bad_command_line
|
369
|
+
GLI.reset
|
370
|
+
GLI.on_error { true }
|
371
|
+
assert_equal -1,GLI.run(['asdfasdfasdf'])
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_exists_nonzero_on_raise_from_command
|
375
|
+
GLI.reset
|
376
|
+
GLI.on_error { true }
|
377
|
+
GLI.command(:foo) do |c|
|
378
|
+
c.action do |g,o,a|
|
379
|
+
raise "Problem"
|
380
|
+
end
|
381
|
+
end
|
382
|
+
assert_equal -2,GLI.run(['foo'])
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_exits_nonzero_with_custom_exception
|
386
|
+
GLI.reset
|
387
|
+
GLI.on_error { true }
|
388
|
+
GLI.command(:foo) do |c|
|
389
|
+
c.action do |g,o,a|
|
390
|
+
raise CustomExit.new("Problem",45)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
assert_equal 45,GLI.run(['foo'])
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_exits_nonzero_with_exit_method
|
397
|
+
GLI.reset
|
398
|
+
GLI.on_error { true }
|
399
|
+
GLI.command(:foo) do |c|
|
400
|
+
c.action do |g,o,a|
|
401
|
+
exit_now!("Problem",45)
|
402
|
+
end
|
403
|
+
end
|
404
|
+
assert_equal 45,GLI.run(['foo'])
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_gli_debug_overrides_error_hiding
|
408
|
+
ENV['GLI_DEBUG'] = 'true'
|
409
|
+
|
410
|
+
GLI.reset
|
411
|
+
GLI.on_error { true }
|
412
|
+
GLI.command(:foo) do |c|
|
413
|
+
c.action do |g,o,a|
|
414
|
+
exit_now!("Problem",45)
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
assert_raises(CustomExit) { GLI.run(['foo']) }
|
419
|
+
end
|
420
|
+
|
421
|
+
private
|
422
|
+
|
423
|
+
def read_file_contents(filename)
|
424
|
+
contents = ""
|
425
|
+
File.open(filename) { |file| file.readlines.each { |line| contents += line }}
|
426
|
+
contents
|
427
|
+
end
|
428
|
+
|
429
|
+
end
|