lib/boson/commands/core.rb in boson-0.2.1 vs lib/boson/commands/core.rb in boson-0.2.2

- old
+ new

@@ -4,40 +4,47 @@ def config command_attributes = Boson::Command::ATTRIBUTES + [:usage, :full_name, :render_options] library_attributes = Boson::Library::ATTRIBUTES + [:library_type] commands = { - 'render'=>{:description=>"Render any object using Hirb"}, - 'menu'=>{:description=>"Provide a menu to multi-select elements from a given array"}, - 'usage'=>{:description=>"Print a command's usage", :options=>{[:verbose, :V]=>:boolean}}, + '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}}, 'commands'=>{ - :description=>"List or search commands", :default_option=>'query', - :options=>{ :index=>{:type=>:boolean, :desc=>"Searches index"}}, + :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'}}, :query=>{:keys=>command_attributes, :default_keys=>'full_name'}, - :fields=>{:default=>[:full_name, :lib, :alias, :usage, :description], :values=>command_attributes} } + :fields=>{:default=>[:full_name, :lib, :alias, :usage, :desc], :values=>command_attributes, :enum=>false}, + :filters=>{:default=>{:render_options=>:inspect, :options=>:inspect, :args=>:inspect, :config=>:inspect}} + } }, 'libraries'=>{ - :description=>"List or search libraries", :default_option=>'query', - :options=>{ :index=>{:type=>:boolean, :desc=>"Searches index"} }, + :desc=>"List or search libraries. Query must come before any options.", :default_option=>'query', + :options=>{ :index=>{:type=>:boolean, :desc=>"Searches index"}, + :local=>{:type=>:boolean, :desc=>"Local libraries only" } }, :render_options=>{ :query=>{:keys=>library_attributes, :default_keys=>'name'}, - :fields=>{:default=>[:name, :commands, :gems, :library_type], :values=>library_attributes}, + :fields=>{:default=>[:name, :commands, :gems, :library_type], :values=>library_attributes, :enum=>false}, :filters=>{:default=>{:gems=>[:join, ','],:commands=>:size}, :desc=>"Filters to apply to library fields" }} }, - 'load_library'=>{:description=>"Load a library", :options=>{[:verbose,:V]=>true}} + 'load_library'=>{:desc=>"Load a library", :options=>{[:verbose,:V]=>true}} } {:namespace=>false, :library_file=>File.expand_path(__FILE__), :commands=>commands} end def commands(options={}) - options[:index] ? (Boson::Index.read || true) && Boson::Index.commands : Boson.commands + cmds = options[:index] ? (Boson::Index.read || true) && Boson::Index.commands : Boson.commands + options[:local] ? cmds.select {|e| e.library && e.library.local? } : cmds end def libraries(options={}) - options[:index] ? (Boson::Index.read || true) && Boson::Index.libraries : Boson.libraries + libs = options[:index] ? (Boson::Index.read || true) && Boson::Index.libraries : Boson.libraries + options[:local] ? libs.select {|e| e.local? } : libs end def load_library(library, options={}) Boson::Manager.load(library, options) end @@ -48,18 +55,18 @@ def menu(output, options={}, &block) Hirb::Console.format_output(output, options.merge(:class=>"Hirb::Menu"), &block) end - def usage(name, options={}) - msg = (command = Boson::Command.find(name)) ? "#{name} #{command.usage}" : "Command '#{name}' not found" + def usage(command, options={}) + msg = (cmd = Boson::Command.find(command)) ? "#{command} #{cmd.usage}" : "Command '#{cmd}' not found" puts msg - if command && options[:verbose] - if command.options && !command.options.empty? + if cmd && options[:verbose] + if cmd.options && !cmd.options.empty? puts "\nLOCAL OPTIONS" - command.option_parser.print_usage_table + cmd.option_parser.print_usage_table end puts "\nGLOBAL OPTIONS" - Boson::Scientist.option_command(command).option_parser.print_usage_table + Boson::Scientist.option_command(cmd).option_parser.print_usage_table end end end \ No newline at end of file