clio 0.0.1 → 0.2.0

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.
Files changed (181) hide show
  1. data/CHANGES +66 -0
  2. data/MANIFEST +48 -169
  3. data/README +13 -17
  4. data/RELEASE +8 -0
  5. data/VERSION +1 -0
  6. data/lib/clio/buffer.rb +93 -0
  7. data/lib/clio/commandable.rb +71 -69
  8. data/lib/clio/commandline.rb +429 -230
  9. data/lib/clio/consoleutils.rb +0 -16
  10. data/lib/clio/facets/kernel.rb +13 -0
  11. data/lib/clio/facets/string.rb +25 -0
  12. data/lib/clio/layout.rb +14 -0
  13. data/lib/clio/layout/flow.rb +1 -0
  14. data/lib/clio/layout/line.rb +23 -0
  15. data/lib/clio/layout/list.rb +33 -0
  16. data/lib/clio/layout/split.rb +122 -0
  17. data/lib/clio/layout/stack.rb +17 -0
  18. data/lib/clio/layout/table.rb +46 -0
  19. data/lib/clio/progressbar.rb +189 -210
  20. data/lib/clio/string.rb +116 -109
  21. data/lib/clio/usage.rb +184 -0
  22. data/lib/clio/usage/argument.rb +84 -0
  23. data/lib/clio/usage/command.rb +440 -0
  24. data/lib/clio/usage/interface.rb +122 -0
  25. data/lib/clio/usage/main.rb +165 -0
  26. data/lib/clio/usage/option.rb +251 -0
  27. data/lib/clio/usage/parser.rb +191 -0
  28. data/lib/clio/usage/signature.rb +55 -0
  29. data/meta/abstract +3 -0
  30. data/meta/authors +1 -0
  31. data/meta/created +1 -0
  32. data/meta/homepage +1 -0
  33. data/meta/license +1 -0
  34. data/meta/repository +1 -0
  35. data/meta/summary +1 -0
  36. data/spec/commandline/autousage.rd +56 -0
  37. data/spec/commandline/bracket.rd +64 -0
  38. data/spec/commandline/completion.rd +38 -0
  39. data/spec/commandline/define.rd +44 -0
  40. data/spec/commandline/method.rd +60 -0
  41. data/spec/commandline/parse.rd +72 -0
  42. data/spec/commandline/scenario.rd +81 -0
  43. data/spec/commandline/subclass.rd +54 -0
  44. data/spec/string/unit.rd +58 -0
  45. data/spec/usage/define.rd +44 -0
  46. data/spec/usage/parse.rd +47 -0
  47. metadata +65 -196
  48. data/HISTORY +0 -11
  49. data/METADATA +0 -18
  50. data/NEWS +0 -10
  51. data/admin/config/reap.yaml +0 -30
  52. data/admin/depot/commandline.rb +0 -219
  53. data/admin/depot/multicommand.rb +0 -403
  54. data/admin/depot/test_multicommand.rb +0 -40
  55. data/admin/log/notes.xml +0 -28
  56. data/admin/log/stats.html +0 -25
  57. data/admin/log/syntax.log +0 -0
  58. data/admin/log/testunit.log +0 -16
  59. data/admin/pack/clio-0.0.1.gem +0 -0
  60. data/admin/share/reap/example.rb +0 -7
  61. data/admin/temps/lib/clio/about.rb.erb +0 -4
  62. data/lib/clio/command.rb +0 -296
  63. data/lib/clio/option.rb +0 -36
  64. data/lib/clio/runmode.rb +0 -126
  65. data/test/test_command.rb +0 -42
  66. data/test/test_commandline.rb +0 -83
  67. data/vendor/Console/Console.cpp +0 -1203
  68. data/vendor/Console/Console.rdoc +0 -690
  69. data/vendor/Console/Console_ANSI.rdoc +0 -302
  70. data/vendor/Console/HISTORY.txt +0 -7
  71. data/vendor/Console/INSTALL.txt +0 -18
  72. data/vendor/Console/Makefile +0 -162
  73. data/vendor/Console/README.txt +0 -26
  74. data/vendor/Console/doc/classes/Win32.html +0 -115
  75. data/vendor/Console/doc/classes/Win32/Console.html +0 -650
  76. data/vendor/Console/doc/classes/Win32/Console.src/M000001.html +0 -31
  77. data/vendor/Console/doc/classes/Win32/Console.src/M000002.html +0 -23
  78. data/vendor/Console/doc/classes/Win32/Console.src/M000003.html +0 -23
  79. data/vendor/Console/doc/classes/Win32/Console.src/M000004.html +0 -27
  80. data/vendor/Console/doc/classes/Win32/Console.src/M000005.html +0 -23
  81. data/vendor/Console/doc/classes/Win32/Console.src/M000006.html +0 -28
  82. data/vendor/Console/doc/classes/Win32/Console.src/M000007.html +0 -23
  83. data/vendor/Console/doc/classes/Win32/Console.src/M000008.html +0 -24
  84. data/vendor/Console/doc/classes/Win32/Console.src/M000009.html +0 -44
  85. data/vendor/Console/doc/classes/Win32/Console.src/M000010.html +0 -23
  86. data/vendor/Console/doc/classes/Win32/Console.src/M000011.html +0 -33
  87. data/vendor/Console/doc/classes/Win32/Console.src/M000012.html +0 -26
  88. data/vendor/Console/doc/classes/Win32/Console.src/M000013.html +0 -27
  89. data/vendor/Console/doc/classes/Win32/Console.src/M000014.html +0 -28
  90. data/vendor/Console/doc/classes/Win32/Console.src/M000015.html +0 -23
  91. data/vendor/Console/doc/classes/Win32/Console.src/M000016.html +0 -23
  92. data/vendor/Console/doc/classes/Win32/Console.src/M000017.html +0 -23
  93. data/vendor/Console/doc/classes/Win32/Console.src/M000018.html +0 -29
  94. data/vendor/Console/doc/classes/Win32/Console.src/M000019.html +0 -23
  95. data/vendor/Console/doc/classes/Win32/Console.src/M000020.html +0 -23
  96. data/vendor/Console/doc/classes/Win32/Console.src/M000021.html +0 -28
  97. data/vendor/Console/doc/classes/Win32/Console.src/M000022.html +0 -23
  98. data/vendor/Console/doc/classes/Win32/Console.src/M000023.html +0 -28
  99. data/vendor/Console/doc/classes/Win32/Console.src/M000024.html +0 -35
  100. data/vendor/Console/doc/classes/Win32/Console.src/M000025.html +0 -28
  101. data/vendor/Console/doc/classes/Win32/Console.src/M000026.html +0 -28
  102. data/vendor/Console/doc/classes/Win32/Console.src/M000027.html +0 -28
  103. data/vendor/Console/doc/classes/Win32/Console.src/M000028.html +0 -31
  104. data/vendor/Console/doc/classes/Win32/Console.src/M000029.html +0 -23
  105. data/vendor/Console/doc/classes/Win32/Console.src/M000030.html +0 -23
  106. data/vendor/Console/doc/classes/Win32/Console.src/M000031.html +0 -23
  107. data/vendor/Console/doc/classes/Win32/Console.src/M000032.html +0 -27
  108. data/vendor/Console/doc/classes/Win32/Console.src/M000033.html +0 -27
  109. data/vendor/Console/doc/classes/Win32/Console.src/M000034.html +0 -25
  110. data/vendor/Console/doc/classes/Win32/Console/ANSI.html +0 -103
  111. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.html +0 -220
  112. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000035.html +0 -32
  113. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000036.html +0 -205
  114. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000037.html +0 -40
  115. data/vendor/Console/doc/classes/Win32/Console/ANSI/IO.src/M000038.html +0 -25
  116. data/vendor/Console/doc/classes/Win32/Console/API.html +0 -758
  117. data/vendor/Console/doc/classes/Win32/Console/API.src/M000039.html +0 -27
  118. data/vendor/Console/doc/classes/Win32/Console/API.src/M000040.html +0 -27
  119. data/vendor/Console/doc/classes/Win32/Console/API.src/M000041.html +0 -27
  120. data/vendor/Console/doc/classes/Win32/Console/API.src/M000042.html +0 -32
  121. data/vendor/Console/doc/classes/Win32/Console/API.src/M000043.html +0 -32
  122. data/vendor/Console/doc/classes/Win32/Console/API.src/M000044.html +0 -28
  123. data/vendor/Console/doc/classes/Win32/Console/API.src/M000045.html +0 -26
  124. data/vendor/Console/doc/classes/Win32/Console/API.src/M000046.html +0 -26
  125. data/vendor/Console/doc/classes/Win32/Console/API.src/M000047.html +0 -27
  126. data/vendor/Console/doc/classes/Win32/Console/API.src/M000048.html +0 -30
  127. data/vendor/Console/doc/classes/Win32/Console/API.src/M000049.html +0 -29
  128. data/vendor/Console/doc/classes/Win32/Console/API.src/M000050.html +0 -27
  129. data/vendor/Console/doc/classes/Win32/Console/API.src/M000051.html +0 -28
  130. data/vendor/Console/doc/classes/Win32/Console/API.src/M000052.html +0 -30
  131. data/vendor/Console/doc/classes/Win32/Console/API.src/M000053.html +0 -27
  132. data/vendor/Console/doc/classes/Win32/Console/API.src/M000054.html +0 -29
  133. data/vendor/Console/doc/classes/Win32/Console/API.src/M000055.html +0 -29
  134. data/vendor/Console/doc/classes/Win32/Console/API.src/M000056.html +0 -28
  135. data/vendor/Console/doc/classes/Win32/Console/API.src/M000057.html +0 -27
  136. data/vendor/Console/doc/classes/Win32/Console/API.src/M000058.html +0 -47
  137. data/vendor/Console/doc/classes/Win32/Console/API.src/M000059.html +0 -32
  138. data/vendor/Console/doc/classes/Win32/Console/API.src/M000060.html +0 -47
  139. data/vendor/Console/doc/classes/Win32/Console/API.src/M000061.html +0 -34
  140. data/vendor/Console/doc/classes/Win32/Console/API.src/M000062.html +0 -32
  141. data/vendor/Console/doc/classes/Win32/Console/API.src/M000063.html +0 -32
  142. data/vendor/Console/doc/classes/Win32/Console/API.src/M000064.html +0 -35
  143. data/vendor/Console/doc/classes/Win32/Console/API.src/M000065.html +0 -26
  144. data/vendor/Console/doc/classes/Win32/Console/API.src/M000066.html +0 -27
  145. data/vendor/Console/doc/classes/Win32/Console/API.src/M000067.html +0 -29
  146. data/vendor/Console/doc/classes/Win32/Console/API.src/M000068.html +0 -27
  147. data/vendor/Console/doc/classes/Win32/Console/API.src/M000069.html +0 -27
  148. data/vendor/Console/doc/classes/Win32/Console/API.src/M000070.html +0 -28
  149. data/vendor/Console/doc/classes/Win32/Console/API.src/M000071.html +0 -27
  150. data/vendor/Console/doc/classes/Win32/Console/API.src/M000072.html +0 -26
  151. data/vendor/Console/doc/classes/Win32/Console/API.src/M000073.html +0 -27
  152. data/vendor/Console/doc/classes/Win32/Console/API.src/M000074.html +0 -31
  153. data/vendor/Console/doc/classes/Win32/Console/API.src/M000075.html +0 -27
  154. data/vendor/Console/doc/classes/Win32/Console/API.src/M000076.html +0 -32
  155. data/vendor/Console/doc/classes/Win32/Console/API.src/M000077.html +0 -27
  156. data/vendor/Console/doc/classes/Win32/Console/API.src/M000078.html +0 -32
  157. data/vendor/Console/doc/classes/Win32/Console/API.src/M000079.html +0 -32
  158. data/vendor/Console/doc/classes/Win32/Console/API.src/M000080.html +0 -32
  159. data/vendor/Console/doc/classes/Win32/Console/Constants.html +0 -360
  160. data/vendor/Console/doc/created.rid +0 -1
  161. data/vendor/Console/doc/files/Console_ANSI_rdoc.html +0 -407
  162. data/vendor/Console/doc/files/Console_cpp.html +0 -104
  163. data/vendor/Console/doc/files/Console_rdoc.html +0 -964
  164. data/vendor/Console/doc/files/lib/Win32/Console/ANSI_rb.html +0 -123
  165. data/vendor/Console/doc/files/lib/Win32/Console_rb.html +0 -297
  166. data/vendor/Console/doc/fr_class_index.html +0 -32
  167. data/vendor/Console/doc/fr_file_index.html +0 -31
  168. data/vendor/Console/doc/fr_method_index.html +0 -106
  169. data/vendor/Console/doc/index.html +0 -24
  170. data/vendor/Console/doc/rdoc-style.css +0 -172
  171. data/vendor/Console/extconf.rb +0 -18
  172. data/vendor/Console/lib/Term/ansicolor.rb +0 -76
  173. data/vendor/Console/lib/Win32/Console.rb +0 -970
  174. data/vendor/Console/lib/Win32/Console/ANSI.rb +0 -305
  175. data/vendor/Console/test/test_cursor.rb +0 -9
  176. data/vendor/Console/test/test_mouse.rb +0 -6
  177. data/vendor/Console/test/test_readinput.rb +0 -62
  178. data/vendor/Console/test/test_readoutput.rb +0 -52
  179. data/vendor/Console/test/test_sendevent.rb +0 -17
  180. data/vendor/Console/test/test_title.rb +0 -14
  181. data/vendor/Console/test/test_write.rb +0 -36
