Class Boson::BinRunner

  1. lib/boson/runners/bin_runner.rb
Parent: Boson::Runner

This class handles the boson executable (boson command execution from the commandline). Any changes to your commands are immediately available from the commandline except for changes to the main config file. For those changes to take effect you need to explicitly load and index the libraries with —index. See RepoIndex to understand how Boson can immediately detect the latest commands.

Usage for the boson shell command looks like this:


The boson executable comes with these global options:

Gives a basic help of global options. When a command is given the help shifts to a command’s help.
Using this along with :help option shows more help. Also gives verbosity to other actions i.e. loading.
Like ruby -e, this executes a string of ruby code. However, this has the advantage that all commands are available as normal methods, automatically loading as needed. This is a good way to call commands that take non-string arguments.
This drops Boson into irb after having loaded default commands and any explict libraries with :load option. This is a good way to start irb with only certain libraries loaded.
Explicitly loads a list of libraries separated by commas. Most useful when used with :console option. Can also be used to explicitly load libraries that aren’t being detected automatically.
Updates index for given libraries allowing you to use them. This is useful if Boson’s autodetection of changed libraries isn’t picking up your changes. Since this option has a :bool_default attribute, arguments passed to this option need to be passed with ’=’ i.e. ’—index=my_lib’.
Toggles the auto-rendering done for commands that don’t have views. Doesn’t affect commands that already have views. Default is false. Also see Auto Rendering section below.
Toggles Hirb’s pager in case you’d like to pipe to another command.

Auto Rendering

Commands that don’t have views (defined via render_options) have their return value auto-rendered as a view as follows:

  • nil,false and true aren’t rendered
  • arrays are rendered with Hirb’s tables
  • non-arrays are printed with inspect()
  • Any of these cases can be toggled to render/not render with the global option :render

To turn off auto-rendering by default, add a :no_auto_render: true entry to the main config.


public class

  1. commands
  2. init
  3. options
  4. start


PIPE = '+'


command [RW]

Public class methods

commands ()

Commands to executed, in order given by user

[show source]
# File lib/boson/runners/bin_runner.rb, line 114
      def commands
        @commands ||= {|e| e[0]}
init ()

Loads libraries and handles non-critical options

[show source]
# File lib/boson/runners/bin_runner.rb, line 92
      def init
        Runner.in_shell = true
        Command.all_option_commands = true if @options[:option_commands]

        if @options.key?(:index)
          Index.update(:verbose=>true, :libraries=>@options[:index])
          @index_updated = true
        elsif !@options[:help] && @command && Boson.can_invoke?(@command)
          @index_updated = true
        Manager.load @options[:load], load_options if @options[:load]
        View.toggle_pager if @options[:pager_toggle]
options ()

Hash of global options passed in from commandline

[show source]
# File lib/boson/runners/bin_runner.rb, line 109
      def options
        @options ||= {}
start (args=ARGV)

Starts, processes and ends a commandline request.

[show source]
# File lib/boson/runners/bin_runner.rb, line 57
      def start(args=ARGV)
        @command, @options, @args = parse_args(args)
        return puts("boson #{Boson::VERSION}") if @options[:version]
        return print_usage if args.empty? || (@command.nil? && !@options[:console] && !@options[:execute])
        return ConsoleRunner.bin_start(@options[:console], @options[:load]) if @options[:console]

        if @options[:help]
          autoload_command @command
          Boson.invoke(:usage, @command, :verbose=>@options[:verbose])
        elsif @options[:execute]
          Boson.main_object.instance_eval @options[:execute]
      rescue NoMethodError
        print_error_message no_method_error_message
        print_error_message default_error_message