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.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +1 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +22 -1
  6. data/VERSION +1 -1
  7. data/bin/clone +7 -0
  8. data/clone.gemspec +4 -0
  9. data/docs/readme +16 -0
  10. data/docs/readme.txt +5 -0
  11. data/lib/clone.rb +13 -2
  12. data/lib/clone/config/config.rb +19 -0
  13. data/lib/clone/config/config.yml +22 -0
  14. data/lib/clone/config/default_config.yml +20 -0
  15. data/lib/clone/config/require.rb +3 -0
  16. data/lib/clone/config/version.rb +10 -0
  17. data/lib/clone/config/yml.rb +22 -0
  18. data/lib/clone/config/z_defaults.rb +28 -0
  19. data/lib/clone/generator/engine.rb +581 -0
  20. data/lib/clone/generator/terminal.rb +104 -0
  21. data/lib/clone/helpers/helper_methods.rb +251 -0
  22. data/lib/clone/helpers/local_methods.rb +150 -0
  23. data/lib/clone/helpers/require.rb +37 -0
  24. data/module/Marshal.4.8 +0 -0
  25. data/module/Marshal.4.8.Z +0 -0
  26. data/module/gems/commander-4.1.3/.gitignore +6 -0
  27. data/module/gems/commander-4.1.3/.travis.yml +11 -0
  28. data/module/gems/commander-4.1.3/DEVELOPMENT +15 -0
  29. data/module/gems/commander-4.1.3/Gemfile +3 -0
  30. data/module/gems/commander-4.1.3/History.rdoc +345 -0
  31. data/module/gems/commander-4.1.3/Manifest +38 -0
  32. data/module/gems/commander-4.1.3/README.rdoc +375 -0
  33. data/module/gems/commander-4.1.3/Rakefile +10 -0
  34. data/module/gems/commander-4.1.3/bin/commander +55 -0
  35. data/module/gems/commander-4.1.3/commander.gemspec +26 -0
  36. data/module/gems/commander-4.1.3/lib/commander.rb +32 -0
  37. data/module/gems/commander-4.1.3/lib/commander/blank.rb +8 -0
  38. data/module/gems/commander-4.1.3/lib/commander/command.rb +213 -0
  39. data/module/gems/commander-4.1.3/lib/commander/core_ext.rb +3 -0
  40. data/module/gems/commander-4.1.3/lib/commander/core_ext/array.rb +26 -0
  41. data/module/gems/commander-4.1.3/lib/commander/core_ext/object.rb +11 -0
  42. data/module/gems/commander-4.1.3/lib/commander/delegates.rb +13 -0
  43. data/module/gems/commander-4.1.3/lib/commander/help_formatters.rb +8 -0
  44. data/module/gems/commander-4.1.3/lib/commander/help_formatters/base.rb +18 -0
  45. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal.rb +20 -0
  46. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/command_help.erb +35 -0
  47. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/help.erb +36 -0
  48. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact.rb +12 -0
  49. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/command_help.erb +27 -0
  50. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/help.erb +29 -0
  51. data/module/gems/commander-4.1.3/lib/commander/import.rb +10 -0
  52. data/module/gems/commander-4.1.3/lib/commander/platform.rb +8 -0
  53. data/module/gems/commander-4.1.3/lib/commander/runner.rb +411 -0
  54. data/module/gems/commander-4.1.3/lib/commander/user_interaction.rb +521 -0
  55. data/module/gems/commander-4.1.3/lib/commander/version.rb +3 -0
  56. data/module/gems/commander-4.1.3/spec/command_spec.rb +157 -0
  57. data/module/gems/commander-4.1.3/spec/core_ext/array_spec.rb +20 -0
  58. data/module/gems/commander-4.1.3/spec/core_ext/object_spec.rb +21 -0
  59. data/module/gems/commander-4.1.3/spec/help_formatters/terminal_spec.rb +67 -0
  60. data/module/gems/commander-4.1.3/spec/runner_spec.rb +526 -0
  61. data/module/gems/commander-4.1.3/spec/spec_helper.rb +59 -0
  62. data/module/gems/commander-4.1.3/spec/ui_spec.rb +30 -0
  63. data/module/gems/hello.rb +1 -0
  64. data/module/gems/highline-1.6.19/.gitignore +2 -0
  65. data/module/gems/highline-1.6.19/AUTHORS +3 -0
  66. data/module/gems/highline-1.6.19/CHANGELOG +346 -0
  67. data/module/gems/highline-1.6.19/COPYING +340 -0
  68. data/module/gems/highline-1.6.19/INSTALL +55 -0
  69. data/module/gems/highline-1.6.19/LICENSE +7 -0
  70. data/module/gems/highline-1.6.19/README.rdoc +63 -0
  71. data/module/gems/highline-1.6.19/Rakefile +50 -0
  72. data/module/gems/highline-1.6.19/TODO +6 -0
  73. data/module/gems/highline-1.6.19/examples/ansi_colors.rb +38 -0
  74. data/module/gems/highline-1.6.19/examples/asking_for_arrays.rb +18 -0
  75. data/module/gems/highline-1.6.19/examples/basic_usage.rb +75 -0
  76. data/module/gems/highline-1.6.19/examples/color_scheme.rb +32 -0
  77. data/module/gems/highline-1.6.19/examples/get_character.rb +12 -0
  78. data/module/gems/highline-1.6.19/examples/limit.rb +12 -0
  79. data/module/gems/highline-1.6.19/examples/menus.rb +65 -0
  80. data/module/gems/highline-1.6.19/examples/overwrite.rb +19 -0
  81. data/module/gems/highline-1.6.19/examples/page_and_wrap.rb +322 -0
  82. data/module/gems/highline-1.6.19/examples/password.rb +7 -0
  83. data/module/gems/highline-1.6.19/examples/repeat_entry.rb +21 -0
  84. data/module/gems/highline-1.6.19/examples/trapping_eof.rb +22 -0
  85. data/module/gems/highline-1.6.19/examples/using_readline.rb +17 -0
  86. data/module/gems/highline-1.6.19/highline.gemspec +37 -0
  87. data/module/gems/highline-1.6.19/lib/highline.rb +1012 -0
  88. data/module/gems/highline-1.6.19/lib/highline/color_scheme.rb +134 -0
  89. data/module/gems/highline-1.6.19/lib/highline/compatibility.rb +16 -0
  90. data/module/gems/highline-1.6.19/lib/highline/import.rb +41 -0
  91. data/module/gems/highline-1.6.19/lib/highline/menu.rb +398 -0
  92. data/module/gems/highline-1.6.19/lib/highline/question.rb +475 -0
  93. data/module/gems/highline-1.6.19/lib/highline/simulate.rb +48 -0
  94. data/module/gems/highline-1.6.19/lib/highline/string_extensions.rb +131 -0
  95. data/module/gems/highline-1.6.19/lib/highline/style.rb +181 -0
  96. data/module/gems/highline-1.6.19/lib/highline/system_extensions.rb +222 -0
  97. data/module/gems/highline-1.6.19/setup.rb +1360 -0
  98. data/module/gems/highline-1.6.19/site/.cvsignore +1 -0
  99. data/module/gems/highline-1.6.19/site/highline.css +65 -0
  100. data/module/gems/highline-1.6.19/site/images/logo.png +0 -0
  101. data/module/gems/highline-1.6.19/site/index.html +58 -0
  102. data/module/gems/highline-1.6.19/test/string_methods.rb +32 -0
  103. data/module/gems/highline-1.6.19/test/tc_color_scheme.rb +96 -0
  104. data/module/gems/highline-1.6.19/test/tc_highline.rb +1128 -0
  105. data/module/gems/highline-1.6.19/test/tc_import.rb +52 -0
  106. data/module/gems/highline-1.6.19/test/tc_menu.rb +439 -0
  107. data/module/gems/highline-1.6.19/test/tc_string_extension.rb +20 -0
  108. data/module/gems/highline-1.6.19/test/tc_string_highline.rb +38 -0
  109. data/module/gems/highline-1.6.19/test/tc_style.rb +567 -0
  110. data/module/gems/highline-1.6.19/test/ts_all.rb +16 -0
  111. data/module/latest_specs.4.8 +0 -0
  112. data/module/latest_specs.4.8.gz +0 -0
  113. data/module/prerelease_specs.4.8 +0 -0
  114. data/module/prerelease_specs.4.8.gz +0 -0
  115. data/module/specs.4.8 +0 -0
  116. data/module/specs.4.8.gz +0 -0
  117. data/samples/blather/restlike/Gemfile +4 -0
  118. data/samples/blather/restlike/cmd.yml +1 -0
  119. data/samples/blather/restlike/lib/blather.rb +9 -0
  120. data/samples/blather/restlike/lib/blather/dsl/api.rb +78 -0
  121. data/samples/blather/restlike/lib/blather/dsl/call.rb +13 -0
  122. data/samples/blather/restlike/lib/blather/dsl/client.rb +58 -0
  123. data/samples/blather/restlike/lib/blather/dsl/config.rb +11 -0
  124. data/samples/blather/restlike/lib/blather/dsl/extraDSL.rb +163 -0
  125. data/samples/blather/restlike/lib/blather/meta/require.rb +8 -0
  126. data/samples/blather/restlike/lib/blather/meta/xmpp.yml +5 -0
  127. data/samples/blather/restlike/lib/blather/vendors/xmpp_default.rb +27 -0
  128. data/samples/blather/restlike/readme +2 -0
  129. data/samples/grape/init/Gemfile +2 -0
  130. data/samples/grape/init/cmd.yml +3 -0
  131. data/samples/grape/init/config.ru +2 -0
  132. data/samples/grape/init/docs/grape/documentation.txt +939 -0
  133. data/samples/grape/init/docs/grape/generate_rest_routes.rb +37 -0
  134. data/samples/grape/init/docs/grape/ls_routes.rb +31 -0
  135. data/samples/grape/init/lib/grape.rb +4 -0
  136. data/samples/grape/init/lib/grape/meta/subclasses.rb +20 -0
  137. data/samples/grape/init/lib/grape/xpath/app.rb +30 -0
  138. data/samples/grape/init/lib/grape/xpath/ruotes.rb +6 -0
  139. data/samples/grape/init/readme +1 -0
  140. data/samples/grape/readme +29 -0
  141. data/samples/grape/vendor/lib/grape/vendors/v1/rest.rb +57 -0
  142. data/samples/mongoid/cmd.yml +1 -0
  143. data/samples/mongoid/init/Gemfile +3 -0
  144. data/samples/mongoid/init/cmd.yml +2 -0
  145. data/samples/mongoid/init/docs/mongoid/ModelsRelations.rb +11 -0
  146. data/samples/mongoid/init/docs/mongoid/documents.xls +0 -0
  147. data/samples/mongoid/init/docs/mongoid/generate_modelsToDocs.rb +25 -0
  148. data/samples/mongoid/init/docs/mongoid/modelsToDocs.rb +25 -0
  149. data/samples/mongoid/init/docs/mongoid/relations.txt +1354 -0
  150. data/samples/mongoid/init/lib/mongoid.rb +44 -0
  151. data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_CRUD.rb +446 -0
  152. data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_MP.rb +517 -0
  153. data/samples/mongoid/init/lib/mongoid/dsl/init.rb +37 -0
  154. data/samples/mongoid/init/lib/mongoid/dsl/params.rb +67 -0
  155. data/samples/mongoid/init/lib/mongoid/meta/banned.rb +147 -0
  156. data/samples/mongoid/init/lib/mongoid/meta/control.yml +13 -0
  157. data/samples/mongoid/init/lib/mongoid/meta/mongoid.yml +6 -0
  158. data/samples/mongoid/init/lib/mongoid/meta/mpatch.rb +14 -0
  159. data/samples/mongoid/model/lib/mongoid/models/model.rb +28 -0
  160. data/samples/mongoid/readme +33 -0
  161. data/samples/rack/init/Gemfile +10 -0
  162. data/samples/rack/init/cmd.yml +2 -0
  163. data/samples/rack/init/config.ru +1 -0
  164. data/samples/rack/init/docs/rack/rake introducing.txt +60 -0
  165. data/samples/rack/init/docs/rack/webservers/Thin +43 -0
  166. data/samples/rack/init/docs/rack/webservers/ebb +72 -0
  167. data/samples/rack/init/docs/rack/webservers/fcgi +103 -0
  168. data/samples/rack/init/docs/rack/webservers/mongrel +74 -0
  169. data/samples/rack/init/docs/rack/webservers/passenger +37 -0
  170. data/samples/rack/init/docs/rack/webservers/scgi +188 -0
  171. data/samples/rack/init/lib/rack.rb +1 -0
  172. data/samples/rack/init/lib/rack/meta/webserver/thin.rb +45 -0
  173. data/samples/rack/init/lib/rack/meta/webserver/thin.yml +6 -0
  174. data/samples/rack/init/server.rb +0 -0
  175. data/samples/rack/readme +13 -0
  176. data/samples/rest_client/init/Gemfile +5 -0
  177. data/samples/rest_client/init/boot.rb +2 -0
  178. data/samples/rest_client/init/cmd.yml +1 -0
  179. data/samples/rest_client/init/config/rest_client/defaults.rb +16 -0
  180. data/samples/rest_client/init/docs/rest_client/simple overlook +251 -0
  181. data/samples/rest_client/init/test/rest_client/rest_dsl.rb +5 -0
  182. data/samples/rest_client/readme +7 -0
  183. data/samples/scripts/lines_counter/lines_number.rb +32 -0
  184. data/samples/scripts/lines_counter/readme +5 -0
  185. data/samples/scripts/readme +1 -0
  186. metadata +197 -7
  187. data/lib/clone/cms.rb +0 -56
  188. data/lib/clone/ext.rb +0 -77
  189. data/sample/test.rb +0 -30
