bbcloud 0.11.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,180 @@
|
|
|
1
|
+
require 'gli'
|
|
2
|
+
require 'gli/command'
|
|
3
|
+
require 'gli/terminal'
|
|
4
|
+
|
|
5
|
+
module GLI
|
|
6
|
+
class DefaultHelpCommand < Command #:nodoc:
|
|
7
|
+
@@output = $stdout
|
|
8
|
+
@@skips_pre = true
|
|
9
|
+
@@skips_post = true
|
|
10
|
+
|
|
11
|
+
# Exposed for testing
|
|
12
|
+
def self.output_device=(o); @@output = o; end
|
|
13
|
+
|
|
14
|
+
# To override the default behavior of the help command, which is
|
|
15
|
+
# to NOT run the pre block, use this.
|
|
16
|
+
def self.skips_pre=(skips_pre)
|
|
17
|
+
@@skips_pre = skips_pre
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# To override the default behavior of the help command, which is
|
|
21
|
+
# to NOT run the post block, use this.
|
|
22
|
+
def self.skips_post=(skips_post)
|
|
23
|
+
@@skips_post = skips_post
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def initialize(version,*omit_from_list)
|
|
27
|
+
@omit_from_list = omit_from_list
|
|
28
|
+
@version = version
|
|
29
|
+
super(:help,
|
|
30
|
+
'Shows list of commands or help for one command',
|
|
31
|
+
'[command]',
|
|
32
|
+
'Gets help for the application or its commands. Can also list the commands in a way helpful to creating a bash-style completion function')
|
|
33
|
+
self.desc 'List all commands one line at a time, for use with shell completion ([command] argument is partial command to match)'
|
|
34
|
+
self.switch [:c,:completion]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def skips_pre; @@skips_pre; end
|
|
38
|
+
def skips_post; @@skips_post; end
|
|
39
|
+
|
|
40
|
+
def execute(global_options,options,arguments)
|
|
41
|
+
if options[:c]
|
|
42
|
+
names = commands_to_show.reduce([]) do |memo,obj|
|
|
43
|
+
memo << obj[0]
|
|
44
|
+
memo << obj[1].aliases
|
|
45
|
+
memo = memo.flatten
|
|
46
|
+
end
|
|
47
|
+
names.map! { |name| name.to_s }
|
|
48
|
+
if arguments && arguments.size > 0
|
|
49
|
+
names = names.select { |name| name =~ /^#{arguments[0]}/ }
|
|
50
|
+
end
|
|
51
|
+
names.sort.each do |command|
|
|
52
|
+
next if command.empty?
|
|
53
|
+
@@output.puts command
|
|
54
|
+
end
|
|
55
|
+
else
|
|
56
|
+
if arguments.empty?
|
|
57
|
+
list_global_flags
|
|
58
|
+
list_commands
|
|
59
|
+
else
|
|
60
|
+
list_one_command_help(arguments[0])
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def list_global_flags
|
|
68
|
+
if GLI.program_desc
|
|
69
|
+
@@output.puts wrap(GLI.program_desc,0)
|
|
70
|
+
@@output.puts
|
|
71
|
+
end
|
|
72
|
+
usage = "usage: #{GLI.program_name} "
|
|
73
|
+
all_options = GLI.switches.merge(GLI.flags)
|
|
74
|
+
if !all_options.empty?
|
|
75
|
+
usage += "[global options] "
|
|
76
|
+
end
|
|
77
|
+
usage += "command"
|
|
78
|
+
usage += ' [command options]'
|
|
79
|
+
@@output.puts usage
|
|
80
|
+
@@output.puts
|
|
81
|
+
if @version
|
|
82
|
+
@@output.puts "Version: #{@version}"
|
|
83
|
+
@@output.puts
|
|
84
|
+
end
|
|
85
|
+
@@output.puts 'Global Options:' if !all_options.empty?
|
|
86
|
+
output_command_tokens_for_help(all_options)
|
|
87
|
+
@@output.puts if !all_options.empty?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def list_commands
|
|
91
|
+
@@output.puts 'Commands:'
|
|
92
|
+
output_command_tokens_for_help(commands_to_show,:names)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def commands_to_show
|
|
96
|
+
GLI.commands.reject{ |name,c| @omit_from_list.include?(c) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def list_one_command_help(command_name)
|
|
100
|
+
command = GLI.find_command(command_name)
|
|
101
|
+
if command
|
|
102
|
+
@@output.puts command.usage
|
|
103
|
+
description = wrap(command.description,4)
|
|
104
|
+
@@output.puts " #{description}"
|
|
105
|
+
if command.long_description
|
|
106
|
+
@@output.puts
|
|
107
|
+
@@output.puts " #{wrap(command.long_description,4)}"
|
|
108
|
+
end
|
|
109
|
+
all_options = command.switches.merge(command.flags)
|
|
110
|
+
if !all_options.empty?
|
|
111
|
+
@@output.puts
|
|
112
|
+
@@output.puts "Command Options:"
|
|
113
|
+
output_command_tokens_for_help(all_options)
|
|
114
|
+
end
|
|
115
|
+
else
|
|
116
|
+
@@output.puts "No such command #{command_name}"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def output_command_tokens_for_help(tokens,usage_name=:usage)
|
|
121
|
+
max = 0
|
|
122
|
+
tokens.values.each do |token|
|
|
123
|
+
len = token.send(usage_name).length
|
|
124
|
+
if len > max
|
|
125
|
+
max = len
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
names = tokens.keys.sort { |x,y| x.to_s <=> y.to_s }
|
|
129
|
+
names.each do |name|
|
|
130
|
+
token = tokens[name]
|
|
131
|
+
description = token.description || ''
|
|
132
|
+
if token.kind_of? Flag
|
|
133
|
+
description += " (default: #{token.default_value})" if token.default_value
|
|
134
|
+
end
|
|
135
|
+
description = wrap(description,max+7)
|
|
136
|
+
string = sprintf " %-#{max}s - %s",token.send(usage_name),description
|
|
137
|
+
@@output.puts string
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
private
|
|
143
|
+
|
|
144
|
+
# Wraps the line at the given column length, using the given line padding.
|
|
145
|
+
# Assumes that the first line doesn't need the padding, as its filled
|
|
146
|
+
# up with other stuff
|
|
147
|
+
def wrap(line,pad_length=0,line_length=nil)
|
|
148
|
+
if line_length.nil?
|
|
149
|
+
line_length = Terminal.instance.size[0]
|
|
150
|
+
end
|
|
151
|
+
line_padding = sprintf("%#{pad_length}s",'')
|
|
152
|
+
words = line.split(/\s+/)
|
|
153
|
+
return line if !words || words.empty?
|
|
154
|
+
wrapped = ''
|
|
155
|
+
while wrapped.length + line_padding.length < line_length
|
|
156
|
+
wrapped += ' ' if wrapped.length > 0
|
|
157
|
+
word = words.shift
|
|
158
|
+
if (wrapped.length + line_padding.length + word.length > line_length)
|
|
159
|
+
words.unshift word
|
|
160
|
+
break;
|
|
161
|
+
end
|
|
162
|
+
wrapped += word
|
|
163
|
+
return wrapped if words.empty?
|
|
164
|
+
end
|
|
165
|
+
wrapped += "\n"
|
|
166
|
+
this_line = line_padding
|
|
167
|
+
words.each do |word|
|
|
168
|
+
if this_line.length + word.length > line_length
|
|
169
|
+
wrapped += this_line
|
|
170
|
+
wrapped += "\n"
|
|
171
|
+
this_line = line_padding + word
|
|
172
|
+
else
|
|
173
|
+
this_line += ' ' if this_line.length > line_padding.length
|
|
174
|
+
this_line += word
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
wrapped.chomp!
|
|
178
|
+
wrapped + "\n" + this_line
|
|
179
|
+
end
|
|
180
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'gli'
|
|
2
|
+
require 'gli/command'
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module GLI
|
|
6
|
+
class InitConfig < Command # :nodoc:
|
|
7
|
+
COMMANDS_KEY = 'commands'
|
|
8
|
+
|
|
9
|
+
def initialize(config_file_name)
|
|
10
|
+
@filename = config_file_name
|
|
11
|
+
super(:initconfig,"Initialize the config file using current global options",nil,'Initializes a configuration file where you can set default options for command line flags, both globally and on a per-command basis. These defaults override the built-in defaults and allow you to omit commonly-used command line flags when invoking this program')
|
|
12
|
+
|
|
13
|
+
self.desc 'force overwrite of existing config file'
|
|
14
|
+
self.switch :force
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def execute(global_options,options,arguments)
|
|
18
|
+
if options[:force] || !File.exist?(@filename)
|
|
19
|
+
config = global_options
|
|
20
|
+
config[COMMANDS_KEY] = {}
|
|
21
|
+
GLI.commands.each do |name,command|
|
|
22
|
+
if (command != self) && (name != :rdoc) && (name != :help)
|
|
23
|
+
config[COMMANDS_KEY][name.to_sym] = {} if command != self
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
File.open(@filename,'w') do |file|
|
|
27
|
+
YAML.dump(config,file)
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
raise "Not overwriting existing config file #{@filename}, use --force to override"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
require 'gli'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
module GLI
|
|
5
|
+
class RDocCommand < Command # :nodoc:
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
super(:rdoc,'Generates RDoc (and other types of documentation) for your command line interface')
|
|
9
|
+
self.desc 'Create a very basic scaffold for a cheat-style cheatsheet, in addition to rdoc'
|
|
10
|
+
self.switch 'cheatsheet'
|
|
11
|
+
self.desc 'Include a manapage suitable for gem man, in addition to rdoc'
|
|
12
|
+
self.switch 'manpage'
|
|
13
|
+
self.desc 'Do not create rdoc'
|
|
14
|
+
self.switch 'no-rdoc'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def execute(g,options,a)
|
|
18
|
+
create_rdoc unless options[:'no-rdoc']
|
|
19
|
+
create_manpage if options[:manpage]
|
|
20
|
+
create_cheatsheet if options[:cheatsheet]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create_cheatsheet
|
|
24
|
+
File.open("#{GLI.program_name}.cheat",'w') do |file|
|
|
25
|
+
file << GLI.program_name
|
|
26
|
+
file << "\n"
|
|
27
|
+
file << GLI.program_name.length.times.inject("") { |a,x| a + "=" }
|
|
28
|
+
file << "\n"
|
|
29
|
+
file << "\n"
|
|
30
|
+
file << "Installation:\n"
|
|
31
|
+
file << "$ gem install #{GLI.program_name}\n\n"
|
|
32
|
+
GLI.commands.values.sort.each do |command|
|
|
33
|
+
next if command == self
|
|
34
|
+
file << command.description
|
|
35
|
+
file << "\n"
|
|
36
|
+
[command.name,command.aliases].flatten.each do |name|
|
|
37
|
+
next unless name
|
|
38
|
+
file << "$ #{GLI.program_name} #{name} #{command.arguments_description}\n"
|
|
39
|
+
end
|
|
40
|
+
file << "\n"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def create_manpage
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def create_rdoc
|
|
49
|
+
File.open("#{GLI.program_name}.rdoc",'w') do |file|
|
|
50
|
+
file << "= <tt>#{GLI.program_name}</tt>\n\n"
|
|
51
|
+
if GLI.program_desc
|
|
52
|
+
file << GLI.program_desc
|
|
53
|
+
file << "\n\n"
|
|
54
|
+
end
|
|
55
|
+
file << " "
|
|
56
|
+
file << GLI.program_name
|
|
57
|
+
file << " "
|
|
58
|
+
global_options = GLI.switches.merge(GLI.flags)
|
|
59
|
+
if (global_options && global_options.length > 0)
|
|
60
|
+
file << "[global options] "
|
|
61
|
+
end
|
|
62
|
+
file << "command_name"
|
|
63
|
+
file << " [command-specific options]"
|
|
64
|
+
file << " [--] arguments...\n\n"
|
|
65
|
+
file << "* Use the command +help+ to get a summary of commands\n"
|
|
66
|
+
file << "* Use the command <tt>help command_name</tt> to get a help for +command_name+\n"
|
|
67
|
+
file << "* Use <tt>--</tt> to stop command line argument processing; useful if your arguments have dashes in them\n"
|
|
68
|
+
file << "\n"
|
|
69
|
+
if (global_options && global_options.length > 0)
|
|
70
|
+
file << "== Global Options\n"
|
|
71
|
+
file << "These options are available for any command and are specified before the name of the command\n\n"
|
|
72
|
+
output_flags(file,global_options)
|
|
73
|
+
end
|
|
74
|
+
file << "== Commands\n"
|
|
75
|
+
GLI.commands.values.sort.each do |command|
|
|
76
|
+
next if command == self
|
|
77
|
+
file << "[<tt>#{command.name}</tt>] #{command.description}\n"
|
|
78
|
+
end
|
|
79
|
+
file << "\n"
|
|
80
|
+
|
|
81
|
+
GLI.commands.values.sort.each do |command|
|
|
82
|
+
next if command == self
|
|
83
|
+
file << "=== <tt>#{command.name} #{command.arguments_description}</tt>\n\n"
|
|
84
|
+
file << "#{command.description}\n\n"
|
|
85
|
+
if command.aliases
|
|
86
|
+
file << "*Aliases*\n"
|
|
87
|
+
command.aliases.each do |al|
|
|
88
|
+
file << "* <tt><b>#{al}</b></tt>\n"
|
|
89
|
+
end
|
|
90
|
+
file << "\n"
|
|
91
|
+
end
|
|
92
|
+
all_options = command.switches.merge(command.flags)
|
|
93
|
+
file << "#{command.long_description}\n\n" if command.long_description
|
|
94
|
+
if (all_options && all_options.length > 0)
|
|
95
|
+
file << "==== Options\n"
|
|
96
|
+
file << "These options are specified *after* the command.\n\n"
|
|
97
|
+
output_flags(file,all_options)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def output_flags(file,flags)
|
|
104
|
+
flags.values.sort.each do |flag|
|
|
105
|
+
file << "[<tt>#{flag.usage}</tt>] #{flag.description}"
|
|
106
|
+
if flag.kind_of? Flag
|
|
107
|
+
file << " <i>( default: <tt>#{flag.default_value}</tt>)</i>" if flag.default_value
|
|
108
|
+
end
|
|
109
|
+
file << "\n"
|
|
110
|
+
if flag.long_description
|
|
111
|
+
file << "\n"
|
|
112
|
+
# 12 is: 4 for tt, 5 for /tt, 2 for the brackets and 1 for spacing
|
|
113
|
+
(flag.usage.length + 12).times { file << " " }
|
|
114
|
+
file << "#{flag.long_description}\n\n"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
require 'gli'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
module GLI
|
|
5
|
+
class Scaffold #:nodoc:
|
|
6
|
+
|
|
7
|
+
def self.create_scaffold(root_dir,create_test_dir,create_ext_dir,project_name,commands,force=false,dry_run=false)
|
|
8
|
+
dirs = [File.join(root_dir,project_name,'lib')]
|
|
9
|
+
dirs << File.join(root_dir,project_name,'bin')
|
|
10
|
+
dirs << File.join(root_dir,project_name,'test') if create_test_dir
|
|
11
|
+
dirs << File.join(root_dir,project_name,'ext') if create_ext_dir
|
|
12
|
+
|
|
13
|
+
if mkdirs(dirs,force,dry_run)
|
|
14
|
+
mk_binfile(root_dir,create_ext_dir,force,dry_run,project_name,commands)
|
|
15
|
+
mk_readme(root_dir,dry_run,project_name)
|
|
16
|
+
mk_gemspec(root_dir,dry_run,project_name)
|
|
17
|
+
mk_rakefile(root_dir,dry_run,project_name,create_test_dir)
|
|
18
|
+
mk_version(root_dir,dry_run,project_name)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.mk_readme(root_dir,dry_run,project_name)
|
|
23
|
+
return if dry_run
|
|
24
|
+
File.open("#{root_dir}/#{project_name}/README.rdoc",'w') do |file|
|
|
25
|
+
file << "= #{project_name}\n\n"
|
|
26
|
+
file << "Describe your project here\n\n"
|
|
27
|
+
file << ":include:#{project_name}.rdoc\n\n"
|
|
28
|
+
end
|
|
29
|
+
puts "Created #{root_dir}/#{project_name}/README.rdoc"
|
|
30
|
+
File.open("#{root_dir}/#{project_name}/#{project_name}.rdoc",'w') do |file|
|
|
31
|
+
file << "= #{project_name}\n\n"
|
|
32
|
+
file << "Generate this with\n #{project_name} rdoc\nAfter you have described your command line interface"
|
|
33
|
+
end
|
|
34
|
+
puts "Created #{root_dir}/#{project_name}/#{project_name}.rdoc"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.mk_gemspec(root_dir,dry_run,project_name)
|
|
38
|
+
return if dry_run
|
|
39
|
+
File.open("#{root_dir}/#{project_name}/#{project_name}.gemspec",'w') do |file|
|
|
40
|
+
file.puts <<EOS
|
|
41
|
+
# Ensure we require the local version and not one we might have installed already
|
|
42
|
+
require File.join([File.dirname(__FILE__),'lib','#{project_name}_version.rb'])
|
|
43
|
+
spec = Gem::Specification.new do |s|
|
|
44
|
+
s.name = '#{project_name}'
|
|
45
|
+
s.version = #{project_name_as_module_name(project_name)}::VERSION
|
|
46
|
+
s.author = 'Your Name Here'
|
|
47
|
+
s.email = 'your@email.address.com'
|
|
48
|
+
s.homepage = 'http://your.website.com'
|
|
49
|
+
s.platform = Gem::Platform::RUBY
|
|
50
|
+
s.summary = 'A description of your project'
|
|
51
|
+
# Add your other files here if you make them
|
|
52
|
+
s.files = %w(
|
|
53
|
+
bin/#{project_name}
|
|
54
|
+
)
|
|
55
|
+
s.require_paths << 'lib'
|
|
56
|
+
s.has_rdoc = true
|
|
57
|
+
s.extra_rdoc_files = ['README.rdoc','#{project_name}.rdoc']
|
|
58
|
+
s.rdoc_options << '--title' << '#{project_name}' << '--main' << 'README.rdoc' << '-ri'
|
|
59
|
+
s.bindir = 'bin'
|
|
60
|
+
s.executables << '#{project_name}'
|
|
61
|
+
s.add_development_dependency('rake')
|
|
62
|
+
s.add_development_dependency('rdoc')
|
|
63
|
+
end
|
|
64
|
+
EOS
|
|
65
|
+
end
|
|
66
|
+
puts "Created #{root_dir}/#{project_name}/#{project_name}.gemspec"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.project_name_as_module_name(project_name)
|
|
70
|
+
project_name.split(/_/).map { |part| part[0..0].upcase + part[1..-1] }.join('')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.mk_version(root_dir,dry_run,project_name)
|
|
74
|
+
return if dry_run
|
|
75
|
+
File.open("#{root_dir}/#{project_name}/lib/#{project_name}_version.rb",'w') do |file|
|
|
76
|
+
file.puts <<EOS
|
|
77
|
+
module #{project_name_as_module_name(project_name)}
|
|
78
|
+
VERSION = '0.0.1'
|
|
79
|
+
end
|
|
80
|
+
EOS
|
|
81
|
+
end
|
|
82
|
+
puts "Created #{root_dir}/#{project_name}/lib/#{project_name}_version.rb"
|
|
83
|
+
end
|
|
84
|
+
def self.mk_rakefile(root_dir,dry_run,project_name,create_test_dir)
|
|
85
|
+
return if dry_run
|
|
86
|
+
File.open("#{root_dir}/#{project_name}/Rakefile",'w') do |file|
|
|
87
|
+
file.puts <<EOS
|
|
88
|
+
require 'rake/clean'
|
|
89
|
+
require 'rubygems'
|
|
90
|
+
require 'rake/gempackagetask'
|
|
91
|
+
require 'rake/rdoctask'
|
|
92
|
+
|
|
93
|
+
Rake::RDocTask.new do |rd|
|
|
94
|
+
rd.main = "README.rdoc"
|
|
95
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
|
96
|
+
rd.title = 'Your application title'
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
spec = eval(File.read('#{project_name}.gemspec'))
|
|
100
|
+
|
|
101
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
EOS
|
|
105
|
+
if create_test_dir
|
|
106
|
+
file.puts <<EOS
|
|
107
|
+
require 'rake/testtask'
|
|
108
|
+
Rake::TestTask.new do |t|
|
|
109
|
+
t.libs << "test"
|
|
110
|
+
t.test_files = FileList['test/tc_*.rb']
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
task :default => :test
|
|
114
|
+
EOS
|
|
115
|
+
File.open("#{root_dir}/#{project_name}/test/tc_nothing.rb",'w') do |test_file|
|
|
116
|
+
test_file.puts <<EOS
|
|
117
|
+
require 'test/unit'
|
|
118
|
+
|
|
119
|
+
class TC_testNothing < Test::Unit::TestCase
|
|
120
|
+
|
|
121
|
+
def setup
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def teardown
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_the_truth
|
|
128
|
+
assert true
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
EOS
|
|
132
|
+
end
|
|
133
|
+
puts "Created #{root_dir}/#{project_name}/test/tc_nothing.rb"
|
|
134
|
+
else
|
|
135
|
+
file.puts "task :default => :package\n"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
puts "Created #{root_dir}/#{project_name}/Rakefile"
|
|
139
|
+
File.open("#{root_dir}/#{project_name}/Gemfile",'w') do |bundler_file|
|
|
140
|
+
bundler_file.puts "source :rubygems"
|
|
141
|
+
bundler_file.puts "gemspec"
|
|
142
|
+
end
|
|
143
|
+
puts "Created #{root_dir}/#{project_name}/Gemfile"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def self.mk_binfile(root_dir,create_ext_dir,force,dry_run,project_name,commands)
|
|
147
|
+
bin_file = File.join(root_dir,project_name,'bin',project_name)
|
|
148
|
+
if !File.exist?(bin_file) || force
|
|
149
|
+
if !dry_run
|
|
150
|
+
File.open(bin_file,'w') do |file|
|
|
151
|
+
file.chmod(0755)
|
|
152
|
+
file.puts '#!/usr/bin/env ruby'
|
|
153
|
+
file.puts <<EOS
|
|
154
|
+
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
|
|
155
|
+
# have this method, so we add it so we get resolved symlinks
|
|
156
|
+
# and compatibility
|
|
157
|
+
unless File.respond_to? :realpath
|
|
158
|
+
class File #:nodoc:
|
|
159
|
+
def self.realpath path
|
|
160
|
+
return realpath(File.readlink(path)) if symlink?(path)
|
|
161
|
+
path
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
EOS
|
|
166
|
+
file.puts '$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + \'/../lib\')'
|
|
167
|
+
file.puts '$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + \'/../ext\')' if create_ext_dir
|
|
168
|
+
file.puts <<EOS
|
|
169
|
+
require 'rubygems'
|
|
170
|
+
require 'gli'
|
|
171
|
+
require '#{project_name}_version'
|
|
172
|
+
|
|
173
|
+
include GLI
|
|
174
|
+
|
|
175
|
+
program_desc 'Describe your application here'
|
|
176
|
+
|
|
177
|
+
version #{project_name_as_module_name(project_name)}::VERSION
|
|
178
|
+
|
|
179
|
+
desc 'Describe some switch here'
|
|
180
|
+
switch [:s,:switch]
|
|
181
|
+
|
|
182
|
+
desc 'Describe some flag here'
|
|
183
|
+
default_value 'the default'
|
|
184
|
+
arg_name 'The name of the argument'
|
|
185
|
+
flag [:f,:flagname]
|
|
186
|
+
EOS
|
|
187
|
+
first = true
|
|
188
|
+
commands.each do |command|
|
|
189
|
+
file.puts <<EOS
|
|
190
|
+
|
|
191
|
+
desc 'Describe #{command} here'
|
|
192
|
+
arg_name 'Describe arguments to #{command} here'
|
|
193
|
+
EOS
|
|
194
|
+
if first
|
|
195
|
+
file.puts <<EOS
|
|
196
|
+
command :#{command} do |c|
|
|
197
|
+
c.desc 'Describe a switch to #{command}'
|
|
198
|
+
c.switch :s
|
|
199
|
+
|
|
200
|
+
c.desc 'Describe a flag to #{command}'
|
|
201
|
+
c.default_value 'default'
|
|
202
|
+
c.flag :f
|
|
203
|
+
c.action do |global_options,options,args|
|
|
204
|
+
|
|
205
|
+
# Your command logic here
|
|
206
|
+
|
|
207
|
+
# If you have any errors, just raise them
|
|
208
|
+
# raise "that command made no sense"
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
EOS
|
|
212
|
+
else
|
|
213
|
+
file.puts <<EOS
|
|
214
|
+
command :#{command} do |c|
|
|
215
|
+
c.action do |global_options,options,args|
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
EOS
|
|
219
|
+
end
|
|
220
|
+
first = false
|
|
221
|
+
end
|
|
222
|
+
file.puts <<EOS
|
|
223
|
+
|
|
224
|
+
pre do |global,command,options,args|
|
|
225
|
+
# Pre logic here
|
|
226
|
+
# Return true to proceed; false to abourt and not call the
|
|
227
|
+
# chosen command
|
|
228
|
+
# Use skips_pre before a command to skip this block
|
|
229
|
+
# on that command only
|
|
230
|
+
true
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
post do |global,command,options,args|
|
|
234
|
+
# Post logic here
|
|
235
|
+
# Use skips_post before a command to skip this
|
|
236
|
+
# block on that command only
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
on_error do |exception|
|
|
240
|
+
# Error logic here
|
|
241
|
+
# return false to skip default error handling
|
|
242
|
+
true
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
exit GLI.run(ARGV)
|
|
246
|
+
EOS
|
|
247
|
+
puts "Created #{bin_file}"
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
else
|
|
251
|
+
puts bin_file + " exists; use --force to override"
|
|
252
|
+
return false
|
|
253
|
+
end
|
|
254
|
+
true
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def self.mkdirs(dirs,force,dry_run)
|
|
258
|
+
exists = false
|
|
259
|
+
if !force
|
|
260
|
+
dirs.each do |dir|
|
|
261
|
+
if File.exist? dir
|
|
262
|
+
raise "#{dir} exists; use --force to override"
|
|
263
|
+
exists = true
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
if !exists
|
|
268
|
+
dirs.each do |dir|
|
|
269
|
+
puts "Creating dir #{dir}..."
|
|
270
|
+
if dry_run
|
|
271
|
+
puts "dry-run; #{dir} not created"
|
|
272
|
+
else
|
|
273
|
+
FileUtils.mkdir_p dir
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
else
|
|
277
|
+
puts "Exiting..."
|
|
278
|
+
return false
|
|
279
|
+
end
|
|
280
|
+
true
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
end
|
|
284
|
+
end
|