Module: Boson::Commands::Core
Overview
:nodoc:
Instance Method Summary collapse
- #commands(options = {}) ⇒ Object
- #config ⇒ Object
- #libraries(options = {}) ⇒ Object
- #load_library(library, options = {}) ⇒ Object
- #menu(arr, options = {}, &block) ⇒ Object
- #render(object, options = {}) ⇒ Object
- #usage(command, options = {}) ⇒ Object
Instance Method Details
#commands(options = {}) ⇒ Object
41 42 43 44 |
# File 'lib/boson/commands/core.rb', line 41 def commands(={}) cmds = [:index] ? (Boson::Index.read || true) && Boson::Index.commands : Boson.commands [:local] ? cmds.select {|e| e.library && e.library.local? } : cmds end |
#config ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/boson/commands/core.rb', line 4 def config command_attributes = Boson::Command::ATTRIBUTES + [:usage, :full_name, :render_options] 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=>{: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, :default=> true, :desc=>"Local commands only" } }, :render_options=>{ [: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}} } }, 'libraries'=>{ :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, :enum=>false}, :filters=>{:default=>{:gems=>[:join, ','],:commands=>:size}, :desc=>"Filters to apply to library fields" }} }, 'load_library'=>{:desc=>"Load a library", :options=>{[:verbose,:V]=>true}} } {:namespace=>false, :library_file=>File.(__FILE__), :commands=>commands} end |
#libraries(options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/boson/commands/core.rb', line 46 def libraries(={}) libs = [:index] ? (Boson::Index.read || true) && Boson::Index.libraries : Boson.libraries [:local] ? libs.select {|e| e.local? } : libs end |
#load_library(library, options = {}) ⇒ Object
51 52 53 |
# File 'lib/boson/commands/core.rb', line 51 def load_library(library, ={}) Boson::Manager.load(library, ) end |
#menu(arr, options = {}, &block) ⇒ Object
59 60 61 |
# File 'lib/boson/commands/core.rb', line 59 def (arr, ={}, &block) Hirb::Console.format_output(arr, .merge(:class=>"Hirb::Menu"), &block) end |
#render(object, options = {}) ⇒ Object
55 56 57 |
# File 'lib/boson/commands/core.rb', line 55 def render(object, ={}) Boson::View.render(object, ) end |
#usage(command, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/boson/commands/core.rb', line 63 def usage(command, ={}) puts Boson::Command.usage(command) if (cmd = Boson::Command.find(command)) if cmd. && !cmd..empty? puts "\nLOCAL OPTIONS" cmd.option_parser.print_usage_table [:render_options].dup.merge(:local=>true) end if [:verbose] && cmd.render_option_parser puts "\nGLOBAL OPTIONS" cmd.render_option_parser.print_usage_table [:render_options].dup end end end |