Method: Drydock::Command#show_commands
- Defined in:
- lib/drydock.rb
#show_commands ⇒ Object
Print the list of available commands to STDOUT. This is used as the “default” command unless another default commands is supplied. You can also write your own Drydock::Command#show_commands to override this default behaviour.
The output was worked on here: etherpad.com/SXjqQGRr8M
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/drydock.rb', line 269 def show_commands project = " for #{Drydock.project}" if Drydock.project? cmds = {} Drydock.commands.keys.each do |cmd| next if cmd == :show_commands pretty = Drydock.decanonize(cmd) # Out to sea cmds[Drydock.commands[cmd].cmd] ||= {} unless cmd === Drydock.commands[cmd].cmd (cmds[Drydock.commands[cmd].cmd][:aliases] ||= []) << pretty next end cmds[cmd][:desc] = Drydock.commands[cmd].desc cmds[cmd][:desc] = nil if cmds[cmd][:desc] && cmds[cmd][:desc].empty? cmds[cmd][:pretty] = pretty end cmd_names_sorted = cmds.keys.sort{ |a,b| a.to_s <=> b.to_s } if @global.quiet puts 'Commands: ' line = [] cmd_names_sorted.each_with_index do |cmd,i| line << cmd if (line.size % 4 == 0) || i == (cmd_names_sorted.size - 1) puts " %s" % line.join(', ') line.clear end end return end puts '%5s: %s' % ['Usage', "#{@executable} [global options] COMMAND [command options]"] puts '%5s: %s' % ['Try', "#{@executable} -h"] puts '%5s %s' % ['', "#{@executable} COMMAND -h"] puts puts 'Commands: ' if @global.verbose.positive? puts # empty line cmd_names_sorted.each do |cmd| puts "$ %s" % [@executable] if Drydock.default?(cmd) puts "$ %s %s" % [@executable, cmds[cmd][:pretty]] puts "%10s: %s" % ["About", cmds[cmd][:desc]] if cmds[cmd][:desc] if cmds[cmd][:aliases] cmds[cmd][:aliases].sort!{ |a,b| a.size <=> b.size } puts "%10s: %s" % ["Aliases", cmds[cmd][:aliases].join(', ')] end puts end else cmd_names_sorted.each do |cmd| aliases = cmds[cmd][:aliases] || [] aliases.sort!{ |a,b| a.size <=> b.size } aliases = aliases.empty? ? '' : "(aliases: #{aliases.join(', ')})" pattern = Drydock.default?(cmd) ? "* %-16s %s" : " %-16s %s" puts pattern % [cmds[cmd][:pretty], aliases] end end end |