boson 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +6 -7
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.rdoc +1 -1
- data/README.md +144 -0
- data/README.rdoc +2 -2
- data/Upgrading.md +23 -0
- data/bin/boson +2 -2
- data/lib/boson.rb +44 -52
- data/lib/boson/bare_runner.rb +83 -0
- data/lib/boson/bin_runner.rb +114 -0
- data/lib/boson/command.rb +92 -132
- data/lib/boson/inspector.rb +49 -48
- data/lib/boson/library.rb +71 -120
- data/lib/boson/loader.rb +73 -84
- data/lib/boson/manager.rb +131 -135
- data/lib/boson/method_inspector.rb +112 -0
- data/lib/boson/option_command.rb +71 -154
- data/lib/boson/option_parser.rb +178 -173
- data/lib/boson/options.rb +46 -32
- data/lib/boson/runner.rb +58 -66
- data/lib/boson/runner_library.rb +31 -0
- data/lib/boson/scientist.rb +48 -81
- data/lib/boson/util.rb +46 -61
- data/lib/boson/version.rb +1 -1
- data/test/bin_runner_test.rb +53 -191
- data/test/command_test.rb +5 -9
- data/test/deps.rip +2 -2
- data/test/loader_test.rb +18 -216
- data/test/manager_test.rb +69 -79
- data/test/method_inspector_test.rb +12 -36
- data/test/option_parser_test.rb +45 -32
- data/test/runner_library_test.rb +10 -0
- data/test/runner_test.rb +158 -28
- data/test/scientist_test.rb +9 -147
- data/test/test_helper.rb +87 -52
- metadata +30 -72
- data/deps.rip +0 -2
- data/lib/boson/commands.rb +0 -7
- data/lib/boson/commands/core.rb +0 -77
- data/lib/boson/commands/web_core.rb +0 -153
- data/lib/boson/index.rb +0 -48
- data/lib/boson/inspectors/argument_inspector.rb +0 -97
- data/lib/boson/inspectors/comment_inspector.rb +0 -100
- data/lib/boson/inspectors/method_inspector.rb +0 -98
- data/lib/boson/libraries/file_library.rb +0 -144
- data/lib/boson/libraries/gem_library.rb +0 -30
- data/lib/boson/libraries/local_file_library.rb +0 -30
- data/lib/boson/libraries/module_library.rb +0 -37
- data/lib/boson/libraries/require_library.rb +0 -23
- data/lib/boson/namespace.rb +0 -31
- data/lib/boson/pipe.rb +0 -147
- data/lib/boson/pipes.rb +0 -75
- data/lib/boson/repo.rb +0 -107
- data/lib/boson/runners/bin_runner.rb +0 -208
- data/lib/boson/runners/console_runner.rb +0 -58
- data/lib/boson/view.rb +0 -95
- data/test/argument_inspector_test.rb +0 -62
- data/test/commands_test.rb +0 -22
- data/test/comment_inspector_test.rb +0 -126
- data/test/file_library_test.rb +0 -42
- data/test/pipes_test.rb +0 -65
- data/test/repo_index_test.rb +0 -122
- data/test/repo_test.rb +0 -23
data/lib/boson/pipes.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
module Boson
|
2
|
-
# === Default Pipes: Search and Sort
|
3
|
-
# The default pipe options, :query, :sort and :reverse_sort, are quite useful for searching and sorting arrays:
|
4
|
-
# Some examples using default commands:
|
5
|
-
# # Searches commands in the full_name field for 'lib' and sorts results by that field.
|
6
|
-
# $ boson commands -q=f:lib -s=f # or commands --query=full_name:lib --sort=full_name
|
7
|
-
#
|
8
|
-
# # Multiple fields can be searched if separated by a ','. This searches the full_name and desc fields.
|
9
|
-
# $ boson commands -q=f,d:web # or commands --query=full_name,desc:web
|
10
|
-
#
|
11
|
-
# # All fields can be queried using a '*'.
|
12
|
-
# # Searches all library fields and then reverse sorts on name field
|
13
|
-
# $ boson libraries -q=*:core -s=n -R # or libraries --query=*:core --sort=name --reverse_sort
|
14
|
-
#
|
15
|
-
# # Multiple searches can be joined together by ','
|
16
|
-
# # Searches for libraries that have the name matching core or a library_type matching gem
|
17
|
-
# $ boson libraries -q=n:core,l:gem # or libraries --query=name:core,library_type:gem
|
18
|
-
#
|
19
|
-
# In these examples, we queried commands and examples with an explicit --query. However, -q or --query isn't necessary
|
20
|
-
# for these commands because they already default to it when not present. This behavior comes from the default_option
|
21
|
-
# attribute a command can have.
|
22
|
-
module Pipes
|
23
|
-
extend self
|
24
|
-
|
25
|
-
# Case-insensitive search an array of objects or hashes for the :query option.
|
26
|
-
# This option is a hash of fields mapped to their search terms. Searches are OR-ed.
|
27
|
-
# When searching hashes, numerical string keys in query_hash are converted to actual numbers to
|
28
|
-
# interface with Hirb.
|
29
|
-
def query_pipe(object, query_hash)
|
30
|
-
if object[0].is_a?(Hash)
|
31
|
-
query_hash.map {|field,query|
|
32
|
-
field = field.to_i if field.to_s[/^\d+$/]
|
33
|
-
object.select {|e| e[field].to_s =~ /#{query}/i }
|
34
|
-
}.flatten.uniq
|
35
|
-
else
|
36
|
-
query_hash.map {|field,query| object.select {|e| e.send(field).to_s =~ /#{query}/i } }.flatten.uniq
|
37
|
-
end
|
38
|
-
rescue NoMethodError
|
39
|
-
$stderr.puts "Query failed with nonexistant method '#{$!.message[/`(.*)'/,1]}'"
|
40
|
-
end
|
41
|
-
|
42
|
-
# Sorts an array of objects or hashes using a sort field. Sort is reversed with reverse_sort set to true.
|
43
|
-
def sort_pipe(object, sort)
|
44
|
-
sort_lambda = lambda {}
|
45
|
-
if object[0].is_a?(Hash)
|
46
|
-
if sort.to_s[/^\d+$/]
|
47
|
-
sort = sort.to_i
|
48
|
-
elsif object[0].keys.all? {|e| e.is_a?(Symbol) }
|
49
|
-
sort = sort.to_sym
|
50
|
-
end
|
51
|
-
sort_lambda = untouched_sort?(object.map {|e| e[sort] }) ? lambda {|e| e[sort] } : lambda {|e| e[sort].to_s }
|
52
|
-
else
|
53
|
-
sort_lambda = untouched_sort?(object.map {|e| e.send(sort) }) ? lambda {|e| e.send(sort) || ''} :
|
54
|
-
lambda {|e| e.send(sort).to_s }
|
55
|
-
end
|
56
|
-
object.sort_by &sort_lambda
|
57
|
-
rescue NoMethodError, ArgumentError
|
58
|
-
$stderr.puts "Sort failed with nonexistant method '#{sort}'"
|
59
|
-
end
|
60
|
-
|
61
|
-
def untouched_sort?(values) #:nodoc:
|
62
|
-
values.all? {|e| e.respond_to?(:<=>) } && values.map {|e| e.class }.uniq.size == 1
|
63
|
-
end
|
64
|
-
|
65
|
-
# Reverse an object
|
66
|
-
def reverse_sort_pipe(object, extra=nil)
|
67
|
-
object.reverse
|
68
|
-
end
|
69
|
-
|
70
|
-
# Pipes output of multiple commands recursively, given initial object
|
71
|
-
def pipes_pipe(obj, arr)
|
72
|
-
arr.inject(obj) {|acc,e| Boson.full_invoke(e, [acc]) }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
data/lib/boson/repo.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
%w{yaml fileutils}.each {|e| require e }
|
2
|
-
module Boson
|
3
|
-
# A class for repositories. A repository has a root directory with required subdirectories config/ and
|
4
|
-
# commands/ and optional subdirectory lib/. Each repository has a primary config file at config/boson.yml.
|
5
|
-
class Repo
|
6
|
-
def self.commands_dir(dir) #:nodoc:
|
7
|
-
File.join(dir, 'commands')
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_accessor :dir, :config
|
11
|
-
# Creates a repository given a root directory.
|
12
|
-
def initialize(dir)
|
13
|
-
@dir = dir
|
14
|
-
end
|
15
|
-
|
16
|
-
# Points to the config/ subdirectory and is automatically created when called. Used for config files.
|
17
|
-
def config_dir
|
18
|
-
@config_dir ||= FileUtils.mkdir_p(config_dir_path) && config_dir_path
|
19
|
-
end
|
20
|
-
|
21
|
-
def config_dir_path
|
22
|
-
"#{dir}/config"
|
23
|
-
end
|
24
|
-
|
25
|
-
# Path name of main config file. If passed true, parent directory of file is created.
|
26
|
-
def config_file(create_dir=false)
|
27
|
-
File.join((create_dir ? config_dir : config_dir_path), 'boson.yml')
|
28
|
-
end
|
29
|
-
|
30
|
-
# Points to the commands/ subdirectory and is automatically created when called. Used for command libraries.
|
31
|
-
def commands_dir
|
32
|
-
@commands_dir ||= (cdir = self.class.commands_dir(@dir)) && FileUtils.mkdir_p(cdir) && cdir
|
33
|
-
end
|
34
|
-
|
35
|
-
# A hash read from the YAML config file at config/boson.yml.
|
36
|
-
# {See here}[http://github.com/cldwalker/irbfiles/blob/master/boson/config/boson.yml] for an example config file.
|
37
|
-
# Top level config keys, library attributes and config attributes need to be symbols.
|
38
|
-
# ==== Config keys for all repositories:
|
39
|
-
# [:libraries] Hash of libraries mapping their name to attribute hashes. See Library.new for configurable attributes.
|
40
|
-
# Example:
|
41
|
-
# :libraries=>{'completion'=>{:namespace=>true}}
|
42
|
-
# [:command_aliases] Hash of commands names and their aliases. Since this is global it will be read by _all_ libraries.
|
43
|
-
# This is useful for quickly creating aliases without having to worry about placing them under
|
44
|
-
# the correct library config. For non-global aliasing, aliases should be placed under the :command_aliases
|
45
|
-
# key of a library entry in :libraries.
|
46
|
-
# Example:
|
47
|
-
# :command_aliases=>{'libraries'=>'lib', 'commands'=>'com'}
|
48
|
-
# [:defaults] Array of libraries to load at start up for commandline and irb. This is useful for extending boson i.e. adding your
|
49
|
-
# own option types since these are loaded before any other libraries. Default is no libraries.
|
50
|
-
# [:console_defaults] Array of libraries to load at start up when used in irb. Default is to load all library files and libraries
|
51
|
-
# defined in the config.
|
52
|
-
# [:bin_defaults] Array of libraries to load at start up when used from the commandline. Default is no libraries.
|
53
|
-
# [:add_load_path] Boolean specifying whether to add a load path pointing to the lib subdirectory/. This is useful in sharing
|
54
|
-
# classes between libraries without resorting to packaging them as gems. Defaults to false if the lib
|
55
|
-
# subdirectory doesn't exist in the boson directory.
|
56
|
-
#
|
57
|
-
# ==== Config keys specific to the main repo config ~/.boson/config/boson.yml
|
58
|
-
# [:pipe_options] Hash of options available to all option commands for piping (see Pipe). A pipe option has the
|
59
|
-
# {normal option attributes}[link:classes/Boson/OptionParser.html#M000081] and these:
|
60
|
-
# * :pipe: Specifies the command to call when piping. Defaults to the pipe's option name.
|
61
|
-
# * :filter: Boolean which indicates that the pipe command will modify its input with what it returns.
|
62
|
-
# Default is false.
|
63
|
-
# [:render_options] Hash of render options available to all option commands to be passed to a Hirb view (see View). Since
|
64
|
-
# this merges with default render options, it's possible to override default render options.
|
65
|
-
# [:error_method_conflicts] Boolean specifying library loading behavior when its methods conflicts with existing methods in
|
66
|
-
# the global namespace. When set to false, Boson automatically puts the library in its own namespace.
|
67
|
-
# When set to true, the library fails to load explicitly. Default is false.
|
68
|
-
# [:console] Console to load when using --console from commandline. Default is irb.
|
69
|
-
# [:auto_namespace] Boolean which automatically namespaces all user-defined libraries. Be aware this can break libraries which
|
70
|
-
# depend on commands from other libraries. Default is false.
|
71
|
-
# [:ignore_directories] Array of directories to ignore when detecting local repositories for Boson.local_repo.
|
72
|
-
# [:no_auto_render] When set, turns off commandline auto-rendering of a command's output. Default is false.
|
73
|
-
# [:option_underscore_search] When set, OptionParser option values (with :values or :keys) are auto aliased with underscore searching.
|
74
|
-
# Default is true. See Util.underscore_search.
|
75
|
-
def config(reload=false)
|
76
|
-
if reload || @config.nil?
|
77
|
-
begin
|
78
|
-
@config = {:libraries=>{}, :command_aliases=>{}, :console_defaults=>[], :option_underscore_search=>true}
|
79
|
-
@config.merge!(YAML::load_file(config_file(true))) if File.exists?(config_file)
|
80
|
-
rescue ArgumentError
|
81
|
-
message = $!.message !~ /syntax error on line (\d+)/ ? "Error"+$!.message :
|
82
|
-
"Error: Syntax error in line #{$1} of config file '#{config_file}'"
|
83
|
-
Kernel.abort message
|
84
|
-
end
|
85
|
-
end
|
86
|
-
@config
|
87
|
-
end
|
88
|
-
|
89
|
-
# Updates main config file by passing config into a block to be modified and then saved
|
90
|
-
def update_config
|
91
|
-
yield(config)
|
92
|
-
write_config_file
|
93
|
-
end
|
94
|
-
|
95
|
-
def write_config_file #:nodoc:
|
96
|
-
File.open(config_file, 'w') {|f| f.write config.to_yaml }
|
97
|
-
end
|
98
|
-
|
99
|
-
def detected_libraries #:nodoc:
|
100
|
-
Dir[File.join(commands_dir, '**/*.rb')].map {|e| e.gsub(/^#{commands_dir}\/|\.rb$/, '') }
|
101
|
-
end
|
102
|
-
|
103
|
-
def all_libraries #:nodoc:
|
104
|
-
(detected_libraries + config[:libraries].keys).uniq
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,208 +0,0 @@
|
|
1
|
-
module Boson
|
2
|
-
# This class handles the boson executable (boson command execution from the commandline). Any changes
|
3
|
-
# to your commands are immediately available from the commandline except for changes to the main config file.
|
4
|
-
# For those changes to take effect you need to explicitly load and index the libraries with --index.
|
5
|
-
# See RepoIndex to understand how Boson can immediately detect the latest commands.
|
6
|
-
#
|
7
|
-
# Usage for the boson shell command looks like this:
|
8
|
-
# boson [GLOBAL OPTIONS] [COMMAND] [ARGS] [COMMAND OPTIONS]
|
9
|
-
#
|
10
|
-
# The boson executable comes with these global options:
|
11
|
-
# [:help] Gives a basic help of global options. When a command is given the help shifts to a command's help.
|
12
|
-
# [:verbose] Using this along with :help option shows more help. Also gives verbosity to other actions i.e. loading.
|
13
|
-
# [:execute] Like ruby -e, this executes a string of ruby code. However, this has the advantage that all
|
14
|
-
# commands are available as normal methods, automatically loading as needed. This is a good
|
15
|
-
# way to call commands that take non-string arguments.
|
16
|
-
# [:console] This drops Boson into irb after having loaded default commands and any explict libraries with
|
17
|
-
# :load option. This is a good way to start irb with only certain libraries loaded.
|
18
|
-
# [:load] Explicitly loads a list of libraries separated by commas. Most useful when used with :console option.
|
19
|
-
# Can also be used to explicitly load libraries that aren't being detected automatically.
|
20
|
-
# [:index] Updates index for given libraries allowing you to use them. This is useful if Boson's autodetection of
|
21
|
-
# changed libraries isn't picking up your changes. Since this option has a :bool_default attribute, arguments
|
22
|
-
# passed to this option need to be passed with '=' i.e. '--index=my_lib'.
|
23
|
-
# [:render] Toggles the auto-rendering done for commands that don't have views. Doesn't affect commands that already have views.
|
24
|
-
# Default is false. Also see Auto Rendering section below.
|
25
|
-
# [:pager_toggle] Toggles Hirb's pager in case you'd like to pipe to another command.
|
26
|
-
# [:backtrace] Prints full backtrace on error. Default is false.
|
27
|
-
#
|
28
|
-
# ==== Auto Rendering
|
29
|
-
# Commands that don't have views (defined via render_options) have their return value auto-rendered as a view as follows:
|
30
|
-
# * nil,false and true aren't rendered
|
31
|
-
# * arrays are rendered with Hirb's tables
|
32
|
-
# * non-arrays are printed with inspect()
|
33
|
-
# * Any of these cases can be toggled to render/not render with the global option :render
|
34
|
-
# To turn off auto-rendering by default, add a :no_auto_render: true entry to the main config.
|
35
|
-
class BinRunner < Runner
|
36
|
-
GLOBAL_OPTIONS = {
|
37
|
-
:verbose=>{:type=>:boolean, :desc=>"Verbose description of loading libraries, errors or help"},
|
38
|
-
:version=>{:type=>:boolean, :desc=>"Prints the current version"},
|
39
|
-
:index=>{:type=>:array, :desc=>"Libraries to index. Libraries must be passed with '='.",
|
40
|
-
:bool_default=>nil, :values=>all_libraries, :regexp=>true, :enum=>false},
|
41
|
-
:execute=>{:type=>:string, :desc=>"Executes given arguments as a one line script"},
|
42
|
-
:console=>{:type=>:boolean, :desc=>"Drops into irb with default and explicit libraries loaded"},
|
43
|
-
:help=>{:type=>:boolean, :desc=>"Displays this help message or a command's help if given a command"},
|
44
|
-
:load=>{:type=>:array, :values=>all_libraries, :regexp=>true, :enum=>false,
|
45
|
-
:desc=>"A comma delimited array of libraries to load"},
|
46
|
-
:unload=>{:type=>:string, :desc=>"Acts as a regular expression to unload default libraries"},
|
47
|
-
:render=>{:type=>:boolean, :desc=>"Renders a Hirb view from result of command without options"},
|
48
|
-
:pager_toggle=>{:type=>:boolean, :desc=>"Toggles Hirb's pager"},
|
49
|
-
:option_commands=>{:type=>:boolean, :desc=>"Toggles on all commands to be defined as option commands" },
|
50
|
-
:ruby_debug=>{:type=>:boolean, :desc=>"Sets $DEBUG", :alias=>'D'},
|
51
|
-
:debug=>{:type=>:boolean, :desc=>"Prints debug info for boson"},
|
52
|
-
:load_path=>{:type=>:string, :desc=>"Add to front of $LOAD_PATH", :alias=>'I'},
|
53
|
-
:backtrace=>{:type=>:boolean, :desc=>'Prints full backtrace'}
|
54
|
-
} #:nodoc:
|
55
|
-
|
56
|
-
PIPE = '+'
|
57
|
-
|
58
|
-
class <<self
|
59
|
-
attr_accessor :command
|
60
|
-
|
61
|
-
# Starts, processes and ends a commandline request.
|
62
|
-
def start(args=ARGV)
|
63
|
-
@command, @options, @args = parse_args(args)
|
64
|
-
return puts("boson #{Boson::VERSION}") if @options[:version]
|
65
|
-
return print_usage if args.empty? || (@command.nil? && !@options[:console] && !@options[:execute])
|
66
|
-
$:.unshift(*options[:load_path].split(":")) if options[:load_path]
|
67
|
-
Runner.debug = true if @options[:debug]
|
68
|
-
return ConsoleRunner.bin_start(@options[:console], @options[:load]) if @options[:console]
|
69
|
-
$DEBUG = true if options[:ruby_debug]
|
70
|
-
init
|
71
|
-
|
72
|
-
if @options[:help]
|
73
|
-
autoload_command @command
|
74
|
-
Boson.invoke(:usage, @command, :verbose=>@options[:verbose])
|
75
|
-
elsif @options[:execute]
|
76
|
-
define_autoloader
|
77
|
-
Boson.main_object.instance_eval @options[:execute]
|
78
|
-
else
|
79
|
-
execute_command
|
80
|
-
end
|
81
|
-
rescue NoMethodError
|
82
|
-
abort_with no_method_error_message
|
83
|
-
rescue
|
84
|
-
abort_with default_error_message
|
85
|
-
end
|
86
|
-
|
87
|
-
def no_method_error_message #:nodoc:
|
88
|
-
@command = @command.to_s
|
89
|
-
if $!.backtrace.grep(/`(invoke|full_invoke)'$/).empty? ||
|
90
|
-
!$!.message[/undefined method `(\w+\.)?#{@command.split(NAMESPACE)[-1]}'/]
|
91
|
-
default_error_message
|
92
|
-
else
|
93
|
-
@command.to_s[/\w+/] &&
|
94
|
-
(!(Index.read && Index.find_command(@command[/\w+/])) || @command.include?(NAMESPACE)) ?
|
95
|
-
"Error: Command '#{@command}' not found" : default_error_message
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Loads libraries and handles non-critical options
|
100
|
-
def init
|
101
|
-
Runner.in_shell = true
|
102
|
-
Command.all_option_commands = true if @options[:option_commands]
|
103
|
-
super
|
104
|
-
|
105
|
-
if @options.key?(:index)
|
106
|
-
Index.update(:verbose=>true, :libraries=>@options[:index])
|
107
|
-
@index_updated = true
|
108
|
-
elsif !@options[:help] && @command && Boson.can_invoke?(@command)
|
109
|
-
Index.update(:verbose=>@options[:verbose])
|
110
|
-
@index_updated = true
|
111
|
-
end
|
112
|
-
Manager.load @options[:load], load_options if @options[:load]
|
113
|
-
View.toggle_pager if @options[:pager_toggle]
|
114
|
-
end
|
115
|
-
|
116
|
-
# Hash of global options passed in from commandline
|
117
|
-
def options
|
118
|
-
@options ||= {}
|
119
|
-
end
|
120
|
-
|
121
|
-
# Commands to executed, in order given by user
|
122
|
-
def commands
|
123
|
-
@commands ||= @all_args.map {|e| e[0]}
|
124
|
-
end
|
125
|
-
|
126
|
-
#:stopdoc:
|
127
|
-
def abort_with(message)
|
128
|
-
message += "\nOriginal error: #{$!}\n #{$!.backtrace.join("\n ")}" if options[:verbose] || options[:backtrace]
|
129
|
-
abort message
|
130
|
-
end
|
131
|
-
|
132
|
-
def default_error_message
|
133
|
-
"Error: #{$!.message}"
|
134
|
-
end
|
135
|
-
|
136
|
-
def autoload_command(cmd)
|
137
|
-
if !Boson.can_invoke?(cmd, false)
|
138
|
-
unless @index_updated
|
139
|
-
Index.update(:verbose=>@options[:verbose])
|
140
|
-
@index_updated = true
|
141
|
-
end
|
142
|
-
super(cmd, load_options)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def default_libraries
|
147
|
-
libs = super + Boson.repos.map {|e| e.config[:bin_defaults] || [] }.flatten + Dir.glob('Bosonfile')
|
148
|
-
@options[:unload] ? libs.select {|e| e !~ /#{@options[:unload]}/} : libs
|
149
|
-
end
|
150
|
-
|
151
|
-
def execute_command
|
152
|
-
output = @all_args.inject(nil) {|acc, (cmd,*args)|
|
153
|
-
begin
|
154
|
-
@command = cmd # for external errors
|
155
|
-
autoload_command cmd
|
156
|
-
args = translate_args(args, acc)
|
157
|
-
Boson.full_invoke(cmd, args)
|
158
|
-
rescue ArgumentError
|
159
|
-
if $!.class == OptionCommand::CommandArgumentError || ($!.message[/wrong number of arguments/] &&
|
160
|
-
(cmd_obj = Command.find(cmd)) && cmd_obj.arg_size != args.size)
|
161
|
-
abort_with "'#{cmd}' was called incorrectly.\n" + Command.usage(cmd)
|
162
|
-
else
|
163
|
-
raise
|
164
|
-
end
|
165
|
-
end
|
166
|
-
}
|
167
|
-
render_output output
|
168
|
-
end
|
169
|
-
|
170
|
-
def translate_args(args, piped)
|
171
|
-
args.unshift piped if piped
|
172
|
-
args
|
173
|
-
end
|
174
|
-
|
175
|
-
def parse_args(args)
|
176
|
-
@all_args = Util.split_array_by(args, PIPE)
|
177
|
-
args = @all_args[0]
|
178
|
-
@option_parser = OptionParser.new(GLOBAL_OPTIONS)
|
179
|
-
options = @option_parser.parse(args.dup, :opts_before_args=>true)
|
180
|
-
new_args = @option_parser.non_opts
|
181
|
-
@all_args[0] = new_args
|
182
|
-
[new_args[0], options, new_args[1..-1]]
|
183
|
-
end
|
184
|
-
|
185
|
-
def render_output(output)
|
186
|
-
if (!Scientist.rendered && !View.silent_object?(output)) ^ @options[:render] ^
|
187
|
-
Boson.repo.config[:no_auto_render]
|
188
|
-
opts = output.is_a?(String) ? {:method=>'puts'} :
|
189
|
-
{:inspect=>!output.is_a?(Array) || (Scientist.global_options || {})[:render] }
|
190
|
-
View.render output, opts
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def print_usage
|
195
|
-
puts "boson [GLOBAL OPTIONS] [COMMAND] [ARGS] [COMMAND OPTIONS]\n\n"
|
196
|
-
puts "GLOBAL OPTIONS"
|
197
|
-
View.enable
|
198
|
-
@option_parser.print_usage_table
|
199
|
-
if @options[:verbose]
|
200
|
-
Manager.load [Boson::Commands::Core]
|
201
|
-
puts "\n\nDEFAULT COMMANDS"
|
202
|
-
Boson.invoke :commands, :fields=>["name", "usage", "description"], :description=>false
|
203
|
-
end
|
204
|
-
end
|
205
|
-
#:startdoc:
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Boson
|
2
|
-
# Runner used when starting irb. To use in irb, drop this in your ~/.irbrc:
|
3
|
-
# require 'boson'
|
4
|
-
# Boson.start
|
5
|
-
class ConsoleRunner < Runner
|
6
|
-
class <<self
|
7
|
-
# Starts Boson by loading configured libraries. If no default libraries are specified in the config,
|
8
|
-
# it will load up all detected libraries. Options:
|
9
|
-
# [:libraries] Array of libraries to load.
|
10
|
-
# [:verbose] Boolean to be verbose about libraries loading. Default is true.
|
11
|
-
# [:no_defaults] Boolean or :all which turns off loading default libraries. If set to true,
|
12
|
-
# effects loading user's console default libraries. If set to :all, effects
|
13
|
-
# all libraries including boson's. Default is false.
|
14
|
-
# [:autoload_libraries] Boolean which makes any command execution easier. It redefines
|
15
|
-
# method_missing on Boson.main_object so that commands with unloaded
|
16
|
-
# libraries are automatically loaded. Default is false.
|
17
|
-
def start(options={})
|
18
|
-
@options = {:verbose=>true}.merge options
|
19
|
-
init unless @initialized
|
20
|
-
Manager.load(@options[:libraries], load_options) if @options[:libraries]
|
21
|
-
end
|
22
|
-
|
23
|
-
# Loads libraries and then starts irb (or the configured console) from the commandline.
|
24
|
-
def bin_start(repl, libraries)
|
25
|
-
start :no_defaults=>true, :libraries=>libraries
|
26
|
-
repl = Boson.repo.config[:console] if Boson.repo.config[:console]
|
27
|
-
repl = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' unless repl.is_a?(String)
|
28
|
-
unless repl.index('/') == 0 || (repl = Util.which(repl))
|
29
|
-
abort "Console not found. Please specify full path in config[:console]."
|
30
|
-
else
|
31
|
-
load_repl(repl)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def load_repl(repl) #:nodoc:
|
36
|
-
ARGV.replace ['-f']
|
37
|
-
$progname = $0
|
38
|
-
alias $0 $progname
|
39
|
-
Kernel.load $0 = repl
|
40
|
-
end
|
41
|
-
|
42
|
-
def init #:nodoc:
|
43
|
-
super
|
44
|
-
define_autoloader if @options[:autoload_libraries]
|
45
|
-
@initialized = true
|
46
|
-
end
|
47
|
-
|
48
|
-
def default_libraries #:nodoc:
|
49
|
-
return [] if @options[:no_defaults] == :all
|
50
|
-
return super if @options[:no_defaults]
|
51
|
-
defaults = super + Boson.repos.map {|e| e.config[:console_defaults] }.flatten
|
52
|
-
defaults += detected_libraries if defaults.empty?
|
53
|
-
defaults.uniq
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|