clone 1.0.0.alpha → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +1 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -1
- data/VERSION +1 -1
- data/bin/clone +7 -0
- data/clone.gemspec +4 -0
- data/docs/readme +16 -0
- data/docs/readme.txt +5 -0
- data/lib/clone.rb +13 -2
- data/lib/clone/config/config.rb +19 -0
- data/lib/clone/config/config.yml +22 -0
- data/lib/clone/config/default_config.yml +20 -0
- data/lib/clone/config/require.rb +3 -0
- data/lib/clone/config/version.rb +10 -0
- data/lib/clone/config/yml.rb +22 -0
- data/lib/clone/config/z_defaults.rb +28 -0
- data/lib/clone/generator/engine.rb +581 -0
- data/lib/clone/generator/terminal.rb +104 -0
- data/lib/clone/helpers/helper_methods.rb +251 -0
- data/lib/clone/helpers/local_methods.rb +150 -0
- data/lib/clone/helpers/require.rb +37 -0
- data/module/Marshal.4.8 +0 -0
- data/module/Marshal.4.8.Z +0 -0
- data/module/gems/commander-4.1.3/.gitignore +6 -0
- data/module/gems/commander-4.1.3/.travis.yml +11 -0
- data/module/gems/commander-4.1.3/DEVELOPMENT +15 -0
- data/module/gems/commander-4.1.3/Gemfile +3 -0
- data/module/gems/commander-4.1.3/History.rdoc +345 -0
- data/module/gems/commander-4.1.3/Manifest +38 -0
- data/module/gems/commander-4.1.3/README.rdoc +375 -0
- data/module/gems/commander-4.1.3/Rakefile +10 -0
- data/module/gems/commander-4.1.3/bin/commander +55 -0
- data/module/gems/commander-4.1.3/commander.gemspec +26 -0
- data/module/gems/commander-4.1.3/lib/commander.rb +32 -0
- data/module/gems/commander-4.1.3/lib/commander/blank.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/command.rb +213 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext.rb +3 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext/array.rb +26 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext/object.rb +11 -0
- data/module/gems/commander-4.1.3/lib/commander/delegates.rb +13 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/base.rb +18 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal.rb +20 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/command_help.erb +35 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/help.erb +36 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact.rb +12 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/command_help.erb +27 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/help.erb +29 -0
- data/module/gems/commander-4.1.3/lib/commander/import.rb +10 -0
- data/module/gems/commander-4.1.3/lib/commander/platform.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/runner.rb +411 -0
- data/module/gems/commander-4.1.3/lib/commander/user_interaction.rb +521 -0
- data/module/gems/commander-4.1.3/lib/commander/version.rb +3 -0
- data/module/gems/commander-4.1.3/spec/command_spec.rb +157 -0
- data/module/gems/commander-4.1.3/spec/core_ext/array_spec.rb +20 -0
- data/module/gems/commander-4.1.3/spec/core_ext/object_spec.rb +21 -0
- data/module/gems/commander-4.1.3/spec/help_formatters/terminal_spec.rb +67 -0
- data/module/gems/commander-4.1.3/spec/runner_spec.rb +526 -0
- data/module/gems/commander-4.1.3/spec/spec_helper.rb +59 -0
- data/module/gems/commander-4.1.3/spec/ui_spec.rb +30 -0
- data/module/gems/hello.rb +1 -0
- data/module/gems/highline-1.6.19/.gitignore +2 -0
- data/module/gems/highline-1.6.19/AUTHORS +3 -0
- data/module/gems/highline-1.6.19/CHANGELOG +346 -0
- data/module/gems/highline-1.6.19/COPYING +340 -0
- data/module/gems/highline-1.6.19/INSTALL +55 -0
- data/module/gems/highline-1.6.19/LICENSE +7 -0
- data/module/gems/highline-1.6.19/README.rdoc +63 -0
- data/module/gems/highline-1.6.19/Rakefile +50 -0
- data/module/gems/highline-1.6.19/TODO +6 -0
- data/module/gems/highline-1.6.19/examples/ansi_colors.rb +38 -0
- data/module/gems/highline-1.6.19/examples/asking_for_arrays.rb +18 -0
- data/module/gems/highline-1.6.19/examples/basic_usage.rb +75 -0
- data/module/gems/highline-1.6.19/examples/color_scheme.rb +32 -0
- data/module/gems/highline-1.6.19/examples/get_character.rb +12 -0
- data/module/gems/highline-1.6.19/examples/limit.rb +12 -0
- data/module/gems/highline-1.6.19/examples/menus.rb +65 -0
- data/module/gems/highline-1.6.19/examples/overwrite.rb +19 -0
- data/module/gems/highline-1.6.19/examples/page_and_wrap.rb +322 -0
- data/module/gems/highline-1.6.19/examples/password.rb +7 -0
- data/module/gems/highline-1.6.19/examples/repeat_entry.rb +21 -0
- data/module/gems/highline-1.6.19/examples/trapping_eof.rb +22 -0
- data/module/gems/highline-1.6.19/examples/using_readline.rb +17 -0
- data/module/gems/highline-1.6.19/highline.gemspec +37 -0
- data/module/gems/highline-1.6.19/lib/highline.rb +1012 -0
- data/module/gems/highline-1.6.19/lib/highline/color_scheme.rb +134 -0
- data/module/gems/highline-1.6.19/lib/highline/compatibility.rb +16 -0
- data/module/gems/highline-1.6.19/lib/highline/import.rb +41 -0
- data/module/gems/highline-1.6.19/lib/highline/menu.rb +398 -0
- data/module/gems/highline-1.6.19/lib/highline/question.rb +475 -0
- data/module/gems/highline-1.6.19/lib/highline/simulate.rb +48 -0
- data/module/gems/highline-1.6.19/lib/highline/string_extensions.rb +131 -0
- data/module/gems/highline-1.6.19/lib/highline/style.rb +181 -0
- data/module/gems/highline-1.6.19/lib/highline/system_extensions.rb +222 -0
- data/module/gems/highline-1.6.19/setup.rb +1360 -0
- data/module/gems/highline-1.6.19/site/.cvsignore +1 -0
- data/module/gems/highline-1.6.19/site/highline.css +65 -0
- data/module/gems/highline-1.6.19/site/images/logo.png +0 -0
- data/module/gems/highline-1.6.19/site/index.html +58 -0
- data/module/gems/highline-1.6.19/test/string_methods.rb +32 -0
- data/module/gems/highline-1.6.19/test/tc_color_scheme.rb +96 -0
- data/module/gems/highline-1.6.19/test/tc_highline.rb +1128 -0
- data/module/gems/highline-1.6.19/test/tc_import.rb +52 -0
- data/module/gems/highline-1.6.19/test/tc_menu.rb +439 -0
- data/module/gems/highline-1.6.19/test/tc_string_extension.rb +20 -0
- data/module/gems/highline-1.6.19/test/tc_string_highline.rb +38 -0
- data/module/gems/highline-1.6.19/test/tc_style.rb +567 -0
- data/module/gems/highline-1.6.19/test/ts_all.rb +16 -0
- data/module/latest_specs.4.8 +0 -0
- data/module/latest_specs.4.8.gz +0 -0
- data/module/prerelease_specs.4.8 +0 -0
- data/module/prerelease_specs.4.8.gz +0 -0
- data/module/specs.4.8 +0 -0
- data/module/specs.4.8.gz +0 -0
- data/samples/blather/restlike/Gemfile +4 -0
- data/samples/blather/restlike/cmd.yml +1 -0
- data/samples/blather/restlike/lib/blather.rb +9 -0
- data/samples/blather/restlike/lib/blather/dsl/api.rb +78 -0
- data/samples/blather/restlike/lib/blather/dsl/call.rb +13 -0
- data/samples/blather/restlike/lib/blather/dsl/client.rb +58 -0
- data/samples/blather/restlike/lib/blather/dsl/config.rb +11 -0
- data/samples/blather/restlike/lib/blather/dsl/extraDSL.rb +163 -0
- data/samples/blather/restlike/lib/blather/meta/require.rb +8 -0
- data/samples/blather/restlike/lib/blather/meta/xmpp.yml +5 -0
- data/samples/blather/restlike/lib/blather/vendors/xmpp_default.rb +27 -0
- data/samples/blather/restlike/readme +2 -0
- data/samples/grape/init/Gemfile +2 -0
- data/samples/grape/init/cmd.yml +3 -0
- data/samples/grape/init/config.ru +2 -0
- data/samples/grape/init/docs/grape/documentation.txt +939 -0
- data/samples/grape/init/docs/grape/generate_rest_routes.rb +37 -0
- data/samples/grape/init/docs/grape/ls_routes.rb +31 -0
- data/samples/grape/init/lib/grape.rb +4 -0
- data/samples/grape/init/lib/grape/meta/subclasses.rb +20 -0
- data/samples/grape/init/lib/grape/xpath/app.rb +30 -0
- data/samples/grape/init/lib/grape/xpath/ruotes.rb +6 -0
- data/samples/grape/init/readme +1 -0
- data/samples/grape/readme +29 -0
- data/samples/grape/vendor/lib/grape/vendors/v1/rest.rb +57 -0
- data/samples/mongoid/cmd.yml +1 -0
- data/samples/mongoid/init/Gemfile +3 -0
- data/samples/mongoid/init/cmd.yml +2 -0
- data/samples/mongoid/init/docs/mongoid/ModelsRelations.rb +11 -0
- data/samples/mongoid/init/docs/mongoid/documents.xls +0 -0
- data/samples/mongoid/init/docs/mongoid/generate_modelsToDocs.rb +25 -0
- data/samples/mongoid/init/docs/mongoid/modelsToDocs.rb +25 -0
- data/samples/mongoid/init/docs/mongoid/relations.txt +1354 -0
- data/samples/mongoid/init/lib/mongoid.rb +44 -0
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_CRUD.rb +446 -0
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_MP.rb +517 -0
- data/samples/mongoid/init/lib/mongoid/dsl/init.rb +37 -0
- data/samples/mongoid/init/lib/mongoid/dsl/params.rb +67 -0
- data/samples/mongoid/init/lib/mongoid/meta/banned.rb +147 -0
- data/samples/mongoid/init/lib/mongoid/meta/control.yml +13 -0
- data/samples/mongoid/init/lib/mongoid/meta/mongoid.yml +6 -0
- data/samples/mongoid/init/lib/mongoid/meta/mpatch.rb +14 -0
- data/samples/mongoid/model/lib/mongoid/models/model.rb +28 -0
- data/samples/mongoid/readme +33 -0
- data/samples/rack/init/Gemfile +10 -0
- data/samples/rack/init/cmd.yml +2 -0
- data/samples/rack/init/config.ru +1 -0
- data/samples/rack/init/docs/rack/rake introducing.txt +60 -0
- data/samples/rack/init/docs/rack/webservers/Thin +43 -0
- data/samples/rack/init/docs/rack/webservers/ebb +72 -0
- data/samples/rack/init/docs/rack/webservers/fcgi +103 -0
- data/samples/rack/init/docs/rack/webservers/mongrel +74 -0
- data/samples/rack/init/docs/rack/webservers/passenger +37 -0
- data/samples/rack/init/docs/rack/webservers/scgi +188 -0
- data/samples/rack/init/lib/rack.rb +1 -0
- data/samples/rack/init/lib/rack/meta/webserver/thin.rb +45 -0
- data/samples/rack/init/lib/rack/meta/webserver/thin.yml +6 -0
- data/samples/rack/init/server.rb +0 -0
- data/samples/rack/readme +13 -0
- data/samples/rest_client/init/Gemfile +5 -0
- data/samples/rest_client/init/boot.rb +2 -0
- data/samples/rest_client/init/cmd.yml +1 -0
- data/samples/rest_client/init/config/rest_client/defaults.rb +16 -0
- data/samples/rest_client/init/docs/rest_client/simple overlook +251 -0
- data/samples/rest_client/init/test/rest_client/rest_dsl.rb +5 -0
- data/samples/rest_client/readme +7 -0
- data/samples/scripts/lines_counter/lines_number.rb +32 -0
- data/samples/scripts/lines_counter/readme +5 -0
- data/samples/scripts/readme +1 -0
- metadata +197 -7
- data/lib/clone/cms.rb +0 -56
- data/lib/clone/ext.rb +0 -77
- data/sample/test.rb +0 -30
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008-2009 TJ Holowaychuk <tj@vision-media.ca>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require 'highline/import'
|
25
|
+
require 'commander/version'
|
26
|
+
require 'commander/blank'
|
27
|
+
require 'commander/user_interaction'
|
28
|
+
require 'commander/core_ext'
|
29
|
+
require 'commander/runner'
|
30
|
+
require 'commander/command'
|
31
|
+
require 'commander/help_formatters'
|
32
|
+
require 'commander/platform'
|
@@ -0,0 +1,213 @@
|
|
1
|
+
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Commander
|
5
|
+
class Command
|
6
|
+
|
7
|
+
attr_accessor :name, :examples, :syntax, :description
|
8
|
+
attr_accessor :summary, :proxy_options, :options
|
9
|
+
|
10
|
+
##
|
11
|
+
# Options struct.
|
12
|
+
|
13
|
+
class Options
|
14
|
+
include Blank
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@table = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def __hash__
|
21
|
+
@table
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing meth, *args, &block
|
25
|
+
meth.to_s =~ /=$/ ? @table[meth.to_s.chop.to_sym] = args.first : @table[meth]
|
26
|
+
end
|
27
|
+
|
28
|
+
def default defaults = {}
|
29
|
+
@table = defaults.merge! @table
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
"<Commander::Command::Options #{ __hash__.map { |k,v| "#{k}=#{v.inspect}" }.join(', ') }>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Initialize new command with specified _name_.
|
39
|
+
|
40
|
+
def initialize name
|
41
|
+
@name, @examples, @when_called = name.to_s, [], []
|
42
|
+
@options, @proxy_options = [], []
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Add a usage example for this command.
|
47
|
+
#
|
48
|
+
# Usage examples are later displayed in help documentation
|
49
|
+
# created by the help formatters.
|
50
|
+
#
|
51
|
+
# === Examples
|
52
|
+
#
|
53
|
+
# command :something do |c|
|
54
|
+
# c.example "Should do something", "my_command something"
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
|
58
|
+
def example description, command
|
59
|
+
@examples << [description, command]
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Add an option.
|
64
|
+
#
|
65
|
+
# Options are parsed via OptionParser so view it
|
66
|
+
# for additional usage documentation. A block may optionally be
|
67
|
+
# passed to handle the option, otherwise the _options_ struct seen below
|
68
|
+
# contains the results of this option. This handles common formats such as:
|
69
|
+
#
|
70
|
+
# -h, --help options.help # => bool
|
71
|
+
# --[no-]feature options.feature # => bool
|
72
|
+
# --large-switch options.large_switch # => bool
|
73
|
+
# --file FILE options.file # => file passed
|
74
|
+
# --list WORDS options.list # => array
|
75
|
+
# --date [DATE] options.date # => date or nil when optional argument not set
|
76
|
+
#
|
77
|
+
# === Examples
|
78
|
+
#
|
79
|
+
# command :something do |c|
|
80
|
+
# c.option '--recursive', 'Do something recursively'
|
81
|
+
# c.option '--file FILE', 'Specify a file'
|
82
|
+
# c.option('--info', 'Display info') { puts "handle with block" }
|
83
|
+
# c.option '--[no-]feature', 'With or without feature'
|
84
|
+
# c.option '--list FILES', Array, 'List the files specified'
|
85
|
+
#
|
86
|
+
# c.when_called do |args, options|
|
87
|
+
# do_something_recursively if options.recursive
|
88
|
+
# do_something_with_file options.file if options.file
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# === Help Formatters
|
93
|
+
#
|
94
|
+
# This method also parses the arguments passed in order to determine
|
95
|
+
# which were switches, and which were descriptions for the
|
96
|
+
# option which can later be used within help formatters
|
97
|
+
# using option[:switches] and option[:description].
|
98
|
+
#
|
99
|
+
# === Input Parsing
|
100
|
+
#
|
101
|
+
# Since Commander utilizes OptionParser you can pre-parse and evaluate
|
102
|
+
# option arguments. Simply require 'optparse/time', or 'optparse/date', as these
|
103
|
+
# objects must respond to #parse.
|
104
|
+
#
|
105
|
+
# c.option '--time TIME', Time
|
106
|
+
# c.option '--date [DATE]', Date
|
107
|
+
#
|
108
|
+
|
109
|
+
def option *args, &block
|
110
|
+
switches, description = Runner.separate_switches_from_description(*args)
|
111
|
+
proc = block || option_proc(switches)
|
112
|
+
@options << {
|
113
|
+
:args => args,
|
114
|
+
:proc => proc,
|
115
|
+
:switches => switches,
|
116
|
+
:description => description,
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Handle execution of command. The handler may be a class,
|
122
|
+
# object, or block (see examples below).
|
123
|
+
#
|
124
|
+
# === Examples
|
125
|
+
#
|
126
|
+
# # Simple block handling
|
127
|
+
# c.when_called do |args, options|
|
128
|
+
# # do something
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# # Create inst of Something and pass args / options
|
132
|
+
# c.when_called MyLib::Command::Something
|
133
|
+
#
|
134
|
+
# # Create inst of Something and use arbitrary method
|
135
|
+
# c.when_called MyLib::Command::Something, :some_method
|
136
|
+
#
|
137
|
+
# # Pass an object to handle callback (requires method symbol)
|
138
|
+
# c.when_called SomeObject, :some_method
|
139
|
+
#
|
140
|
+
|
141
|
+
def when_called *args, &block
|
142
|
+
raise ArgumentError, 'must pass an object, class, or block.' if args.empty? and !block
|
143
|
+
@when_called = block ? [block] : args
|
144
|
+
end
|
145
|
+
alias :action :when_called
|
146
|
+
|
147
|
+
##
|
148
|
+
# Run the command with _args_.
|
149
|
+
#
|
150
|
+
# * parses options, call option blocks
|
151
|
+
# * invokes when_called proc
|
152
|
+
#
|
153
|
+
|
154
|
+
def run *args
|
155
|
+
call parse_options_and_call_procs(*args)
|
156
|
+
end
|
157
|
+
|
158
|
+
#:stopdoc:
|
159
|
+
|
160
|
+
##
|
161
|
+
# Parses options and calls associated procs,
|
162
|
+
# returning the arguments remaining.
|
163
|
+
|
164
|
+
def parse_options_and_call_procs *args
|
165
|
+
return args if args.empty?
|
166
|
+
@options.inject OptionParser.new do |opts, option|
|
167
|
+
opts.on(*option[:args], &option[:proc])
|
168
|
+
opts
|
169
|
+
end.parse! args
|
170
|
+
end
|
171
|
+
|
172
|
+
##
|
173
|
+
# Call the commands when_called block with _args_.
|
174
|
+
|
175
|
+
def call args = []
|
176
|
+
object = @when_called.shift
|
177
|
+
meth = @when_called.shift || :call
|
178
|
+
options = proxy_option_struct
|
179
|
+
case object
|
180
|
+
when Proc ; object.call(args, options)
|
181
|
+
when Class ; meth != :call ? object.new.send(meth, args, options) : object.new(args, options)
|
182
|
+
else object.send(meth, args, options) if object
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
##
|
187
|
+
# Creates an Options instance populated with the option values
|
188
|
+
# collected by the #option_proc.
|
189
|
+
|
190
|
+
def proxy_option_struct
|
191
|
+
proxy_options.inject Options.new do |options, (option, value)|
|
192
|
+
# options that are present will evaluate to true
|
193
|
+
value = true if value.nil?
|
194
|
+
options.__send__ :"#{option}=", value
|
195
|
+
options
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Option proxy proc used when a block is not explicitly passed
|
201
|
+
# via the #option method. This allows commander to auto-populate
|
202
|
+
# and work with option values.
|
203
|
+
|
204
|
+
def option_proc switches
|
205
|
+
lambda { |value| proxy_options << [Runner.switch_to_sym(switches.last), value] }
|
206
|
+
end
|
207
|
+
|
208
|
+
def inspect
|
209
|
+
"<Commander::Command:#{name}>"
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
|
4
|
+
##
|
5
|
+
# Split _string_ into an array. Used in
|
6
|
+
# conjunction with Highline's #ask, or #ask_for_array
|
7
|
+
# methods, which must respond to #parse.
|
8
|
+
#
|
9
|
+
# This method allows escaping of whitespace. For example
|
10
|
+
# the arguments foo bar\ baz will become ['foo', 'bar baz']
|
11
|
+
#
|
12
|
+
# === Example
|
13
|
+
#
|
14
|
+
# # ask invokes Array#parse
|
15
|
+
# list = ask 'Favorite cookies:', Array
|
16
|
+
#
|
17
|
+
# # or use ask_for_CLASS
|
18
|
+
# list = ask_for_array 'Favorite cookies: '
|
19
|
+
#
|
20
|
+
|
21
|
+
def self.parse string
|
22
|
+
# Using reverse + lookahead to work around Ruby 1.8's lack of lookbehind
|
23
|
+
string.reverse.split(/\s(?!\\)/).reverse.map { |s| s.reverse.gsub('\\ ', ' ') }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
module Commander
|
3
|
+
module Delegates
|
4
|
+
%w( add_command command program run! global_option
|
5
|
+
commands alias_command default_command ).each do |meth|
|
6
|
+
eval <<-END, binding, __FILE__, __LINE__
|
7
|
+
def #{meth} *args, &block
|
8
|
+
::Commander::Runner.instance.#{meth} *args, &block
|
9
|
+
end
|
10
|
+
END
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module Commander
|
3
|
+
|
4
|
+
##
|
5
|
+
# = Help Formatter
|
6
|
+
#
|
7
|
+
# Commander's help formatters control the output when
|
8
|
+
# either the help command, or --help switch are called.
|
9
|
+
# The default formatter is Commander::HelpFormatter::Terminal.
|
10
|
+
|
11
|
+
module HelpFormatter
|
12
|
+
class Base
|
13
|
+
def initialize runner; @runner = runner end
|
14
|
+
def render; 'Implement global help here' end
|
15
|
+
def render_command command; "Implement help for #{command.name} here" end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Commander
|
5
|
+
module HelpFormatter
|
6
|
+
class Terminal < Base
|
7
|
+
def render
|
8
|
+
template(:help).result @runner.get_binding
|
9
|
+
end
|
10
|
+
|
11
|
+
def render_command command
|
12
|
+
template(:command_help).result command.get_binding
|
13
|
+
end
|
14
|
+
|
15
|
+
def template name
|
16
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), nil, '-')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
<%= $terminal.color "NAME", :bold %>:
|
3
|
+
|
4
|
+
<%= @name %>
|
5
|
+
<% if @syntax -%>
|
6
|
+
|
7
|
+
<%= $terminal.color "SYNOPSIS", :bold %>:
|
8
|
+
|
9
|
+
<%= @syntax -%>
|
10
|
+
|
11
|
+
<% end -%>
|
12
|
+
|
13
|
+
<%= $terminal.color "DESCRIPTION", :bold %>:
|
14
|
+
|
15
|
+
<%= @description || @summary || 'No description.' -%>
|
16
|
+
|
17
|
+
<% unless @examples.empty? -%>
|
18
|
+
|
19
|
+
<%= $terminal.color "EXAMPLES", :bold %>:
|
20
|
+
<% for description, command in @examples -%>
|
21
|
+
|
22
|
+
# <%= description %>
|
23
|
+
<%= command %>
|
24
|
+
<% end -%>
|
25
|
+
<% end -%>
|
26
|
+
<% unless @options.empty? -%>
|
27
|
+
|
28
|
+
<%= $terminal.color "OPTIONS", :bold %>:
|
29
|
+
<% for option in @options -%>
|
30
|
+
|
31
|
+
<%= option[:switches].join ', ' %>
|
32
|
+
<%= option[:description] %>
|
33
|
+
<% end -%>
|
34
|
+
<% end -%>
|
35
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<%= $terminal.color "NAME", :bold %>:
|
2
|
+
|
3
|
+
<%= program :name %>
|
4
|
+
|
5
|
+
<%= $terminal.color "DESCRIPTION", :bold %>:
|
6
|
+
|
7
|
+
<%= program :description %>
|
8
|
+
|
9
|
+
<%= $terminal.color "COMMANDS", :bold %>:
|
10
|
+
<% for name, command in @commands.sort -%>
|
11
|
+
<% unless alias? name %>
|
12
|
+
<%= "%-20s %s" % [command.name, command.summary || command.description] -%>
|
13
|
+
<% end -%>
|
14
|
+
<% end %>
|
15
|
+
<% unless @aliases.empty? %>
|
16
|
+
<%= $terminal.color "ALIASES", :bold %>:
|
17
|
+
<% for alias_name, args in @aliases.sort %>
|
18
|
+
<%= "%-20s %s %s" % [alias_name, command(alias_name).name, args.join(' ')] -%>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
21
|
+
<% unless @options.empty? -%>
|
22
|
+
<%= $terminal.color "GLOBAL OPTIONS", :bold %>:
|
23
|
+
<% for option in @options -%>
|
24
|
+
|
25
|
+
<%= option[:switches].join ', ' %>
|
26
|
+
<%= option[:description] %>
|
27
|
+
<% end -%>
|
28
|
+
<% end -%>
|
29
|
+
<% if program :help -%>
|
30
|
+
<% for title, body in program(:help) %>
|
31
|
+
<%= $terminal.color title.to_s.upcase, :bold %>:
|
32
|
+
|
33
|
+
<%= body %>
|
34
|
+
<% end -%>
|
35
|
+
<% end -%>
|
36
|
+
|