@@ -1,40 +0,0 @@
1
- require 'test/unit'
2
- require 'clio/multicommand'
3
-
4
- class TestCommand < Test::Unit::TestCase
5
-
6
- class ExampleCommand < Clio::MultiCommand
7
-
8
- def setup
9
- @check = {}
10
- end
11
-
12
- # No arguments and no options.
13
- def a
14
- @check['a'] = true
15
- end
16
-
17
- # Takes only options.
18
- def b(opts)
19
- @check['b'] = opts
20
- end
21
-
22
- # Takes multiple arguments and options. (Ruby 1.9 only)
23
- #def c(*args, opts)
24
- #end
25
-
26
- # opt 'a', :bolean, 'example option a'
27
-
28
- # Takes one argument and options.
29
- def d(args, opts)
30
- @check['d'] = [args, opts]
31
- end
32
-
33
- def e(args, opts)
34
- opts.has_only! %w{a b c}
35
- end
36
-
37
- end
38
-
39
- end
40
-
data/admin/log/notes.xml DELETED
@@ -1,28 +0,0 @@
1
- <notes>
2
- <set label="FIXME">
3
- <file src="lib/clio/progressbar.rb">
4
- <note line="134" type="FIXME">FIXME: I don&apos;t know how portable it is.</note>
5
- </file>
6
- </set>
7
- <set label="TODO">
8
- <file src="lib/clio/string.rb">
9
- <note line="76" type="TODO">TODO: No doubt the delegation will need to be made more robust.</note>
10
- </file>
11
- <file src="lib/clio/commandline.rb">
12
- <note line="30" type="TODO">TODO: Rename this method.</note>
13
- </file>
14
- <file src="lib/clio/commandable.rb">
15
- <note line="118" type="TODO">TODO: to_b if &apos;true&apos; or &apos;false&apos; ?</note>
16
- </file>
17
- <file src="lib/clio/runmode.rb">
18
- <note line="117" type="TODO">TODO: Reduce to one, two at most.</note>
19
- </file>
20
- <file src="lib/clio/consoleutils.rb">
21
- <note line="66" type="TODO">TODO: Don&apos;t know how portable #screen_width is.</note>
22
- </file>
23
- <file src="lib/clio/command.rb">
24
- <note line="79" type="TODO">TODO: Support passing a string or *args, opts in place of ARGV.</note>
25
- <note line="201" type="TODO">TODO: use clio/option</note>
26
- </file>
27
- </set>
28
- </notes>
data/admin/log/stats.html DELETED
@@ -1,25 +0,0 @@
1
- <html><head>
2
- <title>Clio Code Statistics</title>
3
- <link rel="stylesheet" type="text/css" href="log.css"/>
4
- </head><body>
5
- <div class="basic_statistics">
6
- <h1>Clio -- Basic Code Statistics</h1>
7
- <table class="counts" border="1">
8
- <tr><th colspan="9"><h2>Code Counts</h2></th></tr>
9
- <tr><th>TYPE</th><th>Total</th><th>Code</th><th>-%-</th><th>Docs</th><th>-%-</th><th>Blank</th><th>-%-</th><th>Files</th></tr>
10
- <tr><th>Source</th><td>1780</td><td>888</td><td>49%</td><td>641</td><td>36%</td><td>251</td><td>14%</td><td>10</td></tr>
11
- <tr><th>Test</th><td>125</td><td>81</td><td>4%</td><td>7</td><td>0%</td><td>37</td><td>2%</td><td>2</td></tr>
12
- <tr><th>Total</th><td>1905</td><td>969</td><td>50%</td><td>648</td><td>34%</td><td>288</td><td>15%</td><td>12</td></tr>
13
- </table>
14
- <table class="ratios" border="1">
15
- <tr><th colspan="6"><h2>Code Ratios</h2></th></tr>
16
- <tr><th>RATIO</th><th>Code</th><th>Docs</th><th>Blank</th><th>Test</th><th>Total</th></tr>
17
- <tr><th>Code</th><td> 1.0</td><td> 1.4</td><td> 3.5</td><td> 7.1</td><td> -</td></tr>
18
- <tr><th>Docs</th><td> -</td><td> 1.0</td><td> 2.6</td><td> 5.1</td><td> -</td></tr>
19
- <tr><th>Blank</th><td> -</td><td> -</td><td> 1.0</td><td> 2.0</td><td> -</td></tr>
20
- <tr><th>Test</th><td> -</td><td> -</td><td> -</td><td> 1.0</td><td> -</td></tr>
21
- <tr><th>Total</th><td> 2.0</td><td> 2.8</td><td> 7.1</td><td> 14.2</td><td> 1.0</td></tr>
22
- </table>
23
- <div class="date">Wed Sep 03 06:57:55 -0400 2008</div>
24
- </div>
25
- </body></html>
data/admin/log/syntax.log DELETED
File without changes
@@ -1,16 +0,0 @@
1
- Loaded suite [test/test_command.rb, test/test_commandline.rb]
2
- Started
3
- F...Loaded suite [test/test_command.rb, test/test_commandline.rb]
4
- Started
5
- ....Loaded suite [test/test_command.rb, test/test_commandline.rb]
6
- Started
7
- ............
8
- Finished in 0.004846 seconds.
9
-
10
- 12 tests, 13 assertions, 0 failures, 0 errors
11
- Loaded suite [test/test_command.rb, test/test_commandline.rb]
12
- Started
13
- ............
14
- Finished in 0.004963 seconds.
15
-
16
- 12 tests, 13 assertions, 0 failures, 0 errors
Binary file
@@ -1,7 +0,0 @@
1
- # This is just an example of how reap
2
- # can be extended on a per-project basis.
3
- #
4
- # There is nothing special about these scripts
5
- # they are just ruby and loaded up once the
6
- # main or reap has been loaded.
7
-
@@ -1,4 +0,0 @@
1
- module Clio
2
- VERSION = "<%= version %>"
3
- end
4
-
data/lib/clio/command.rb DELETED
@@ -1,296 +0,0 @@
1
- require 'clio/errors'
2
- require 'clio/option'
3
-
4
- module Clio
5
-
6
- # = Command
7
- #
8
- # Command is Clio's low-level command option parser solution.
9
- # Despite being low-level, it is actually quite easy to used
10
- # and integrates will with Ruby.
11
- #
12
- # The Command class does not to try overly determine your needs via a
13
- # declarative options DSL, rather it just makes it easy for you to
14
- # process options into a command class. It does this primarily by
15
- # using a simple method naming trick. Methods with names starting
16
- # with underscores (eg. _n or __name) are treated as options.
17
- #
18
- # Clio::Command encourages the command pattern (hence the name). So one
19
- # class does one thing and one thing only. This helps ensure a robust
20
- # design, albeit at the expense of churning a quick all-in-one solution.
21
- #
22
- # For a quicker solution to command line parsing have a look at
23
- # Clio::Commandable or Clio::Commandline.
24
- #
25
- # Although it is low-level it does provide a single high-level "DSL"
26
- # command for describing usage. This is purely a descriptive measure,
27
- # and has no barring on the functionality. It is provided to ease
28
- # the creation of help and command completion output.
29
- #
30
- # Simply specify:
31
- #
32
- # usage :optname, "options description", :type=>"TYPE", :default=>"DEFAULT"
33
- #
34
- # Here is an example of usage.
35
- #
36
- # MainCommand < Clio::Command
37
- #
38
- # usage :quiet, "keep it quiet?", :type=>:BOOLEAN, :default=>:FALSE
39
- # usage :file, "what file to use", :type=>:FILE, :alias => :f
40
- #
41
- # # boolean flag
42
- # def __quiet
43
- # @quiet = true
44
- # end
45
- #
46
- # # required option
47
- # def __file(fname)
48
- # @file = fname
49
- # end
50
- #
51
- # # one letter shortcut
52
- # alias _f __flag
53
- #
54
- # # run command
55
- # def call(*args)
56
- # subcommand = args.shift
57
- # case subcommand
58
- # when 'show'
59
- # puts File.read(@file)
60
- # when 'rshow'
61
- # puts File.read(@file).reverse
62
- # else
63
- # puts "Unknown subcommand"
64
- # end
65
- # end
66
- #
67
- # end
68
- #
69
- # MainCommand.run
70
- #
71
- # You can chain subcommands together via a case statement like
72
- # that given above. Eg.
73
- #
74
- # case subcommand
75
- # when 'build'
76
- # BuildCommand.run(args)
77
- # ...
78
- #
79
- # TODO: Support passing a string or *args, opts in place of ARGV.
80
- #
81
- class Command
82
-
83
- # Used to invoke this command.
84
- def run(argv=ARGV)
85
- args = self.class.parse(self, argv)
86
- call(*args)
87
- end
88
-
89
- # This is command function. Override this
90
- # to do what the command does.
91
- def call(*args)
92
- end
93
-
94
- # Override option_missing if needed.
95
- # This receives the name of the option and
96
- # the remaining arguments list. It must consume
97
- # any argument it uses from the (begining of)
98
- # the list.
99
- def option_missing(opt, *argv)
100
- raise NoOptionError, opt
101
- end
102
-
103
- class << self
104
-
105
- #
106
- def parse(obj, argv=ARGV)
107
- argv = argv.dup
108
- args, opts, i = [], {}, 0
109
- while argv.size > 0
110
- case opt = argv.shift
111
- when /=/
112
- parse_equal(obj, opt, argv)
113
- when /^--/
114
- parse_option(obj, opt, argv)
115
- when /^-/
116
- parse_flags(obj, opt, argv)
117
- else
118
- args << opt
119
- end
120
- end
121
- return args
122
- end
123
-
124
- #
125
- def parse_equal(obj, opt, argv)
126
- if md = /^[-]*(.*?)=(.*?)$/.match(opt)
127
- x, v = md[1], md[2]
128
- else
129
- raise ArgumentError, "#{x}"
130
- end
131
- if obj.respond_to?("__#{x}")
132
- obj.send("__#{x}",v)
133
- else
134
- obj.option_missing(x, v) # argv?
135
- end
136
- end
137
-
138
- #
139
- def parse_option(obj, opt, argv)
140
- x = opt[2..-1]
141
- if obj.respond_to?("__#{x}")
142
- m = obj.method("__#{x}")
143
- if m.arity >= 0
144
- a = []
145
- m.arity.times{ a << argv.shift }
146
- m.call(*a)
147
- else
148
- m.call
149
- end
150
- else
151
- obj.option_missing(x, argv)
152
- end
153
- end
154
-
155
- #
156
- def parse_flags(obj, opt, args)
157
- x = opt[1..-1]
158
- c = 0
159
- x.split(//).each do |k|
160
- if m = obj.method("_#{k}")
161
- a = []
162
- m.arity.times{ a << argv.shift }
163
- m.call(*a)
164
- else
165
- obj.option_missing(x, argv)
166
- end
167
- end
168
- end
169
-
170
- # Shortcut for
171
- #
172
- # Command.new.run()
173
- #
174
- def run(argv=ARGV)
175
- new.run(argv)
176
- end
177
-
178
- def uses
179
- @usage ||= []
180
- @usage.collect do |u|
181
- u.usage
182
- end.join(' ')
183
- end
184
-
185
- def usage(name, desc, opts)
186
- @usage ||= []
187
- @usage << Option.new(name, desc, opts)
188
- end
189
-
190
- #def help
191
- # #command_attrs.each do |k, o|
192
- # # puts "%-20s %s" % [o.usage, o.description]
193
- # #end
194
- #end
195
-
196
- end #class << self
197
-
198
- end
199
-
200
- =begin
201
- # TODO: use clio/option
202
- class UseOption
203
- attr_reader :name
204
- attr_accessor :type
205
- attr_accessor :init
206
- attr_accessor :desc
207
-
208
- alias_method :default, :init
209
- alias_method :description, :desc
210
-
211
- def initialize(name, desc, opts)
212
- @name = name
213
- @desc = desc
214
- @type = opts[:type] || 'value'
215
- @init = opts[:default] || opts[:init]
216
- end
217
- def usage
218
- "--#{name}=#{type.to_s.upcase}"
219
- end
220
- def assert_valid(value)
221
- raise "invalid" unless valid?(value)
222
- end
223
- def valid?(value)
224
- validation ? validation.call(value) : true
225
- end
226
- def validation(&block)
227
- @validation = block if block
228
- @validation
229
- end
230
- end
231
- =end
232
-
233
- end
234
-
235
-
236
- =begin :spec:
237
-
238
- require 'quarry/spec'
239
-
240
- class MyCommand < Clio::Command
241
- attr_reader :size, :quiet, :file
242
-
243
- def initialize
244
- @file = 'hey.txt' # default
245
- end
246
-
247
- use :quiet, "supress standard output", :type => :boolean
248
-
249
- def __quiet(bool=true)
250
- @quiet = bool ? true : bool
251
- end
252
-
253
- use :size, "what size will it be?", :type => :integer, :default => '0'
254
-
255
- def __size(integer)
256
- @size = integer.to_i
257
- end
258
-
259
- use :file, "where to store the stuff", :init => 'hey.txt'
260
-
261
- def __file(fname)
262
- @file = fname
263
- end
264
-
265
- def call(*args)
266
- @args = args
267
- end
268
- end
269
-
270
- Quarry.spec "Command" do
271
- before do
272
- @mc = MyCommand.new
273
- end
274
-
275
- demonstrate 'boolean option' do
276
- @mc.run(['--quiet'])
277
- @mc.quiet.assert == true
278
- end
279
-
280
- demonstrate 'integer option' do
281
- @mc.run(['--size=4'])
282
- @mc.size.assert == 4
283
- end
284
-
285
- demonstrate 'default value' do
286
- @mc.run([''])
287
- @mc.file.assert == 'hey.txt'
288
- end
289
-
290
- demonstrate 'usage output' do
291
- MyCommand.usage.assert == "--quiet=BOOLEAN --size=INTEGER --file=VALUE"
292
- end
293
- end
294
-
295
- =end
296
-
data/lib/clio/option.rb DELETED
@@ -1,36 +0,0 @@
1
- module Clio
2
-
3
- # Option class. This is used by some command
4
- # of the command line parser class to store
5
- # option information.
6
- class Option
7
- attr_reader :name
8
- attr_accessor :type
9
- attr_accessor :init
10
- attr_accessor :desc
11
-
12
- alias_method :default, :init
13
- alias_method :description, :desc
14
-
15
- def initialize(name, desc, opts)
16
- @name = name
17
- @desc = desc
18
- @type = opts[:type] || 'value'
19
- @init = opts[:default] || opts[:init]
20
- end
21
- def usage
22
- "--#{name}=#{type.to_s.upcase}"
23
- end
24
- def assert_valid(value)
25
- raise "invalid" unless valid?(value)
26
- end
27
- def valid?(value)
28
- validation ? validation.call(value) : true
29
- end
30
- def validation(&block)
31
- @validation = block if block
32
- @validation
33
- end
34
- end
35
-
36
- end