bbcloud 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/.gitignore +3 -2
  2. data/Gemfile +3 -0
  3. data/README +11 -1
  4. data/README.rdoc +11 -1
  5. data/Rakefile +12 -0
  6. data/bbcloud.gemspec +10 -10
  7. data/bin/brightbox-accounts +7 -2
  8. data/bin/brightbox-cloudips +7 -2
  9. data/bin/brightbox-config +7 -2
  10. data/bin/brightbox-images +7 -2
  11. data/bin/brightbox-lbs +7 -2
  12. data/bin/brightbox-servers +7 -2
  13. data/bin/brightbox-types +7 -2
  14. data/bin/brightbox-users +7 -2
  15. data/bin/brightbox-zones +7 -2
  16. data/lib/bbcloud.rb +43 -0
  17. data/lib/bbcloud/accounts.rb +5 -3
  18. data/lib/bbcloud/command_generator.rb +50 -0
  19. data/lib/bbcloud/commands/accounts-list.rb +13 -11
  20. data/lib/bbcloud/commands/accounts-reset-ftp-password.rb +26 -23
  21. data/lib/bbcloud/commands/accounts-show.rb +20 -16
  22. data/lib/bbcloud/commands/cloudips-create.rb +16 -14
  23. data/lib/bbcloud/commands/cloudips-destroy.rb +29 -26
  24. data/lib/bbcloud/commands/cloudips-list.rb +13 -11
  25. data/lib/bbcloud/commands/cloudips-map.rb +48 -46
  26. data/lib/bbcloud/commands/cloudips-show.rb +15 -12
  27. data/lib/bbcloud/commands/cloudips-unmap.rb +28 -25
  28. data/lib/bbcloud/commands/config-client-add.rb +33 -31
  29. data/lib/bbcloud/commands/config-client-default.rb +18 -16
  30. data/lib/bbcloud/commands/config-client-list.rb +19 -16
  31. data/lib/bbcloud/commands/config-client-remove.rb +18 -16
  32. data/lib/bbcloud/commands/images-destroy.rb +18 -16
  33. data/lib/bbcloud/commands/images-list.rb +20 -18
  34. data/lib/bbcloud/commands/images-register.rb +21 -19
  35. data/lib/bbcloud/commands/images-show.rb +17 -15
  36. data/lib/bbcloud/commands/lbs-add-nodes.rb +15 -13
  37. data/lib/bbcloud/commands/lbs-create.rb +65 -63
  38. data/lib/bbcloud/commands/lbs-destroy.rb +13 -11
  39. data/lib/bbcloud/commands/lbs-list.rb +13 -11
  40. data/lib/bbcloud/commands/lbs-remove-nodes.rb +15 -13
  41. data/lib/bbcloud/commands/lbs-show.rb +15 -13
  42. data/lib/bbcloud/commands/lbs-update.rb +59 -57
  43. data/lib/bbcloud/commands/servers-activate-cloud.rb +18 -16
  44. data/lib/bbcloud/commands/servers-create.rb +80 -77
  45. data/lib/bbcloud/commands/servers-destroy.rb +17 -15
  46. data/lib/bbcloud/commands/servers-list.rb +14 -14
  47. data/lib/bbcloud/commands/servers-show.rb +39 -37
  48. data/lib/bbcloud/commands/servers-shutdown.rb +14 -12
  49. data/lib/bbcloud/commands/servers-snapshot.rb +14 -12
  50. data/lib/bbcloud/commands/servers-start.rb +15 -13
  51. data/lib/bbcloud/commands/servers-stop.rb +14 -12
  52. data/lib/bbcloud/commands/types-list.rb +13 -11
  53. data/lib/bbcloud/commands/types-show.rb +18 -16
  54. data/lib/bbcloud/commands/users-list.rb +13 -11
  55. data/lib/bbcloud/commands/users-show.rb +17 -15
  56. data/lib/bbcloud/commands/users-update.rb +27 -25
  57. data/lib/bbcloud/commands/zones-list.rb +13 -11
  58. data/lib/bbcloud/config.rb +125 -111
  59. data/lib/bbcloud/error_parser.rb +34 -0
  60. data/lib/bbcloud/fog_extensions.rb +19 -0
  61. data/lib/bbcloud/gli_global_hooks.rb +56 -0
  62. data/lib/bbcloud/logging.rb +40 -0
  63. data/lib/bbcloud/ruby_core_ext.rb +9 -0
  64. data/lib/bbcloud/servers.rb +7 -2
  65. data/lib/bbcloud/tables.rb +78 -73
  66. data/lib/bbcloud/vendor/gli/.gitignore +10 -0
  67. data/lib/bbcloud/vendor/gli/.rvmrc +1 -0
  68. data/lib/bbcloud/vendor/gli/Gemfile +5 -0
  69. data/lib/bbcloud/vendor/gli/LICENSE.txt +201 -0
  70. data/lib/bbcloud/vendor/gli/README.rdoc +54 -0
  71. data/lib/bbcloud/vendor/gli/Rakefile +84 -0
  72. data/lib/bbcloud/vendor/gli/bin/gli +72 -0
  73. data/lib/bbcloud/vendor/gli/bin/report_on_rake_results +10 -0
  74. data/lib/bbcloud/vendor/gli/bin/test_all_rubies.sh +2 -0
  75. data/lib/bbcloud/vendor/gli/features/gli_executable.feature +88 -0
  76. data/lib/bbcloud/vendor/gli/features/gli_init.feature +122 -0
  77. data/lib/bbcloud/vendor/gli/features/step_definitions/gli_executable_steps.rb +12 -0
  78. data/lib/bbcloud/vendor/gli/features/step_definitions/gli_init_steps.rb +4 -0
  79. data/lib/bbcloud/vendor/gli/features/support/env.rb +21 -0
  80. data/lib/bbcloud/vendor/gli/gli.cheat +80 -0
  81. data/lib/bbcloud/vendor/gli/gli.gemspec +46 -0
  82. data/lib/bbcloud/vendor/gli/gli.rdoc +51 -0
  83. data/lib/bbcloud/vendor/gli/lib/gli.rb +560 -0
  84. data/lib/bbcloud/vendor/gli/lib/gli/command.rb +124 -0
  85. data/lib/bbcloud/vendor/gli/lib/gli/command_line_token.rb +58 -0
  86. data/lib/bbcloud/vendor/gli/lib/gli/copy_options_to_aliases.rb +33 -0
  87. data/lib/bbcloud/vendor/gli/lib/gli/exceptions.rb +45 -0
  88. data/lib/bbcloud/vendor/gli/lib/gli/flag.rb +67 -0
  89. data/lib/bbcloud/vendor/gli/lib/gli/options.rb +19 -0
  90. data/lib/bbcloud/vendor/gli/lib/gli/switch.rb +63 -0
  91. data/lib/bbcloud/vendor/gli/lib/gli/terminal.rb +79 -0
  92. data/lib/bbcloud/vendor/gli/lib/gli_version.rb +3 -0
  93. data/lib/bbcloud/vendor/gli/lib/support/help.rb +180 -0
  94. data/lib/bbcloud/vendor/gli/lib/support/initconfig.rb +34 -0
  95. data/lib/bbcloud/vendor/gli/lib/support/rdoc.rb +119 -0
  96. data/lib/bbcloud/vendor/gli/lib/support/scaffold.rb +284 -0
  97. data/lib/bbcloud/vendor/gli/test/config.yaml +9 -0
  98. data/lib/bbcloud/vendor/gli/test/gli.reek +116 -0
  99. data/lib/bbcloud/vendor/gli/test/roodi.yaml +9 -0
  100. data/lib/bbcloud/vendor/gli/test/tc_command.rb +329 -0
  101. data/lib/bbcloud/vendor/gli/test/tc_flag.rb +67 -0
  102. data/lib/bbcloud/vendor/gli/test/tc_gli.rb +429 -0
  103. data/lib/bbcloud/vendor/gli/test/tc_options.rb +31 -0
  104. data/lib/bbcloud/vendor/gli/test/tc_parsing.rb +279 -0
  105. data/lib/bbcloud/vendor/gli/test/tc_switch.rb +80 -0
  106. data/lib/bbcloud/vendor/gli/test/tc_terminal.rb +91 -0
  107. data/lib/bbcloud/version.rb +1 -1
  108. data/pkg/bbcloud-0.12.0.gem +0 -0
  109. data/spec/fixtures/vcr_cassettes/server_list.yml +117 -0
  110. data/spec/servers_spec.rb +36 -0
  111. data/spec/spec_helper.rb +24 -0
  112. data/spec/support/common_helpers.rb +47 -0
  113. metadata +129 -135
  114. data/lib/bbcloud/cli.rb +0 -160
  115. data/lib/bbcloud/vendor/fog/lib/fog.rb +0 -14
  116. data/lib/bbcloud/vendor/fog/lib/fog/compute.rb +0 -43
  117. data/lib/bbcloud/vendor/fog/lib/fog/compute/brightbox.rb +0 -162
  118. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/account.rb +0 -51
  119. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ip.rb +0 -47
  120. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/cloud_ips.rb +0 -34
  121. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavor.rb +0 -33
  122. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/flavors.rb +0 -28
  123. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/image.rb +0 -56
  124. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/images.rb +0 -28
  125. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancer.rb +0 -50
  126. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/load_balancers.rb +0 -28
  127. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/server.rb +0 -108
  128. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/servers.rb +0 -29
  129. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/user.rb +0 -39
  130. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/users.rb +0 -29
  131. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zone.rb +0 -21
  132. data/lib/bbcloud/vendor/fog/lib/fog/compute/models/brightbox/zones.rb +0 -29
  133. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/activate_console_server.rb +0 -20
  134. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb +0 -20
  135. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb +0 -20
  136. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_api_client.rb +0 -19
  137. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_cloud_ip.rb +0 -19
  138. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_image.rb +0 -19
  139. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_load_balancer.rb +0 -19
  140. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/create_server.rb +0 -19
  141. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_api_client.rb +0 -20
  142. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb +0 -20
  143. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_image.rb +0 -20
  144. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb +0 -20
  145. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/destroy_server.rb +0 -20
  146. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_account.rb +0 -19
  147. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_api_client.rb +0 -20
  148. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_cloud_ip.rb +0 -20
  149. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_image.rb +0 -20
  150. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_interface.rb +0 -20
  151. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_load_balancer.rb +0 -20
  152. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server.rb +0 -20
  153. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_server_type.rb +0 -20
  154. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_user.rb +0 -20
  155. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/get_zone.rb +0 -20
  156. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_api_clients.rb +0 -19
  157. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_cloud_ips.rb +0 -19
  158. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_images.rb +0 -19
  159. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_load_balancers.rb +0 -19
  160. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_server_types.rb +0 -19
  161. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_servers.rb +0 -19
  162. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_users.rb +0 -19
  163. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/list_zones.rb +0 -19
  164. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/map_cloud_ip.rb +0 -20
  165. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb +0 -20
  166. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb +0 -20
  167. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb +0 -19
  168. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/resize_server.rb +0 -19
  169. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/shutdown_server.rb +0 -20
  170. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/snapshot_server.rb +0 -20
  171. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/start_server.rb +0 -20
  172. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/stop_server.rb +0 -20
  173. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb +0 -20
  174. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_account.rb +0 -20
  175. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_api_client.rb +0 -21
  176. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_image.rb +0 -21
  177. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_load_balancer.rb +0 -21
  178. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_server.rb +0 -21
  179. data/lib/bbcloud/vendor/fog/lib/fog/compute/requests/brightbox/update_user.rb +0 -21
  180. data/lib/bbcloud/vendor/fog/lib/fog/core.rb +0 -32
  181. data/lib/bbcloud/vendor/fog/lib/fog/core/attributes.rb +0 -178
  182. data/lib/bbcloud/vendor/fog/lib/fog/core/collection.rb +0 -127
  183. data/lib/bbcloud/vendor/fog/lib/fog/core/connection.rb +0 -35
  184. data/lib/bbcloud/vendor/fog/lib/fog/core/credentials.rb +0 -92
  185. data/lib/bbcloud/vendor/fog/lib/fog/core/deprecation.rb +0 -23
  186. data/lib/bbcloud/vendor/fog/lib/fog/core/errors.rb +0 -20
  187. data/lib/bbcloud/vendor/fog/lib/fog/core/hmac.rb +0 -48
  188. data/lib/bbcloud/vendor/fog/lib/fog/core/mock.rb +0 -68
  189. data/lib/bbcloud/vendor/fog/lib/fog/core/model.rb +0 -57
  190. data/lib/bbcloud/vendor/fog/lib/fog/core/parser.rb +0 -99
  191. data/lib/bbcloud/vendor/fog/lib/fog/core/provider.rb +0 -18
  192. data/lib/bbcloud/vendor/fog/lib/fog/core/scp.rb +0 -67
  193. data/lib/bbcloud/vendor/fog/lib/fog/core/service.rb +0 -175
  194. data/lib/bbcloud/vendor/fog/lib/fog/core/ssh.rb +0 -120
  195. data/lib/bbcloud/vendor/fog/lib/fog/core/time.rb +0 -27
  196. data/lib/bbcloud/vendor/fog/lib/fog/core/wait_for.rb +0 -17
  197. data/lib/bbcloud/vendor/fog/lib/fog/providers.rb +0 -9
  198. data/lib/bbcloud/vendor/fog/lib/fog/providers/brightbox.rb +0 -9
