lib/boson/commands/core.rb in boson-0.2.2 vs lib/boson/commands/core.rb in boson-0.2.3
- old
+ new
@@ -6,17 +6,20 @@
library_attributes = Boson::Library::ATTRIBUTES + [:library_type]
commands = {
'render'=>{:desc=>"Render any object using Hirb"},
'menu'=>{:desc=>"Provide a menu to multi-select elements from a given array"},
- 'usage'=>{:desc=>"Print a command's usage", :options=>{[:verbose, :V]=>:boolean}},
+ 'usage'=>{:desc=>"Print a command's usage", :options=>{
+ :verbose=>{:desc=>"Display global options", :type=>:boolean},
+ :render_options=>{:desc=>"Render options for option tables", :default=>{},
+ :keys=>[:vertical, :fields, :hide_empty]} } },
'commands'=>{
:desc=>"List or search commands. Query must come before any options.", :default_option=>'query',
:options=>{ :index=>{:type=>:boolean, :desc=>"Searches index"},
:local=>{:type=>:boolean, :desc=>"Local commands only" } },
:render_options=>{
- :headers=>{:default=>{:desc=>'description'}},
+ [:headers,:H]=>{:default=>{:desc=>'description'}},
:query=>{:keys=>command_attributes, :default_keys=>'full_name'},
:fields=>{:default=>[:full_name, :lib, :alias, :usage, :desc], :values=>command_attributes, :enum=>false},
:filters=>{:default=>{:render_options=>:inspect, :options=>:inspect, :args=>:inspect, :config=>:inspect}}
}
},
@@ -51,22 +54,24 @@
def render(object, options={})
Boson::View.render(object, options)
end
- def menu(output, options={}, &block)
- Hirb::Console.format_output(output, options.merge(:class=>"Hirb::Menu"), &block)
+ def menu(arr, options={}, &block)
+ Hirb::Console.format_output(arr, options.merge(:class=>"Hirb::Menu"), &block)
end
def usage(command, options={})
- msg = (cmd = Boson::Command.find(command)) ? "#{command} #{cmd.usage}" : "Command '#{cmd}' not found"
+ msg = (cmd = Boson::Command.find(command)) ? "#{command} #{cmd.usage}" : "Command '#{command}' not found"
puts msg
- if cmd && options[:verbose]
- if cmd.options && !cmd.options.empty?
- puts "\nLOCAL OPTIONS"
- cmd.option_parser.print_usage_table
- end
+ return if options[:one_line] || !cmd
+
+ if cmd.options && !cmd.options.empty?
+ puts "\nLOCAL OPTIONS"
+ cmd.option_parser.print_usage_table options[:render_options].dup.merge(:local=>true)
+ end
+ if options[:verbose]
puts "\nGLOBAL OPTIONS"
- Boson::Scientist.option_command(cmd).option_parser.print_usage_table
+ cmd.render_option_parser.print_usage_table options[:render_options].dup
end
end
end
\ No newline at end of file