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
@@ -0,0 +1,55 @@
1
+ module Clio
2
+
3
+ module Usage #:nodoc:
4
+
5
+ # = Command Signature
6
+ #
7
+ # Used by the Usage::Parser as the end result
8
+ # of parsing a Usage::Command.
9
+ #
10
+ class Signature
11
+ def initialize(c, a, o)
12
+ @signature = [c, a, o]
13
+ @command = c
14
+ @arguments = a
15
+ @options = o
16
+ end
17
+
18
+ attr :command
19
+ attr :arguments
20
+ attr :options
21
+ attr :signature
22
+
23
+ def to_a; @signature; end
24
+
25
+ def parameters
26
+ @arguments + [@options]
27
+ end
28
+
29
+ def inspect; "#<#{self.class}:" + @signature.inspect + ">"; end
30
+
31
+ #
32
+ def method_missing(s, *a)
33
+ s = s.to_s
34
+ case s
35
+ #when /[=]$/
36
+ # n = s.chomp('=')
37
+ # usage.option(n).type(*a)
38
+ # #parser.parse
39
+ # res = parser.options[n.to_sym]
40
+ #when /[!]$/
41
+ # n = s.chomp('!')
42
+ # res = parser.parse
43
+ when /[?]$/
44
+ options[s.chomp('?').to_sym]
45
+ else
46
+ options[s.to_sym]
47
+ end
48
+ end
49
+
50
+ end#class Signature
51
+
52
+ end#module Usage
53
+
54
+ end#module Clio
55
+
data/meta/abstract ADDED
@@ -0,0 +1,3 @@
1
+ Clio makes commandline interfaces easy.
2
+ It provides both commandline parsing
3
+ as well as console output routines.
data/meta/authors ADDED
@@ -0,0 +1 @@
1
+ 7rans <transfire@gmail.com>
data/meta/created ADDED
@@ -0,0 +1 @@
1
+ Fri Aug 08 23:09:48 -0400 2008
data/meta/homepage ADDED
@@ -0,0 +1 @@
1
+ http://clio.rubyforge.org
data/meta/license ADDED
@@ -0,0 +1 @@
1
+ LGPLv3
data/meta/repository ADDED
@@ -0,0 +1 @@
1
+ git://rubyforge.org/clio.git
data/meta/summary ADDED
@@ -0,0 +1 @@
1
+ Clio makes commandline interfaces easy.
@@ -0,0 +1,56 @@
1
+ = Method Missing "Auto" Usage
2
+
3
+ Require Commandline library.
4
+
5
+ require 'clio/commandline'
6
+ $0 = 'test'
7
+
8
+ Handles a toplevel option using method_missing.
9
+
10
+ cli = Clio::Commandline.new('--verbose')
11
+ cli.verbose?
12
+ cli.to_s.assert == 'test [--verbose]'
13
+
14
+ Handles a toplevel option with aliases using method_missing.
15
+
16
+ cli = Clio::Commandline.new('--verbose')
17
+ cli.verbose?(:v)
18
+ cli.to_s.assert == 'test [-v --verbose]'
19
+
20
+ Returns a toplevel option value"
21
+
22
+ cli = Clio::Commandline.new('--verbose')
23
+ cli.verbose?(:v).assert == true
24
+
25
+ Create new commandline object.
26
+
27
+ cmd = Clio::Commandline.new('--verbose')
28
+ cmd.usage.command('foo')
29
+ cmd.parse
30
+
31
+ == Single Character Option
32
+
33
+ Create new Commandline object.
34
+
35
+ @cmd = Clio::Commandline.new('-V')
36
+
37
+ Returns a toplevel option value.
38
+
39
+ @cmd.verbose?(:V).assert == true
40
+
41
+ == Option Literal Shorthand
42
+
43
+ An option and a subcommand parsed statically.
44
+
45
+ $0 = 'test'
46
+ @cli = Clio::Commandline.new('-V foo')
47
+ @cli.usage.opt('--verbose -V')
48
+ @cli.usage.command('foo')
49
+ @cli.parse
50
+
51
+ Parses the option correctly.
52
+
53
+ @cli.options[:verbose].assert == true
54
+
55
+ QED.
56
+
@@ -0,0 +1,64 @@
1
+ = Command Definition using Bracket Notation
2
+
3
+ Require commandline library.
4
+
5
+ require 'clio/commandline'
6
+
7
+ Since this not a real command line application,
8
+ lets fake one called 'test'.
9
+
10
+ $0 = 'test'
11
+
12
+ We can use a method to define a subcommand.
13
+
14
+ cmd = Clio::Commandline.new
15
+ cmd.usage['doc']
16
+ cmd.to_s.assert == 'test doc'
17
+
18
+ We can use a question-method to define a switch.
19
+
20
+ cmd = Clio::Commandline.new
21
+ cmd.usage['doc']
22
+ cmd.usage['--verbose']
23
+ cmd.to_s.assert == 'test [--verbose] doc'
24
+
25
+ The switch method can also take option aliases.
26
+
27
+ cmd = Clio::Commandline.new
28
+ cmd.usage['--verbose -v']
29
+ cmd.to_s.assert == 'test [-v --verbose]'
30
+
31
+ The command can take argument to process as suboptions
32
+ and arguments.
33
+
34
+ cmd = Clio::Commandline.new
35
+ cmd.usage['doc']['--output=PATH']
36
+ cmd.to_s.assert == 'test doc [--output=PATH]'
37
+ cmd.usage.doc.to_s.assert == 'doc [--output=PATH]'
38
+
39
+ An option and a subcommand parsed statically.
40
+
41
+ cmd = Clio::Commandline.new
42
+ cmd.usage['--verbose -v']
43
+ cmd.usage['doc']['--output=PATH']
44
+ cmd.usage['doc']['<file>']
45
+ cmd.to_s.assert == 'test [-v --verbose] doc [--output=PATH] <file>'
46
+
47
+ We can define help for these commands and options using
48
+ a seaprate help! call.
49
+
50
+ cmd = Clio::Commandline.new
51
+ cmd.usage['doc']['--output=PATH']
52
+ cmd.usage['--verbose -v']
53
+
54
+ #cmd.usage['doc'] = 'generate documentation'
55
+ #cmd.usage['--verbose -v'] = 'verbose mode'
56
+
57
+ cmd.usage.help!(
58
+ 'doc', 'generate documentation',
59
+ '--verbose', 'verbose mode'
60
+ )
61
+
62
+ cmd.usage.options[0].name.assert == 'verbose'
63
+
64
+ QED.
@@ -0,0 +1,38 @@
1
+ = Commandline Tab Completion
2
+
3
+ Load commandline library.
4
+
5
+ require 'clio/commandline'
6
+
7
+ Create a new command line object.
8
+
9
+ $0 = 'c0'
10
+ @cli = Clio::Commandline.new
11
+
12
+ Specify usage for comamndline.
13
+
14
+ @cli.usage.option('o0')
15
+ @cli.usage.command('c1').opt('--o1=TYPE -o')
16
+ @cli.usage.command('c1 c2').option('o2')
17
+ @cli.usage.command('c1 c2').argument('a')
18
+ @cli.usage.command('c1 c2').argument('b')
19
+ @cli.usage.command('c1 c2').argument('c')
20
+
21
+ First lets make sure it parses okay.
22
+
23
+ @cli.parse('--o0 c1 --o1 atype c2 --o2 a b c')
24
+
25
+ Now let try some tab completion. First a command.
26
+
27
+ #@cli.parse('c1 -')
28
+ @cli.completion('c1').assert == ['-o --o1=TYPE', 'c2']
29
+
30
+ Now an option.
31
+
32
+ @cli.completion('c1 --o1').assert == ["TYPE"]
33
+
34
+ QED.
35
+
36
+
37
+
38
+
@@ -0,0 +1,44 @@
1
+ = Commandline Definition using Core Notation
2
+
3
+ Require commandline library.
4
+
5
+ require 'clio/commandline'
6
+
7
+ Fake that we running an executable called 'test'.
8
+
9
+ $0 = 'test'
10
+
11
+ Create a new commandline object.
12
+
13
+ @cmd = Clio::Commandline.new
14
+
15
+ We can define a subcommand using #command on #usage.
16
+
17
+ @cmd.usage.command('foo')
18
+ @cmd.to_s.assert == 'test foo'
19
+
20
+ We can define a toplevel switch using #switch.
21
+
22
+ @cmd.usage.switch('verbose')
23
+ @cmd.to_s.assert == 'test [--verbose] foo'
24
+
25
+ Switches can have aliases.
26
+
27
+ @cmd.usage.switch(:verbose, :v)
28
+ @cmd.to_s.assert == 'test [-v --verbose] foo'
29
+
30
+ There can be mulitple subcommands.
31
+
32
+ @cmd.usage.command('foo bar')
33
+ @cmd.to_s.assert == 'test [-v --verbose] foo bar'
34
+
35
+ Let's bring it all together in one example.
36
+
37
+ cmd = Clio::Commandline.new
38
+ cmd.usage.switch(:verbose, :v)
39
+ cmd.usage.switch(:force, :f)
40
+ cmd.usage.command('foo')
41
+ cmd.usage.command('bar')
42
+ cmd.to_s.assert == 'test [-v --verbose] [-f --force] [foo | bar]'
43
+
44
+ QED.
@@ -0,0 +1,60 @@
1
+ = Command Definition using Method Notation
2
+
3
+ Require commandline library.
4
+
5
+ require 'clio/commandline'
6
+
7
+ Since this not a real command line application,
8
+ lets fake one called 'test'.
9
+
10
+ $0 = 'test'
11
+
12
+ We can use a method to define a subcommand.
13
+
14
+ cmd = Clio::Commandline.new
15
+ cmd.usage.doc
16
+ cmd.to_s.assert == 'test doc'
17
+
18
+ We can use a question-method to define a switch.
19
+
20
+ cmd = Clio::Commandline.new
21
+ cmd.usage.doc
22
+ cmd.usage.verbose?
23
+ cmd.to_s.assert == 'test [--verbose] doc'
24
+
25
+ The switch method can also take option aliases.
26
+
27
+ cmd = Clio::Commandline.new
28
+ cmd.usage.verbose?(:v)
29
+ cmd.to_s.assert == 'test [-v --verbose]'
30
+
31
+ The command can take argument to process as suboptions
32
+ and arguments.
33
+
34
+ cmd = Clio::Commandline.new
35
+ cmd.usage.doc('--output=PATH')
36
+ cmd.to_s.assert == 'test doc [--output=PATH]'
37
+ cmd.usage.doc.to_s.assert == 'doc [--output=PATH]'
38
+
39
+ An option and a subcommand parsed statically.
40
+
41
+ cmd = Clio::Commandline.new
42
+ cmd.usage.doc('--output=PATH')
43
+ cmd.usage.verbose?(:v)
44
+ cmd.to_s.assert == 'test [-v --verbose] doc [--output=PATH]'
45
+
46
+ We can define help for these commands and options using
47
+ a seaprate help! call.
48
+
49
+ cmd = Clio::Commandline.new
50
+ cmd.usage.doc('--output=PATH')
51
+ cmd.usage.verbose?(:v)
52
+
53
+ cmd.usage.help!(
54
+ 'doc', 'generate documentation',
55
+ '--verbose', 'verbose mode'
56
+ )
57
+
58
+ cmd.usage.options[0].name.assert == 'verbose'
59
+
60
+ QED.
@@ -0,0 +1,72 @@
1
+ = Command Parsing
2
+
3
+ Require command library.
4
+
5
+ require 'clio/commandline'
6
+
7
+ A single toplevel option.
8
+
9
+ cmd = Clio::Commandline.new
10
+ cmd.usage.option('force')
11
+ cmd.parse('--force')
12
+ cmd.options.assert == {:force=>true}
13
+
14
+ A single toplevel option with an alias.
15
+
16
+ cmd = Clio::Commandline.new
17
+ cmd.usage.option('force', 'f')
18
+ cmd.parse('-f')
19
+ cmd.options.assert == {:force=>true}
20
+
21
+ A subcommand.
22
+
23
+ cmd = Clio::Commandline.new
24
+ cmd.usage.command('foo')
25
+ cmd.parse('foo')
26
+ cmd.command.assert == 'foo'
27
+ cmd.commands.assert == ['foo']
28
+
29
+ A subcommand with an option.
30
+
31
+ cmd = Clio::Commandline.new
32
+ cmd.usage.command('foo')
33
+ cmd.usage.command('foo').option('verbose')
34
+ cmd.parse('foo --verbose')
35
+
36
+ cmd.command.assert == 'foo'
37
+ cmd.commands.assert == ['foo']
38
+ cmd.options.assert == {:verbose=>true}
39
+
40
+ cmd[0].options.assert == {}
41
+ cmd[1].options.assert == {:verbose=>true}
42
+
43
+ Multiple subcommands.
44
+
45
+ cmd = Clio::Commandline.new
46
+ cmd.usage.command('foo').command('bar').option('verbose')
47
+ cmd.parse('foo bar --verbose')
48
+
49
+ cmd.command.assert == 'foo bar'
50
+ cmd.commands.assert == ['foo','bar']
51
+ cmd.options == {:verbose=>true}
52
+
53
+ cmd[0].options.assert == {}
54
+ cmd[1].options.assert == {}
55
+ cmd[2].options.assert == {:verbose=>true}
56
+
57
+ Multiple subcommands.
58
+
59
+ cmd = Clio::Commandline.new
60
+ cmd.usage.command('foo').option('verbose')
61
+ cmd.usage.command('foo bar')
62
+ cmd.parse('foo bar --verbose')
63
+
64
+ cmd.command.assert == 'foo bar'
65
+ cmd.commands.assert == ['foo','bar']
66
+ cmd.options == {:verbose=>true}
67
+
68
+ cmd[0].options.assert == {}
69
+ cmd[1].options.assert == {}
70
+ cmd[2].options.assert == {:verbose=>true}
71
+
72
+ QED.
@@ -0,0 +1,81 @@
1
+ = Commandline Parses Correctly
2
+
3
+ Load commandline library.
4
+
5
+ require 'clio/commandline'
6
+
7
+ Create a new command line object.
8
+
9
+ $0 = 'c0'
10
+ @cli = Clio::Commandline.new('--o0 c1 --o1 c2 --o2 a b c')
11
+
12
+ Specify usage for comamndline.
13
+
14
+ @cli.usage.option('o0')
15
+ @cli.usage.command('c1').option('o1')
16
+ @cli.usage.command('c1 c2').option('o2')
17
+ @cli.usage.command('c1 c2').argument('a')
18
+ @cli.usage.command('c1 c2').argument('b')
19
+ @cli.usage.command('c1 c2').argument('c')
20
+
21
+ #@cli.usage.option('o0')
22
+ #@cliusage.argument('a0')
23
+ #@cli.usage.command('c1').option('o1')
24
+ #@cli.usage.command('c1').argument('a1')
25
+ #@cli.usage.command('c1').command('c2').option('o2')
26
+ #@cli.usage.command('c1').command('c2').argument('a2')
27
+
28
+ Usage string is correct.
29
+
30
+ @cli.to_s.assert == 'c0 [--o0] c1 [--o1] c2 [--o2] <a> <b> <c>'
31
+
32
+ Parses without error.
33
+
34
+ @cli.parse
35
+
36
+ Full signature is correct.
37
+
38
+ @cli.to_a.assert == [
39
+ ["c0", [], {:o0=>true}],
40
+ ["c1", [], {:o1=>true}],
41
+ ["c2", ["a", "b", "c"], {:o2=>true}]
42
+ ]
43
+
44
+ Options provides all options merged together.
45
+
46
+ @cli.options.assert == {:o0=>true,:o1=>true,:o2=>true}
47
+
48
+ Switches method is an alias for options.
49
+
50
+ @cli.switches.assert == {:o0=>true,:o1=>true,:o2=>true}
51
+
52
+ Arguments provides all concated together.
53
+
54
+ @cli.arguments.assert == ["a", "b", "c"]
55
+
56
+ Parameters method provides arguments and options.
57
+
58
+ @cli.parameters.assert == ["a", "b", "c", {:o0=>true,:o1=>true,:o2=>true}]
59
+
60
+ Zeroth signature is correct.
61
+
62
+ @cli[0].command.assert == 'c0'
63
+ @cli[0].options.assert == {:o0=>true}
64
+ @cli[0].arguments.assert == []
65
+ @cli[0].parameters.assert == [{:o0=>true}]
66
+ @cli[0].signature.assert == ["c0", [], {:o0=>true}]
67
+ @cli[0].to_a.assert == ["c0", [], {:o0=>true}]
68
+
69
+ First signature is correct.
70
+
71
+ @cli[1].to_a.assert == ["c1", [], {:o1=>true}]
72
+
73
+ Second signature is correct.
74
+
75
+ @cli[2].to_a.assert == ["c2", ["a", "b", "c"], {:o2=>true}]
76
+
77
+ There are no more signatures after the second.
78
+
79
+ @cli[3].assert == nil
80
+
81
+ QED.