rcoli 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/lib/rcoli/help.rb +12 -3
- data/lib/rcoli/model.rb +15 -5
- data/lib/rcoli/templates/help.erb +10 -6
- data/lib/rcoli/templates/help_command.erb +23 -0
- data/lib/rcoli/version.rb +1 -1
- data/lib/rcoli.rb +1 -1
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/lib/rcoli/help.rb
CHANGED
@@ -4,11 +4,20 @@ module RCoLi
|
|
4
4
|
|
5
5
|
module Help
|
6
6
|
|
7
|
-
def help
|
8
|
-
|
7
|
+
def help(*args)
|
8
|
+
if args[0].empty?
|
9
|
+
puts template('help', nil)
|
10
|
+
else
|
11
|
+
command = self
|
12
|
+
args[0].each do |arg|
|
13
|
+
command = command.find_command(arg)
|
14
|
+
raise InvalidCommand, "'#{arg}' is not a valid #{@name} command" unless command
|
15
|
+
end
|
16
|
+
puts template('help_command', command)
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
|
-
def template(name)
|
20
|
+
def template(name, command)
|
12
21
|
ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', "#{name}.erb")), nil, '-').result binding
|
13
22
|
end
|
14
23
|
|
data/lib/rcoli/model.rb
CHANGED
@@ -71,16 +71,16 @@ module RCoLi
|
|
71
71
|
parse_args(args, result)
|
72
72
|
end
|
73
73
|
|
74
|
+
def find_command(name)
|
75
|
+
commands.find{|command| command.value_of_name.eql? name}
|
76
|
+
end
|
77
|
+
|
74
78
|
private
|
75
79
|
|
76
80
|
def find_option(name)
|
77
81
|
options.find{|opt| opt.correspond?(name)}
|
78
82
|
end
|
79
|
-
|
80
|
-
def find_command(name)
|
81
|
-
commands.find{|command| command.value_of_name.eql? name}
|
82
|
-
end
|
83
|
-
|
83
|
+
|
84
84
|
def is_option?(value)
|
85
85
|
value.start_with?('-')
|
86
86
|
end
|
@@ -141,6 +141,16 @@ module RCoLi
|
|
141
141
|
|
142
142
|
include CommandContainer
|
143
143
|
|
144
|
+
def full_command
|
145
|
+
command = self
|
146
|
+
result = []
|
147
|
+
while(command.parent) do
|
148
|
+
result << command.value_of_name
|
149
|
+
command = command.parent
|
150
|
+
end
|
151
|
+
return result.reverse.join(' ')
|
152
|
+
end
|
153
|
+
|
144
154
|
end
|
145
155
|
|
146
156
|
class Program
|
@@ -1,16 +1,20 @@
|
|
1
1
|
<%= $terminal.color "NAME", :bold %>:
|
2
|
-
|
2
|
+
|
3
|
+
<%= @name %> - <%= @description %>
|
3
4
|
|
5
|
+
<%= $terminal.color "SYNOPSIS", :bold %>:
|
6
|
+
|
7
|
+
<%=@name%> [global options] command [command options] [arguments...]
|
8
|
+
|
4
9
|
<%= $terminal.color "VERSION", :bold %>:
|
10
|
+
|
5
11
|
<%= @version %>
|
6
12
|
|
7
|
-
<%= $terminal.color "DESCRIPTION", :bold %>:
|
8
|
-
<%= @description %>
|
9
|
-
|
10
13
|
<%= $terminal.color "COMMANDS", :bold %>:
|
11
|
-
|
14
|
+
|
15
|
+
<% @commands.sort{|a,b| a.value_of_name <=> b.value_of_name}.each do |c| -%>
|
12
16
|
<%= "%-20s %s" % [c.value_of_name, c.value_of_description] %>
|
13
|
-
|
17
|
+
<% end -%>
|
14
18
|
|
15
19
|
<% unless @options.empty? -%>
|
16
20
|
<%= $terminal.color "GLOBAL OPTIONS", :bold %>:
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%= $terminal.color "NAME", :bold %>:
|
2
|
+
|
3
|
+
<%= command.full_command %> - <%= command.value_of_description %>
|
4
|
+
|
5
|
+
<%= $terminal.color "SYNOPSIS", :bold %>:
|
6
|
+
|
7
|
+
<%= @name %> [global options] <%= command.full_command%> [command options] [arguments...]
|
8
|
+
|
9
|
+
<% unless command.commands.empty? -%>
|
10
|
+
<%= $terminal.color "SUBCOMMANDS", :bold %>:
|
11
|
+
|
12
|
+
<% command.commands.sort{|a,b| a.value_of_name <=> b.value_of_name}.each do |c| -%>
|
13
|
+
<%= "%-20s %s" % [c.value_of_name, c.value_of_description] %>
|
14
|
+
<% end %>
|
15
|
+
<% end -%>
|
16
|
+
|
17
|
+
<% unless command.options.empty? -%>
|
18
|
+
<%= $terminal.color "COMMAND OPTIONS", :bold %>:
|
19
|
+
<% for option in command.options -%>
|
20
|
+
<%= option.help_keys.join ', ' %>
|
21
|
+
<%= option.value_of_description %>
|
22
|
+
<% end -%>
|
23
|
+
<% end -%>
|
data/lib/rcoli/version.rb
CHANGED
data/lib/rcoli.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcoli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/rcoli/help.rb
|
61
61
|
- lib/rcoli/model.rb
|
62
62
|
- lib/rcoli/templates/help.erb
|
63
|
+
- lib/rcoli/templates/help_command.erb
|
63
64
|
- lib/rcoli/version.rb
|
64
65
|
- rcoli.gemspec
|
65
66
|
homepage: http://jiripisa.com
|
@@ -76,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
77
|
version: '0'
|
77
78
|
segments:
|
78
79
|
- 0
|
79
|
-
hash: -
|
80
|
+
hash: -2525730890181152634
|
80
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
82
|
none: false
|
82
83
|
requirements:
|
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
86
|
version: '0'
|
86
87
|
segments:
|
87
88
|
- 0
|
88
|
-
hash: -
|
89
|
+
hash: -2525730890181152634
|
89
90
|
requirements: []
|
90
91
|
rubyforge_project:
|
91
92
|
rubygems_version: 1.8.24
|