File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def self.included(base)
2222
2323 #
2424 # Default initializer, simply takes a hash of settings
25- # to set attributes via writer methods. Not existnt
25+ # to set attributes via writer methods. Not existant
2626 # attributes are simply ignored.
2727 #
2828 def initialize ( settings = { } )
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module Executable
22
33 # Variation of Executable which provides basic compatibility with
44 # previous versions of Executable. It provides a call method that
5- # automatically dispatches to publich methods.
5+ # automatically dispatches to public methods.
66 #
77 # Among other uses, Dispatch can be useful for dropping into any class
88 # as a quick and dirty way to work with it on the command line.
Original file line number Diff line number Diff line change @@ -3,6 +3,28 @@ module Executable
33 #
44 module Domain
55
6+ #
7+ def usage_name
8+ list = [ ]
9+ ancestors . each do |ancestor |
10+ break if Executable == ancestor
11+ list . unshift calculate_command_name ( ancestor ) . to_s . strip
12+ end
13+ list . reject { |n | n . empty? } . join ( " " )
14+ end
15+
16+ #
17+ def calculate_command_name ( ancestor )
18+ if ancestor . methods ( false ) . include? ( :command_name )
19+ command_name . to_s
20+ else
21+ cname = ancestor . name . sub ( /\# \< .*?\> \: \: / , '' ) . split ( '::' ) . last . downcase
22+ cname . chomp ( 'command' ) . chomp ( 'cli' )
23+ end
24+ end
25+
26+ private :calculate_command_name
27+
628 #
729 # Helper method for creating switch attributes.
830 #
Original file line number Diff line number Diff line change @@ -63,10 +63,7 @@ def initialize(cli_class)
6363 # @method name(text=nil)
6464 #
6565 section ( :name ) do
66- str = cli_class . name . sub ( /\# \< .*?\> \: \: / , '' ) . downcase . gsub ( '::' , '-' )
67- str . chomp! ( 'command' )
68- str . chomp! ( 'cli' )
69- str
66+ cli_class . usage_name
7067 end
7168
7269 #
@@ -122,7 +119,7 @@ def subcommand(name, description)
122119 #
123120 # Show help.
124121 #
125- # @todo man-pages will probably fail on Windows
122+ # @todo man-pages will probably fail on Windows.
126123 #
127124 def show_help ( hint = nil )
128125 if file = manpage ( hint )
@@ -132,6 +129,9 @@ def show_help(hint=nil)
132129 end
133130 end
134131
132+ #
133+ alias :show :show_help
134+
135135 #
136136 def show_manpage ( file )
137137 #exec "man #{file}"
@@ -155,8 +155,10 @@ def manpage(dir=nil)
155155 dir = File . dirname ( file )
156156 end
157157
158+ man_name = name . gsub ( /\s +/ , '-' ) + '.1'
159+
158160 if dir
159- glob = "man/{man1/,}#{ name } .1 "
161+ glob = "man/{man1/,}#{ man_name } "
160162 lookup ( glob , dir )
161163 else
162164 nil
You can’t perform that action at this time.
0 commit comments