@@ -0,0 +1,134 @@
1
+ # color_scheme.rb
2
+ #
3
+ # Created by Jeremy Hinegardner on 2007-01-24
4
+ # Copyright 2007. All rights reserved
5
+ #
6
+ # This is Free Software. See LICENSE and COPYING for details
7
+
8
+ class HighLine
9
+ #
10
+ # ColorScheme objects encapsulate a named set of colors to be used in the
11
+ # HighLine.colors() method call. For example, by applying a ColorScheme that
12
+ # has a <tt>:warning</tt> color then the following could be used:
13
+ #
14
+ # colors("This is a warning", :warning)
15
+ #
16
+ # A ColorScheme contains named sets of HighLine color constants.
17
+ #
18
+ # Example: Instantiating a color scheme, applying it to HighLine,
19
+ # and using it:
20
+ #
21
+ # ft = HighLine::ColorScheme.new do |cs|
22
+ # cs[:headline] = [ :bold, :yellow, :on_black ]
23
+ # cs[:horizontal_line] = [ :bold, :white ]
24
+ # cs[:even_row] = [ :green ]
25
+ # cs[:odd_row] = [ :magenta ]
26
+ # end
27
+ #
28
+ # HighLine.color_scheme = ft
29
+ # say("<%= color('Headline', :headline) %>")
30
+ # say("<%= color('-'*20, :horizontal_line) %>")
31
+ # i = true
32
+ # ("A".."D").each do |row|
33
+ # if i then
34
+ # say("<%= color('#{row}', :even_row ) %>")
35
+ # else
36
+ # say("<%= color('#{row}', :odd_row) %>")
37
+ # end
38
+ # i = !i
39
+ # end
40
+ #
41
+ #
42
+ class ColorScheme
43
+ #
44
+ # Create an instance of HighLine::ColorScheme. The customization can
45
+ # happen as a passed in Hash or via the yielded block. Keys are
46
+ # converted to <tt>:symbols</tt> and values are converted to HighLine
47
+ # constants.
48
+ #
49
+ def initialize( h = nil )
50
+ @scheme = Hash.new
51
+ load_from_hash(h) unless h.nil?
52
+ yield self if block_given?
53
+ end
54
+
55
+ # Load multiple colors from key/value pairs.
56
+ def load_from_hash( h )
57
+ h.each_pair do |color_tag, constants|
58
+ self[color_tag] = constants
59
+ end
60
+ end
61
+
62
+ # Does this color scheme include the given tag name?
63
+ def include?( color_tag )
64
+ @scheme.keys.include?(to_symbol(color_tag))
65
+ end
66
+
67
+ # Allow the scheme to be accessed like a Hash.
68
+ def []( color_tag )
69
+ @scheme[to_symbol(color_tag)]
70
+ end
71
+
72
+ # Retrieve the original form of the scheme
73
+ def definition( color_tag )
74
+ style = @scheme[to_symbol(color_tag)]
75
+ style && style.list
76
+ end
77
+
78
+ # Retrieve the keys in the scheme
79
+ def keys
80
+ @scheme.keys
81
+ end
82
+
83
+ # Allow the scheme to be set like a Hash.
84
+ def []=( color_tag, constants )
85
+ @scheme[to_symbol(color_tag)] = HighLine::Style.new(:name=>color_tag.to_s.downcase.to_sym,
86
+ :list=>constants, :no_index=>true)
87
+ end
88
+
89
+ # Retrieve the color scheme hash (in original definition format)
90
+ def to_hash
91
+ @scheme.inject({}) { |hsh, pair| key, value = pair; hsh[key] = value.list; hsh }
92
+ end
93
+
94
+
95
+ private
96
+
97
+ # Return a normalized representation of a color name.
98
+ def to_symbol( t )
99
+ t.to_s.downcase
100
+ end
101
+
102
+ # Return a normalized representation of a color setting.
103
+ def to_constant( v )
104
+ v = v.to_s if v.is_a?(Symbol)
105
+ if v.is_a?(::String) then
106
+ HighLine.const_get(v.upcase)
107
+ else
108
+ v
109
+ end
110
+ end
111
+ end
112
+
113
+ # A sample ColorScheme.
114
+ class SampleColorScheme < ColorScheme
115
+ #
116
+ # Builds the sample scheme with settings for <tt>:critical</tt>,
117
+ # <tt>:error</tt>, <tt>:warning</tt>, <tt>:notice</tt>, <tt>:info</tt>,
118
+ # <tt>:debug</tt>, <tt>:row_even</tt>, and <tt>:row_odd</tt> colors.
119
+ #
120
+ def initialize( h = nil )
121
+ scheme = {
122
+ :critical => [ :yellow, :on_red ],
123
+ :error => [ :bold, :red ],
124
+ :warning => [ :bold, :yellow ],
125
+ :notice => [ :bold, :magenta ],
126
+ :info => [ :bold, :cyan ],
127
+ :debug => [ :bold, :green ],
128
+ :row_even => [ :cyan ],
129
+ :row_odd => [ :magenta ]
130
+ }
131
+ super(scheme)
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,16 @@
1
+ unless STDIN.respond_to? :getbyte
2
+ class IO
3
+ alias_method :getbyte, :getc
4
+ end
5
+
6
+ class StringIO
7
+ alias_method :getbyte, :getc
8
+ end
9
+ end
10
+
11
+ unless "".respond_to? :each_line
12
+ # Not a perfect translation, but sufficient for our needs.
13
+ class String
14
+ alias_method :each_line, :each
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ # import.rb
2
+ #
3
+ # Created by James Edward Gray II on 2005-04-26.
4
+ # Copyright 2005 Gray Productions. All rights reserved.
5
+ #
6
+ # This is Free Software. See LICENSE and COPYING for details.
7
+
8
+ require "highline"
9
+ require "forwardable"
10
+
11
+ $terminal = HighLine.new
12
+
13
+ #
14
+ # <tt>require "highline/import"</tt> adds shortcut methods to Kernel, making
15
+ # agree(), ask(), choose() and say() globally available. This is handy for
16
+ # quick and dirty input and output. These methods use the HighLine object in
17
+ # the global variable <tt>$terminal</tt>, which is initialized to used
18
+ # <tt>$stdin</tt> and <tt>$stdout</tt> (you are free to change this).
19
+ # Otherwise, these methods are identical to their HighLine counterparts, see that
20
+ # class for detailed explanations.
21
+ #
22
+ module Kernel
23
+ extend Forwardable
24
+ def_delegators :$terminal, :agree, :ask, :choose, :say
25
+ end
26
+
27
+ class Object
28
+ #
29
+ # Tries this object as a _first_answer_ for a HighLine::Question. See that
30
+ # attribute for details.
31
+ #
32
+ # *Warning*: This Object will be passed to String() before set.
33
+ #
34
+ def or_ask( *args, &details )
35
+ ask(*args) do |question|
36
+ question.first_answer = String(self) unless nil?
37
+
38
+ details.call(question) unless details.nil?
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,398 @@
1
+ # menu.rb
2
+ #
3
+ # Created by Gregory Thomas Brown on 2005-05-10.
4
+ # Copyright 2005. All rights reserved.
5
+ #
6
+ # This is Free Software. See LICENSE and COPYING for details.
7
+
8
+ require "highline/question"
9
+
10
+ class HighLine
11
+ #
12
+ # Menu objects encapsulate all the details of a call to HighLine.choose().
13
+ # Using the accessors and Menu.choice() and Menu.choices(), the block passed
14
+ # to HighLine.choose() can detail all aspects of menu display and control.
15
+ #
16
+ class Menu < Question
17
+ #
18
+ # Create an instance of HighLine::Menu. All customization is done
19
+ # through the passed block, which should call accessors and choice() and
20
+ # choices() as needed to define the Menu. Note that Menus are also
21
+ # Questions, so all that functionality is available to the block as
22
+ # well.
23
+ #
24
+ def initialize( )
25
+ #
26
+ # Initialize Question objects with ignored values, we'll
27
+ # adjust ours as needed.
28
+ #
29
+ super("Ignored", [ ], &nil) # avoiding passing the block along
30
+
31
+ @items = [ ]
32
+ @hidden_items = [ ]
33
+ @help = Hash.new("There's no help for that topic.")
34
+
35
+ @index = :number
36
+ @index_suffix = ". "
37
+ @select_by = :index_or_name
38
+ @flow = :rows
39
+ @list_option = nil
40
+ @header = nil
41
+ @prompt = "? "
42
+ @layout = :list
43
+ @shell = false
44
+ @nil_on_handled = false
45
+
46
+ # Override Questions responses, we'll set our own.
47
+ @responses = { }
48
+ # Context for action code.
49
+ @highline = nil
50
+
51
+ yield self if block_given?
52
+
53
+ init_help if @shell and not @help.empty?
54
+ end
55
+
56
+ #
57
+ # An _index_ to append to each menu item in display. See
58
+ # Menu.index=() for details.
59
+ #
60
+ attr_reader :index
61
+ #
62
+ # The String placed between an _index_ and a menu item. Defaults to
63
+ # ". ". Switches to " ", when _index_ is set to a String (like "-").
64
+ #
65
+ attr_accessor :index_suffix
66
+ #
67
+ # The _select_by_ attribute controls how the user is allowed to pick a
68
+ # menu item. The available choices are:
69
+ #
70
+ # <tt>:index</tt>:: The user is allowed to type the numerical
71
+ # or alphabetical index for their selection.
72
+ # <tt>:index_or_name</tt>:: Allows both methods from the
73
+ # <tt>:index</tt> option and the
74
+ # <tt>:name</tt> option.
75
+ # <tt>:name</tt>:: Menu items are selected by typing a portion
76
+ # of the item name that will be
77
+ # auto-completed.
78
+ #
79
+ attr_accessor :select_by
80
+ #
81
+ # This attribute is passed directly on as the mode to HighLine.list() by
82
+ # all the preset layouts. See that method for appropriate settings.
83
+ #
84
+ attr_accessor :flow
85
+ #
86
+ # This setting is passed on as the third parameter to HighLine.list()
87
+ # by all the preset layouts. See that method for details of its
88
+ # effects. Defaults to +nil+.
89
+ #
90
+ attr_accessor :list_option
91
+ #
92
+ # Used by all the preset layouts to display title and/or introductory
93
+ # information, when set. Defaults to +nil+.
94
+ #
95
+ attr_accessor :header
96
+ #
97
+ # Used by all the preset layouts to ask the actual question to fetch a
98
+ # menu selection from the user. Defaults to "? ".
99
+ #
100
+ attr_accessor :prompt
101
+ #
102
+ # An ERb _layout_ to use when displaying this Menu object. See
103
+ # Menu.layout=() for details.
104
+ #
105
+ attr_reader :layout
106
+ #
107
+ # When set to +true+, responses are allowed to be an entire line of
108
+ # input, including details beyond the command itself. Only the first
109
+ # "word" of input will be matched against the menu choices, but both the
110
+ # command selected and the rest of the line will be passed to provided
111
+ # action blocks. Defaults to +false+.
112
+ #
113
+ attr_accessor :shell
114
+ #
115
+ # When +true+, any selected item handled by provided action code will
116
+ # return +nil+, instead of the results to the action code. This may
117
+ # prove handy when dealing with mixed menus where only the names of
118
+ # items without any code (and +nil+, of course) will be returned.
119
+ # Defaults to +false+.
120
+ #
121
+ attr_accessor :nil_on_handled
122
+
123
+ #
124
+ # Adds _name_ to the list of available menu items. Menu items will be
125
+ # displayed in the order they are added.
126
+ #
127
+ # An optional _action_ can be associated with this name and if provided,
128
+ # it will be called if the item is selected. The result of the method
129
+ # will be returned, unless _nil_on_handled_ is set (when you would get
130
+ # +nil+ instead). In _shell_ mode, a provided block will be passed the
131
+ # command chosen and any details that followed the command. Otherwise,
132
+ # just the command is passed. The <tt>@highline</tt> variable is set to
133
+ # the current HighLine context before the action code is called and can
134
+ # thus be used for adding output and the like.
135
+ #
136
+ def choice( name, help = nil, &action )
137
+ @items << [name, action]
138
+
139
+ @help[name.to_s.downcase] = help unless help.nil?
140
+ update_responses # rebuild responses based on our settings
141
+ end
142
+
143
+ #
144
+ # A shortcut for multiple calls to the sister method choice(). <b>Be
145
+ # warned:</b> An _action_ set here will apply to *all* provided
146
+ # _names_. This is considered to be a feature, so you can easily
147
+ # hand-off interface processing to a different chunk of code.
148
+ #
149
+ def choices( *names, &action )
150
+ names.each { |n| choice(n, &action) }
151
+ end
152
+
153
+ # Identical to choice(), but the item will not be listed for the user.
154
+ def hidden( name, help = nil, &action )
155
+ @hidden_items << [name, action]
156
+
157
+ @help[name.to_s.downcase] = help unless help.nil?
158
+ end
159
+
160
+ #
161
+ # Sets the indexing style for this Menu object. Indexes are appended to
162
+ # menu items, when displayed in list form. The available settings are:
163
+ #
164
+ # <tt>:number</tt>:: Menu items will be indexed numerically, starting
165
+ # with 1. This is the default method of indexing.
166
+ # <tt>:letter</tt>:: Items will be indexed alphabetically, starting
167
+ # with a.
168
+ # <tt>:none</tt>:: No index will be appended to menu items.
169
+ # <i>any String</i>:: Will be used as the literal _index_.
170
+ #
171
+ # Setting the _index_ to <tt>:none</tt> or a literal String also adjusts
172
+ # _index_suffix_ to a single space and _select_by_ to <tt>:name</tt>.
173
+ # Because of this, you should make a habit of setting the _index_ first.
174
+ #
175
+ def index=( style )
176
+ @index = style
177
+
178
+ # Default settings.
179
+ if @index == :none or @index.is_a?(::String)
180
+ @index_suffix = " "
181
+ @select_by = :name
182
+ end
183
+ end
184
+
185
+ #
186
+ # Initializes the help system by adding a <tt>:help</tt> choice, some
187
+ # action code, and the default help listing.
188
+ #
189
+ def init_help( )
190
+ return if @items.include?(:help)
191
+
192
+ topics = @help.keys.sort
193
+ help_help = @help.include?("help") ? @help["help"] :
194
+ "This command will display helpful messages about " +
195
+ "functionality, like this one. To see the help for " +
196
+ "a specific topic enter:\n\thelp [TOPIC]\nTry asking " +
197
+ "for help on any of the following:\n\n" +
198
+ "<%= list(#{topics.inspect}, :columns_across) %>"
199
+ choice(:help, help_help) do |command, topic|
200
+ topic.strip!
201
+ topic.downcase!
202
+ if topic.empty?
203
+ @highline.say(@help["help"])
204
+ else
205
+ @highline.say("= #{topic}\n\n#{@help[topic]}")
206
+ end
207
+ end
208
+ end
209
+
210
+ #
211
+ # Used to set help for arbitrary topics. Use the topic <tt>"help"</tt>
212
+ # to override the default message.
213
+ #
214
+ def help( topic, help )
215
+ @help[topic] = help
216
+ end
217
+
218
+ #
219
+ # Setting a _layout_ with this method also adjusts some other attributes
220
+ # of the Menu object, to ideal defaults for the chosen _layout_. To
221
+ # account for that, you probably want to set a _layout_ first in your
222
+ # configuration block, if needed.
223
+ #
224
+ # Accepted settings for _layout_ are:
225
+ #
226
+ # <tt>:list</tt>:: The default _layout_. The _header_ if set
227
+ # will appear at the top on its own line with
228
+ # a trailing colon. Then the list of menu
229
+ # items will follow. Finally, the _prompt_
230
+ # will be used as the ask()-like question.
231
+ # <tt>:one_line</tt>:: A shorter _layout_ that fits on one line.
232
+ # The _header_ comes first followed by a
233
+ # colon and spaces, then the _prompt_ with menu
234
+ # items between trailing parenthesis.
235
+ # <tt>:menu_only</tt>:: Just the menu items, followed up by a likely
236
+ # short _prompt_.
237
+ # <i>any ERb String</i>:: Will be taken as the literal _layout_. This
238
+ # String can access <tt>@header</tt>,
239
+ # <tt>@menu</tt> and <tt>@prompt</tt>, but is
240
+ # otherwise evaluated in the typical HighLine
241
+ # context, to provide access to utilities like
242
+ # HighLine.list() primarily.
243
+ #
244
+ # If set to either <tt>:one_line</tt>, or <tt>:menu_only</tt>, _index_
245
+ # will default to <tt>:none</tt> and _flow_ will default to
246
+ # <tt>:inline</tt>.
247
+ #
248
+ def layout=( new_layout )
249
+ @layout = new_layout
250
+
251
+ # Default settings.
252
+ case @layout
253
+ when :one_line, :menu_only
254
+ self.index = :none
255
+ @flow = :inline
256
+ end
257
+ end
258
+
259
+ #
260
+ # This method returns all possible options for auto-completion, based
261
+ # on the settings of _index_ and _select_by_.
262
+ #
263
+ def options( )
264
+ # add in any hidden menu commands
265
+ @items.concat(@hidden_items)
266
+
267
+ by_index = if @index == :letter
268
+ l_index = "`"
269
+ @items.map { "#{l_index.succ!}" }
270
+ else
271
+ (1 .. @items.size).collect { |s| String(s) }
272
+ end
273
+ by_name = @items.collect { |c| c.first }
274
+
275
+ case @select_by
276
+ when :index then
277
+ by_index
278
+ when :name
279
+ by_name
280
+ else
281
+ by_index + by_name
282
+ end
283
+ ensure
284
+ # make sure the hidden items are removed, before we return
285
+ @items.slice!(@items.size - @hidden_items.size, @hidden_items.size)
286
+ end
287
+
288
+ #
289
+ # This method processes the auto-completed user selection, based on the
290
+ # rules for this Menu object. If an action was provided for the
291
+ # selection, it will be executed as described in Menu.choice().
292
+ #
293
+ def select( highline_context, selection, details = nil )
294
+ # add in any hidden menu commands
295
+ @items.concat(@hidden_items)
296
+
297
+ # Find the selected action.
298
+ name, action = if selection =~ /^\d+$/
299
+ @items[selection.to_i - 1]
300
+ else
301
+ l_index = "`"
302
+ index = @items.map { "#{l_index.succ!}" }.index(selection)
303
+ @items.find { |c| c.first == selection } or @items[index]
304
+ end
305
+
306
+ # Run or return it.
307
+ if not action.nil?
308
+ @highline = highline_context
309
+ if @shell
310
+ result = action.call(name, details)
311
+ else
312
+ result = action.call(name)
313
+ end
314
+ @nil_on_handled ? nil : result
315
+ elsif action.nil?
316
+ name
317
+ else
318
+ nil
319
+ end
320
+ ensure
321
+ # make sure the hidden items are removed, before we return
322
+ @items.slice!(@items.size - @hidden_items.size, @hidden_items.size)
323
+ end
324
+
325
+ #
326
+ # Allows Menu objects to pass as Arrays, for use with HighLine.list().
327
+ # This method returns all menu items to be displayed, complete with
328
+ # indexes.
329
+ #
330
+ def to_ary( )
331
+ case @index
332
+ when :number
333
+ @items.map { |c| "#{@items.index(c) + 1}#{@index_suffix}#{c.first}" }
334
+ when :letter
335
+ l_index = "`"
336
+ @items.map { |c| "#{l_index.succ!}#{@index_suffix}#{c.first}" }
337
+ when :none
338
+ @items.map { |c| "#{c.first}" }
339
+ else
340
+ @items.map { |c| "#{index}#{@index_suffix}#{c.first}" }
341
+ end
342
+ end
343
+
344
+ #
345
+ # Allows Menu to behave as a String, just like Question. Returns the
346
+ # _layout_ to be rendered, which is used by HighLine.say().
347
+ #
348
+ def to_str( )
349
+ case @layout
350
+ when :list
351
+ '<%= if @header.nil? then '' else "#{@header}:\n" end %>' +
352
+ "<%= list( @menu, #{@flow.inspect},
353
+ #{@list_option.inspect} ) %>" +
354
+ "<%= @prompt %>"
355
+ when :one_line
356
+ '<%= if @header.nil? then '' else "#{@header}: " end %>' +
357
+ "<%= @prompt %>" +
358
+ "(<%= list( @menu, #{@flow.inspect},
359
+ #{@list_option.inspect} ) %>)" +
360
+ "<%= @prompt[/\s*$/] %>"
361
+ when :menu_only
362
+ "<%= list( @menu, #{@flow.inspect},
363
+ #{@list_option.inspect} ) %><%= @prompt %>"
364
+ else
365
+ @layout
366
+ end
367
+ end
368
+
369
+ #
370
+ # This method will update the intelligent responses to account for
371
+ # Menu specific differences. This overrides the work done by
372
+ # Question.build_responses().
373
+ #
374
+ def update_responses( )
375
+ append_default unless default.nil?
376
+ @responses = @responses.merge(
377
+ :ambiguous_completion =>
378
+ "Ambiguous choice. " +
379
+ "Please choose one of #{options.inspect}.",
380
+ :ask_on_error =>
381
+ "? ",
382
+ :invalid_type =>
383
+ "You must enter a valid #{options}.",
384
+ :no_completion =>
385
+ "You must choose one of " +
386
+ "#{options.inspect}.",
387
+ :not_in_range =>
388
+ "Your answer isn't within the expected range " +
389
+ "(#{expected_range}).",
390
+ :mismatch =>
391
+ "Your entries didn't match.",
392
+ :not_valid =>
393
+ "Your answer isn't valid (must match " +
394
+ "#{@validate.inspect})."
395
+ )
396
+ end
397
+ end
398
+ end