Class: Bones::App::Main
Constant Summary
Constants included from Colors
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#help ⇒ Object
Show the toplevel Mr Bones help message.
-
#initialize(opts = {}) ⇒ Main
constructor
Create a new Main application instance.
-
#run(args) ⇒ Object
Parse the desired user command and run that command object.
Methods included from Colors
Constructor Details
#initialize(opts = {}) ⇒ Main
Create a new Main application instance. Options can be passed to configuret he stdout and stderr IO streams (very useful for testing).
27 28 29 30 31 32 33 34 |
# File 'lib/bones/app.rb', line 27 def initialize( opts = {} ) opts[:stdout] ||= $stdout opts[:stderr] ||= $stderr @opts = opts @stdout = opts[:stdout] @stderr = opts[:stderr] end |
Instance Attribute Details
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
22 23 24 |
# File 'lib/bones/app.rb', line 22 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
21 22 23 |
# File 'lib/bones/app.rb', line 21 def stdout @stdout end |
Instance Method Details
#help ⇒ Object
Show the toplevel Mr Bones help message.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bones/app.rb', line 73 def help msg = <<-MSG NAME bones v#{::Bones.version} DESCRIPTION Mr Bones is a handy tool that builds a skeleton for your new Ruby projects. The skeleton contains some starter code and a collection of rake tasks to ease the management and deployment of your source code. Usage: bones -h/--help bones -v/--version bones command [options] [arguments] Examples: bones create new_project bones freeze -r git://github.com/fudgestudios/bort.git bort bones create -s bort new_rails_project Commands: MSG fmt = lambda { |cmd| if @plugins[cmd] < ::Bones::App::Command msg << " bones %-15s %s\n" % [cmd, @plugins[cmd].summary] end } ary = [:create, :freeze, :unfreeze, :info, :plugins] ary.each(&fmt) (@plugins.keys - ary).each(&fmt) msg.concat <<-MSG Further Help: Each command has a '--help' option that will provide detailed information for that command. http://github.com/TwP/bones MSG stdout.puts msg end |
#run(args) ⇒ Object
Parse the desired user command and run that command object.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bones/app.rb', line 38 def run( args ) commands = [] @plugins = ::Bones::App.plugins @plugins.each { |k,v| commands << k.to_s if v < ::Bones::App::Command } cmd_str = args.shift cmd = case cmd_str when *commands key = cmd_str.to_sym @plugins[key].new @opts when nil, '-h', '--help' help when '-v', '--version' stdout.puts "Mr Bones v#{::Bones.version}" else raise Error, "Unknown command #{cmd_str.inspect}" end if cmd cmd.parse args cmd.run end rescue Bones::App::Error => err stderr.puts "#{colorize('ERROR', :white, :on_red)}: While executing bones ..." stderr.puts " #{err..split("\n").join("\n ")}" exit 1 rescue StandardError => err stderr.puts "#{colorize('ERROR', :white, :on_red)}: While executing bones ... (#{colorize(err.class, :red)})" stderr.puts " #{err.to_s}" exit 1 end |