drydock 0.5.4 → 0.5.5

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.
Files changed (3) hide show
  1. data/drydock.gemspec +2 -2
  2. data/lib/drydock.rb +54 -13
  3. metadata +5 -3
data/drydock.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = %q{drydock}
3
- s.version = "0.5.4"
4
- s.date = %q{2009-04-15}
3
+ s.version = "0.5.5"
4
+ s.date = %q{2009-04-19}
5
5
  s.specification_version = 1 if s.respond_to? :specification_version=
6
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
7
 
data/lib/drydock.rb CHANGED
@@ -40,7 +40,7 @@ module Drydock
40
40
  @msg = args.shift if args.size == 1
41
41
  @arg, @cmd, @msg = *args
42
42
  @cmd ||= 'COMMAND'
43
- @msg = nil if @msg.empty?
43
+ @msg = nil if @msg && @msg.empty?
44
44
  end
45
45
  def message; @msg || "Error: No #{@arg} provided"; end
46
46
  def usage; "See: #{$0} #{@cmd} -h"; end
@@ -98,6 +98,8 @@ module Drydock
98
98
  attr_accessor :argv
99
99
  # Either an IO handle to STDIN or the output of the Drydock#stdin handler.
100
100
  attr_reader :stdin
101
+ # The basename of the executable or script: File.basename($0)
102
+ attr_reader :executable
101
103
 
102
104
  # The default constructor sets the short name of the command
103
105
  # and stores a reference to the block (if supplied).
@@ -114,7 +116,7 @@ module Drydock
114
116
  @stdin = STDIN
115
117
  @option = OpenStruct.new
116
118
  @global = OpenStruct.new
117
-
119
+ @executable = File.basename($0)
118
120
  @global.verbose = 0
119
121
  @global.quiet = false
120
122
  end
@@ -241,11 +243,15 @@ module Drydock
241
243
  # "default" command unless another default commands is supplied. You
242
244
  # can also write your own Drydock::Command#show_commands to override
243
245
  # this default behaviour.
246
+ #
247
+ # The output was worked on here:
248
+ # http://etherpad.com/SXjqQGRr8M
249
+ #
244
250
  def show_commands
245
251
  project = " for #{Drydock.project}" if Drydock.project?
246
- puts "Available commands#{project}:", ""
247
252
  cmds = {}
248
253
  Drydock.commands.keys.each do |cmd|
254
+ next if cmd == :show_commands
249
255
  pretty = Drydock.decanonize(cmd)
250
256
  # Out to sea
251
257
  cmds[Drydock.commands[cmd].cmd] ||= {}
@@ -254,19 +260,52 @@ module Drydock
254
260
  next
255
261
  end
256
262
  cmds[cmd][:desc] = Drydock.commands[cmd].desc
263
+ cmds[cmd][:desc] = nil if cmds[cmd][:desc] && cmds[cmd][:desc].empty?
257
264
  cmds[cmd][:pretty] = pretty
258
265
  end
266
+
267
+ cmd_names_sorted = cmds.keys.sort{ |a,b| a.to_s <=> b.to_s }
259
268
 
260
- cmds.keys.sort{ |a,b| a.to_s <=> b.to_s }.each do |cmd|
261
- p = cmds[cmd]
262
- puts " %16s: %s" % [p[:pretty], p[:desc]]
263
- puts " %17s (%s: %s)" % ['', "aliases", cmds[cmd][:aliases].join(', ')] if cmds[cmd][:aliases]
269
+
270
+ if @global.quiet
271
+ puts "Commands: "
272
+ line = []
273
+ cmd_names_sorted.each_with_index do |cmd,i|
274
+ line << cmd
275
+ if (line.size % 4 == 0) || i == (cmd_names_sorted.size - 1)
276
+ puts " %s" % line.join(', ')
277
+ line.clear
278
+ end
279
+ end
280
+ return
264
281
  end
265
282
 
266
- puts
267
- puts "%6s: %s" % ["Try", "#{$0} -h"]
268
- puts "%6s %s" % ["", "#{$0} COMMAND -h"]
283
+ puts "%5s: %s" % ["Usage", "#{@executable} [global options] COMMAND [command options]"]
284
+ puts "%5s: %s" % ["Try", "#{@executable} -h"]
285
+ puts "%5s %s" % ["", "#{@executable} COMMAND -h"]
269
286
  puts
287
+
288
+ puts "Commands: "
289
+ if @global.verbose > 0
290
+ puts # empty line
291
+ cmd_names_sorted.each do |cmd|
292
+ puts "%s %s" % [@executable, cmds[cmd][:pretty]]
293
+ puts "%10s: %s" % ["About", cmds[cmd][:desc]] if cmds[cmd][:desc]
294
+ if cmds[cmd][:aliases]
295
+ cmds[cmd][:aliases].sort!{ |a,b| a.size <=> b.size }
296
+ puts "%10s: %s" % ["Aliases", cmds[cmd][:aliases].join(', ')]
297
+ end
298
+ puts
299
+ end
300
+
301
+ else
302
+ cmd_names_sorted.each do |cmd|
303
+ aliases = cmds[cmd][:aliases] || []
304
+ aliases.sort!{ |a,b| a.size <=> b.size }
305
+ aliases = aliases.empty? ? '' : "(aliases: #{aliases.join(', ')})"
306
+ puts " %-16s %s" % [cmds[cmd][:pretty], aliases]
307
+ end
308
+ end
270
309
  end
271
310
 
272
311
  # The name of the command
@@ -565,7 +604,9 @@ module Drydock
565
604
  # Default Usage Banner.
566
605
  # Without this, there's no help displayed for the command.
567
606
  option_parser = get_option_parser(@@command_index)
568
- usage "#{$0} #{c.cmd}" if option_parser.is_a?(OptionParser) && option_parser.banner !~ /^USAGE/
607
+ if option_parser.is_a?(OptionParser) && option_parser.banner !~ /^USAGE/
608
+ usage "#{c.executable} #{c.cmd}"
609
+ end
569
610
 
570
611
  @@commands[c.cmd] = c
571
612
  @@command_index_map[c.cmd] = @@command_index
@@ -835,8 +876,8 @@ module Drydock
835
876
  #
836
877
  # These are the "reel" defaults
837
878
  #
838
- @@global_opts_parser.banner = "USAGE: #{$0} [global options] COMMAND [command options]"
839
- @@global_opts_parser.on " TRY: #{$0} show-commands #{$/}"
879
+ @@global_opts_parser.banner = " Try: #{$0} show-commands"
880
+ @@global_opts_parser.on "Usage: #{$0} [global options] COMMAND [command options] #{$/}"
840
881
  @@command_descriptions = ["Display available commands with descriptions"]
841
882
  @@default_command = Drydock.command(:show_commands).cmd
842
883
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drydock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-15 00:00:00 -04:00
12
+ date: 2009-04-19 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -33,6 +33,8 @@ files:
33
33
  - lib/drydock.rb
34
34
  has_rdoc: true
35
35
  homepage: http://github.com/delano/drydock
36
+ licenses: []
37
+
36
38
  post_install_message:
37
39
  rdoc_options:
38
40
  - --line-numbers
@@ -57,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
59
  requirements: []
58
60
 
59
61
  rubyforge_project: drydock
60
- rubygems_version: 1.3.1
62
+ rubygems_version: 1.3.2
61
63
  signing_key:
62
64
  specification_version: 1
63
65
  summary: A seaworthy DSL for writing command line apps