@@ -0,0 +1,9 @@
1
+ ---
2
+ commands:
3
+ :command:
4
+ :g: bar
5
+ :s: true
6
+ :other_command:
7
+ :g: foobar
8
+ :f: barfoo
9
+ :f: foo
@@ -0,0 +1,116 @@
1
+ ---
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+
5
+ exclude: []
6
+
7
+ enabled: false
8
+ reject:
9
+ - !ruby/regexp /^.$/
10
+ - !ruby/regexp /[0-9]$/
11
+ - !ruby/regexp /[A-Z]/
12
+ LargeClass:
13
+ max_methods: 25
14
+ exclude: []
15
+
16
+ enabled: true
17
+ max_instance_variables: 10
18
+ UncommunicativeMethodName:
19
+ accept: []
20
+
21
+ exclude: []
22
+
23
+ enabled: true
24
+ reject:
25
+ - !ruby/regexp /^[a-z]$/
26
+ - !ruby/regexp /[0-9]$/
27
+ - !ruby/regexp /[A-Z]/
28
+ LongParameterList:
29
+ max_params: 5
30
+ exclude: []
31
+
32
+ enabled: true
33
+ overrides:
34
+ initialize:
35
+ max_params: 6
36
+ FeatureEnvy:
37
+ exclude: &id001 []
38
+
39
+ enabled: false
40
+ ClassVariable:
41
+ exclude: *id001
42
+ enabled: false
43
+ BooleanParameter:
44
+ exclude: ['initialize']
45
+ enabled: true
46
+ IrresponsibleModule:
47
+ exclude: *id001
48
+ enabled: true
49
+ UncommunicativeModuleName:
50
+ accept:
51
+ - Inline::C
52
+ exclude: []
53
+
54
+ enabled: true
55
+ reject:
56
+ - !ruby/regexp /^.$/
57
+ - !ruby/regexp /[0-9]$/
58
+ NestedIterators:
59
+ ignore_iterators: []
60
+
61
+ exclude: []
62
+
63
+ enabled: true
64
+ max_allowed_nesting: 1
65
+ LongMethod:
66
+ max_statements: 10
67
+ exclude:
68
+ - initialize
69
+ - parse_options
70
+ - run
71
+ enabled: true
72
+ Duplication:
73
+ allow_calls: []
74
+
75
+ exclude: ['run']
76
+
77
+ enabled: true
78
+ max_calls: 3
79
+ UtilityFunction:
80
+ max_helper_calls: 1
81
+ exclude: [ 'find_non_flag_index', 'override_default', 'proceed?', 'command_exists?' ]
82
+
83
+ enabled: true
84
+ Attribute:
85
+ exclude: []
86
+
87
+ enabled: false
88
+ UncommunicativeVariableName:
89
+ accept: []
90
+
91
+ exclude: []
92
+
93
+ enabled: true
94
+ reject:
95
+ - !ruby/regexp /^.$/
96
+ - !ruby/regexp /[0-9]$/
97
+ - !ruby/regexp /[A-Z]/
98
+ SimulatedPolymorphism:
99
+ exclude: []
100
+
101
+ enabled: true
102
+ max_ifs: 2
103
+ DataClump:
104
+ exclude: []
105
+
106
+ enabled: false
107
+ max_copies: 2
108
+ min_clump_size: 2
109
+ ControlCouple:
110
+ exclude: ['parse_options_helper', 'program_desc', 'program_name']
111
+ enabled: true
112
+ LongYieldList:
113
+ max_params: 3
114
+ exclude: []
115
+
116
+ enabled: true
@@ -0,0 +1,9 @@
1
+ # Not the most strict checks, but they pass for now
2
+ AssignmentInConditionalCheck: { }
3
+ ClassLineCountCheck: { line_count: 300 }
4
+ ClassNameCheck: { pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/ }
5
+ CyclomaticComplexityBlockCheck: { complexity: 5 }
6
+ EmptyRescueBodyCheck: { }
7
+ ForLoopCheck: { }
8
+ MethodNameCheck: { pattern: !ruby/regexp /^[_a-z<>=\[\]|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/ }
9
+ ModuleNameCheck: { pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/ }
@@ -0,0 +1,329 @@
1
+ require 'gli.rb'
2
+ require 'test/unit'
3
+ require 'tempfile'
4
+
5
+ include GLI
6
+ class TC_testCommand < Test::Unit::TestCase
7
+
8
+ class FakeStdOut
9
+ attr_reader :strings
10
+ def puts(string=nil)
11
+ @strings ||= []
12
+ @strings << string unless string.nil?
13
+ end
14
+
15
+ # Returns true if the regexp matches anything in the output
16
+ def contained?(regexp)
17
+ strings.find{ |x| x =~ regexp }
18
+ end
19
+
20
+ def to_s
21
+ @strings.join("\n")
22
+ end
23
+ end
24
+
25
+ def setup
26
+ GLI.reset
27
+ GLI.program_desc 'A super awesome program'
28
+ GLI.desc 'Some Global Option'
29
+ GLI.switch :g
30
+ GLI.switch :blah
31
+ GLI.long_desc 'This is a very long description for a flag'
32
+ GLI.flag [:y,:yes]
33
+ @pre_called = false
34
+ @post_called = false
35
+ @error_called = false
36
+ GLI.pre { |g,c,o,a| @pre_called = true }
37
+ GLI.post { |g,c,o,a| @post_called = true }
38
+ GLI.on_error { |g,c,o,a| @error_called = true }
39
+ @glob = nil
40
+ @verbose = nil
41
+ @glob_verbose = nil
42
+ @configure = nil
43
+ @args = nil
44
+ GLI.desc 'Some Basic Command that potentially has a really really really really really really really long description and stuff, but you know, who cares?'
45
+ GLI.long_desc 'This is the long description: "Some Basic Command that potentially has a really really really really really really really long description and stuff, but you know, who cares?"'
46
+ GLI.arg_name 'first_file second_file'
47
+ GLI.command [:basic,:bs] do |c|
48
+ c.desc 'be verbose'
49
+ c.switch :v
50
+ c.desc 'configure something or other, in some way that requires a lot of verbose text and whatnot'
51
+ c.default_value 'crud'
52
+ c.flag [:c,:configure]
53
+ c.action do |global_options,options,arguments|
54
+ @glob = global_options[:g] ? 'true' : 'false'
55
+ @verbose = options[:v] ? 'true' : 'false'
56
+ @glob_verbose = global_options[:v] ? 'true' : 'false'
57
+ @configure = options[:c]
58
+ @args = arguments
59
+ end
60
+ end
61
+ @fake_stdout = FakeStdOut.new
62
+ @fake_stderr = FakeStdOut.new
63
+ DefaultHelpCommand.output_device=@fake_stdout
64
+ DefaultHelpCommand.skips_pre=true
65
+ DefaultHelpCommand.skips_post=true
66
+ GLI.error_device=@fake_stderr
67
+ end
68
+
69
+ def tear_down
70
+ FileUtils.rm_f "cruddo.rdoc"
71
+ DefaultHelpCommand.output_device=$stdout
72
+ end
73
+
74
+ def test_names
75
+ command = Command.new([:ls,:list,:'list-them-all'],"List")
76
+ assert_equal "ls, list-them-all, list",command.names
77
+ end
78
+
79
+ def test_command_sort
80
+ commands = [Command.new(:foo,"foo")]
81
+ commands << Command.new(:bar,"bar")
82
+ commands << Command.new(:zazz,"zazz")
83
+ commands << Command.new(:zaz,"zaz")
84
+
85
+ sorted = commands.sort
86
+ assert_equal :bar,sorted[0].name
87
+ assert_equal :foo,sorted[1].name
88
+ assert_equal :zaz,sorted[2].name
89
+ assert_equal :zazz,sorted[3].name
90
+ end
91
+
92
+ def test_basic_command
93
+ args_args = [%w(-g basic -v -c foo bar baz quux), %w(-g basic -v --configure=foo bar baz quux)]
94
+ args_args.each do |args|
95
+ GLI.run(args)
96
+ assert_equal('true',@glob)
97
+ assert_equal('true',@verbose)
98
+ assert_equal('false',@glob_verbose)
99
+ assert_equal('foo',@configure)
100
+ assert_equal(%w(bar baz quux),@args)
101
+ assert(@pre_called,"Pre block should have been called")
102
+ assert(@post_called,"Post block should have been called")
103
+ assert(!@error_called,"Error block should not have been called")
104
+ end
105
+ end
106
+
107
+ def test_command_skips_pre
108
+ GLI.skips_pre
109
+ GLI.skips_post
110
+
111
+ skips_pre_called = false
112
+ runs_pre_called = false
113
+
114
+ GLI.command [:skipspre] do |c|
115
+ c.action do |g,o,a|
116
+ skips_pre_called = true
117
+ end
118
+ end
119
+
120
+ # Making sure skips_pre doesn't leak to other commands
121
+ GLI.command [:runspre] do |c|
122
+ c.action do |g,o,a|
123
+ runs_pre_called = true
124
+ end
125
+ end
126
+
127
+ GLI.run(['skipspre'])
128
+
129
+ assert(skips_pre_called,"'skipspre' should have been called")
130
+ assert(!@pre_called,"Pre block should not have been called")
131
+ assert(!@post_called,"Post block should not have been called")
132
+ assert(!@error_called,"Error block should not have been called")
133
+
134
+ GLI.run(['runspre'])
135
+
136
+ assert(runs_pre_called,"'runspre' should have been called")
137
+ assert(@pre_called,"Pre block should not have been called")
138
+ assert(@post_called,"Post block SHOULD have been called")
139
+ assert(!@error_called,"Error block should not have been called")
140
+ end
141
+
142
+ def test_command_no_globals
143
+ args = %w(basic -c foo bar baz quux)
144
+ GLI.run(args)
145
+ assert_equal('foo',@configure)
146
+ assert_equal(%w(bar baz quux),@args)
147
+ end
148
+
149
+ def test_defaults_get_set
150
+ args = %w(basic bar baz quux)
151
+ GLI.run(args)
152
+ assert_equal('false',@glob)
153
+ assert_equal('false',@verbose)
154
+ assert_equal('crud',@configure)
155
+ assert_equal(%w(bar baz quux),@args)
156
+ end
157
+
158
+ def test_no_arguments
159
+ args = %w(basic -v)
160
+ GLI.run(args)
161
+ assert_equal('true',@verbose)
162
+ assert_equal('crud',@configure)
163
+ assert_equal([],@args)
164
+ end
165
+
166
+ def test_unknown_command
167
+ args = %w(blah)
168
+ GLI.run(args)
169
+ assert(!@post_called)
170
+ assert(@error_called)
171
+ assert_contained(@fake_stderr,/ help/)
172
+ assert_contained(@fake_stderr,/list of commands/)
173
+ end
174
+
175
+ def test_unknown_global_option
176
+ args = %w(--quux basic)
177
+ GLI.run(args)
178
+ assert(!@post_called)
179
+ assert(@error_called)
180
+ assert_contained(@fake_stderr,/ help/)
181
+ assert_contained(@fake_stderr,/list of global options/)
182
+ end
183
+
184
+ def test_unknown_argument
185
+ args = %w(basic --quux)
186
+ GLI.run(args)
187
+ assert(!@post_called)
188
+ assert(@error_called)
189
+ assert_contained(@fake_stderr,/ help basic/)
190
+ assert_contained(@fake_stderr,/list of command options/)
191
+ end
192
+
193
+ def test_help
194
+ args = %w(help)
195
+ GLI.run(args)
196
+ ['\[global options\]','\[command options\]','Global Options:','A super awesome program'].each do |opt|
197
+ assert_contained(@fake_stdout,/#{opt}/)
198
+ end
199
+ assert(!@pre_called,"Expected pre block NOT to have been called")
200
+ assert(!@post_called,"Expected post block NOT to have been called")
201
+ end
202
+
203
+ def test_help_with_config_file_shows_config_value
204
+ config_file = Tempfile.new('gli_config')
205
+ config = {
206
+ :blah => true,
207
+ :y => "foo",
208
+ }
209
+ File.open(config_file.path,'w') { |file| YAML.dump(config,file) }
210
+ GLI.config_file(config_file.path)
211
+ GLI.run(%w(help))
212
+ assert_contained(@fake_stdout,/\(default: foo\)/)
213
+ end
214
+
215
+ def test_help_with_pre_called
216
+ args = %w(help)
217
+ GLI::DefaultHelpCommand.skips_pre=false
218
+ GLI::DefaultHelpCommand.skips_post=false
219
+ GLI.run(args)
220
+ assert(@pre_called,"Expected pre block to have been called")
221
+ assert(@post_called,"Expected pre block to have been called")
222
+ end
223
+
224
+ def test_help_no_global_options
225
+ GLI.reset
226
+ GLI.desc 'Basic Command'
227
+ GLI.command [:basic,:bs] do |c|
228
+ c.action do |global_options,options,arguments|
229
+ end
230
+ end
231
+ @fake_stdout = FakeStdOut.new
232
+ DefaultHelpCommand.output_device=@fake_stdout
233
+
234
+ GLI.run(%w(help))
235
+ assert_not_contained(@fake_stdout,/\[global options\]/)
236
+ end
237
+
238
+ def test_help_one_command
239
+ args = %w(help basic)
240
+ GLI.run(args)
241
+ ['Command Options:','\[command options\]'].each do |opt|
242
+ assert_contained(@fake_stdout,/#{opt}/)
243
+ end
244
+ end
245
+
246
+ def test_version
247
+ GLI.command :foo, :bar do |c|; end
248
+ GLI.command :ls, :list do |c|; end
249
+ GLI.version '1.3.4'
250
+ args = %w(help)
251
+ GLI.run(args)
252
+ assert_not_nil @fake_stdout.strings.find{ |x| x =~ /^Version: 1.3.4/ }
253
+ end
254
+
255
+ def test_version_not_specified
256
+ GLI.command :foo, :bar do |c|; end
257
+ GLI.command :ls, :list do |c|; end
258
+ args = %w(help)
259
+ GLI.run(args)
260
+ assert_nil @fake_stdout.strings.find{ |x| x =~ /^Version: 1.3.4/ }
261
+ end
262
+
263
+ def test_help_completion
264
+ GLI.command :foo, :bar do |c|; end
265
+ GLI.command :ls, :list do |c|; end
266
+ args = %w(help -c)
267
+ GLI.run(args)
268
+ assert_equal 7,@fake_stdout.strings.size
269
+ assert_equal ['bar','basic','bs','foo','help','list','ls'],@fake_stdout.strings
270
+ end
271
+
272
+ def test_help_completion_partial
273
+ GLI.command :foo, :bar do |c|; end
274
+ GLI.command :ls, :list do |c|; end
275
+ args = %w(help -c b)
276
+ GLI.run(args)
277
+ assert_equal 3,@fake_stdout.strings.size
278
+ assert_equal ['bar','basic','bs'],@fake_stdout.strings
279
+ end
280
+
281
+ def test_rdoc
282
+ GLI.program_name 'cruddo'
283
+ args = %w(rdoc)
284
+ GLI.run(args)
285
+ assert File.exists?("cruddo.rdoc")
286
+ end
287
+
288
+ def test_help_no_command
289
+ GLI.program_name 'cruddo'
290
+ args = %w(help foo)
291
+ GLI.run(args)
292
+ assert_equal('cruddo',GLI.program_name)
293
+ end
294
+
295
+ def test_command_create
296
+ GLI.desc 'single symbol'
297
+ GLI.command :single do |c|; end
298
+ command = GLI.commands[:single]
299
+ assert_equal :single, command.name
300
+ assert_equal nil, command.aliases
301
+
302
+ description = 'implicit array'
303
+ GLI.desc description
304
+ GLI.command :foo, :bar do |c|; end
305
+ command = GLI.commands[:foo]
306
+ assert_equal :foo, command.name
307
+ assert_equal [:bar], command.aliases
308
+
309
+ description = 'explicit array'
310
+ GLI.desc description
311
+ GLI.command [:baz, :blah] do |c|; end
312
+ command = GLI.commands[:baz]
313
+ assert_equal :baz, command.name
314
+ assert_equal [:blah], command.aliases
315
+ end
316
+
317
+ private
318
+
319
+ def assert_contained(output,regexp)
320
+ assert_not_nil output.contained?(regexp),
321
+ "Expected output to contain #{regexp.inspect}, output was:\n#{output}"
322
+ end
323
+
324
+ def assert_not_contained(output,regexp)
325
+ assert_nil output.contained?(regexp),
326
+ "Didn't expected output to contain #{regexp.inspect}, output was:\n#{output}"
327
+ end
328
+
329
+ end