ivanvc-choice 0.1.3.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/CHANGELOG +22 -0
- data/LICENSE +18 -0
- data/README +447 -0
- data/examples/ftpd.rb +87 -0
- data/examples/gamble.rb +42 -0
- data/lib/choice.rb +166 -0
- data/lib/choice/lazyhash.rb +67 -0
- data/lib/choice/option.rb +90 -0
- data/lib/choice/parser.rb +233 -0
- data/lib/choice/version.rb +9 -0
- data/lib/choice/writer.rb +187 -0
- data/test/test_choice.rb +234 -0
- data/test/test_lazyhash.rb +76 -0
- data/test/test_option.rb +145 -0
- data/test/test_parser.rb +388 -0
- data/test/test_writer.rb +103 -0
- metadata +69 -0
data/test/test_writer.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
$:.unshift "../lib:lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'choice'
|
4
|
+
|
5
|
+
class TestWriter < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Choice.reset!
|
9
|
+
end
|
10
|
+
|
11
|
+
HELP_OUT = ''
|
12
|
+
def test_help
|
13
|
+
song = Choice::Option.new do
|
14
|
+
short '-s'
|
15
|
+
long '--song=SONG'
|
16
|
+
cast String
|
17
|
+
desc 'Your favorite GNR song.'
|
18
|
+
desc '(Default: MyMichelle)'
|
19
|
+
default 'MyMichelle'
|
20
|
+
end
|
21
|
+
dude = Choice::Option.new do
|
22
|
+
short '-d'
|
23
|
+
long '--dude=DUDE'
|
24
|
+
cast String
|
25
|
+
desc 'Your favorite GNR dude.'
|
26
|
+
desc '(Default: Slash)'
|
27
|
+
default 'Slash'
|
28
|
+
end
|
29
|
+
|
30
|
+
options = [[:song, song], [:dude, dude]]
|
31
|
+
args = { :banner => "Welcome to the jungle",
|
32
|
+
:header => [""],
|
33
|
+
:options => options,
|
34
|
+
:footer => ["", "Wake up."] }
|
35
|
+
|
36
|
+
help_string = <<-HELP
|
37
|
+
Welcome to the jungle
|
38
|
+
|
39
|
+
-s, --song=SONG Your favorite GNR song.
|
40
|
+
(Default: MyMichelle)
|
41
|
+
-d, --dude=DUDE Your favorite GNR dude.
|
42
|
+
(Default: Slash)
|
43
|
+
|
44
|
+
Wake up.
|
45
|
+
HELP
|
46
|
+
|
47
|
+
Choice::Writer.help(args, HELP_OUT, true)
|
48
|
+
|
49
|
+
assert_equal help_string, HELP_OUT
|
50
|
+
end
|
51
|
+
|
52
|
+
BANNER_OUT = ''
|
53
|
+
def test_banner
|
54
|
+
media = Choice::Option.new do
|
55
|
+
short '-m'
|
56
|
+
long '--media=MEDIA'
|
57
|
+
end
|
58
|
+
rom = Choice::Option.new do
|
59
|
+
short '-r'
|
60
|
+
long '--rom=ROM'
|
61
|
+
end
|
62
|
+
|
63
|
+
options = [[:media, media], [:rom, rom]]
|
64
|
+
args = { :header => [""],
|
65
|
+
:options => options }
|
66
|
+
|
67
|
+
help_string = <<-HELP
|
68
|
+
Usage: #{program} [-mr]
|
69
|
+
|
70
|
+
-m, --media=MEDIA
|
71
|
+
-r, --rom=ROM
|
72
|
+
HELP
|
73
|
+
|
74
|
+
Choice::Writer.help(args, BANNER_OUT, true)
|
75
|
+
|
76
|
+
assert_equal help_string, BANNER_OUT
|
77
|
+
end
|
78
|
+
|
79
|
+
SPILLOVER_OUT = ''
|
80
|
+
def test_desc_spillover
|
81
|
+
toolong = Choice::Option.new do
|
82
|
+
long '--thisisgonnabewaytoolongiswear=STRING'
|
83
|
+
desc 'Way too long, boy wonder.'
|
84
|
+
end
|
85
|
+
|
86
|
+
options = [[:toolong, toolong]]
|
87
|
+
|
88
|
+
help_string = <<-HELP
|
89
|
+
Usage: #{program}
|
90
|
+
--thisisgonnabewaytoolongiswear=STRING
|
91
|
+
Way too long, boy wonder.
|
92
|
+
HELP
|
93
|
+
|
94
|
+
|
95
|
+
Choice::Writer.help({:options => options}, SPILLOVER_OUT, true)
|
96
|
+
|
97
|
+
assert_equal help_string, SPILLOVER_OUT
|
98
|
+
end
|
99
|
+
|
100
|
+
def program
|
101
|
+
if (/(\/|\\)/ =~ $0) then File.basename($0) else $0 end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ivanvc-choice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Wanstrath
|
8
|
+
autorequire: choice
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-27 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Choice is a simple little gem for easily defining and parsing command line options with a friendly DSL.
|
17
|
+
email: chris@ozmm.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- CHANGELOG
|
27
|
+
- LICENSE
|
28
|
+
- lib/choice/lazyhash.rb
|
29
|
+
- lib/choice/option.rb
|
30
|
+
- lib/choice/parser.rb
|
31
|
+
- lib/choice/version.rb
|
32
|
+
- lib/choice/writer.rb
|
33
|
+
- lib/choice.rb
|
34
|
+
- test/test_choice.rb
|
35
|
+
- test/test_lazyhash.rb
|
36
|
+
- test/test_option.rb
|
37
|
+
- test/test_parser.rb
|
38
|
+
- test/test_writer.rb
|
39
|
+
- examples/ftpd.rb
|
40
|
+
- examples/gamble.rb
|
41
|
+
has_rdoc: false
|
42
|
+
homepage: http://choice.rubyforge.org/
|
43
|
+
licenses:
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: Choice is a command line option parser.
|
68
|
+
test_files: []
|
69
|
+
|