choosy 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -0
- data/LICENSE +2 -0
- data/README.markdown +102 -54
- data/Rakefile +27 -5
- data/TODO.md +5 -0
- data/examples/bar.rb +9 -7
- data/examples/foo.rb +9 -7
- data/examples/superfoo.rb +48 -36
- data/lib/VERSION.yml +6 -0
- data/lib/choosy/argument.rb +5 -0
- data/lib/choosy/base_command.rb +11 -10
- data/lib/choosy/command.rb +17 -1
- data/lib/choosy/converter.rb +5 -1
- data/lib/choosy/dsl/argument_builder.rb +33 -21
- data/lib/choosy/dsl/base_builder.rb +26 -0
- data/lib/choosy/dsl/base_command_builder.rb +23 -30
- data/lib/choosy/dsl/command_builder.rb +8 -12
- data/lib/choosy/dsl/option_builder.rb +14 -45
- data/lib/choosy/dsl/super_command_builder.rb +17 -20
- data/lib/choosy/errors.rb +1 -0
- data/lib/choosy/option.rb +19 -0
- data/lib/choosy/printing/base_printer.rb +231 -0
- data/lib/choosy/printing/color.rb +8 -5
- data/lib/choosy/printing/erb_printer.rb +1 -1
- data/lib/choosy/printing/help_printer.rb +49 -163
- data/lib/choosy/printing/manpage.rb +235 -0
- data/lib/choosy/printing/manpage_printer.rb +95 -0
- data/lib/choosy/printing/terminal.rb +39 -8
- data/lib/choosy/printing.rb +1 -0
- data/lib/choosy/super_command.rb +13 -4
- data/lib/choosy/super_parser.rb +5 -1
- data/lib/choosy/verifier.rb +8 -0
- data/lib/choosy/version.rb +64 -5
- data/spec/choosy/argument_spec.rb +28 -0
- data/spec/choosy/base_command_spec.rb +7 -3
- data/spec/choosy/command_spec.rb +2 -2
- data/spec/choosy/converter_spec.rb +3 -2
- data/spec/choosy/dsl/argument_builder_spec.rb +19 -8
- data/spec/choosy/dsl/base_builder_spec.rb +43 -0
- data/spec/choosy/dsl/base_command_builder_spec.rb +7 -9
- data/spec/choosy/dsl/commmand_builder_spec.rb +9 -1
- data/spec/choosy/dsl/option_builder_spec.rb +1 -65
- data/spec/choosy/dsl/super_command_builder_spec.rb +19 -8
- data/spec/choosy/option_spec.rb +68 -0
- data/spec/choosy/printing/base_printer_spec.rb +155 -0
- data/spec/choosy/printing/color_spec.rb +4 -0
- data/spec/choosy/printing/help_printer_spec.rb +15 -109
- data/spec/choosy/printing/manpage_printer_spec.rb +95 -0
- data/spec/choosy/printing/manpage_spec.rb +206 -0
- data/spec/choosy/super_command_spec.rb +7 -0
- data/spec/choosy/super_parser_spec.rb +9 -0
- data/spec/choosy/verifier_spec.rb +31 -1
- data/spec/choosy/version.yml +5 -0
- data/spec/choosy/version_spec.rb +87 -0
- data/spec/integration/command-C_spec.rb +23 -0
- data/spec/integration/supercommand-C_spec.rb +45 -0
- metadata +81 -78
- data/lib/VERSION +0 -1
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'choosy/errors'
|
2
|
+
|
3
|
+
module Choosy::Printing
|
4
|
+
class ManpageFormatter
|
5
|
+
def bold(line=nil)
|
6
|
+
if line.nil?
|
7
|
+
'\\fB'
|
8
|
+
else
|
9
|
+
"\\fB#{line}\\fP"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def italics(line=nil)
|
14
|
+
if line.nil?
|
15
|
+
'\\fI'
|
16
|
+
else
|
17
|
+
"\\fI#{line}\\fP"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def roman(line=nil)
|
22
|
+
if line.nil?
|
23
|
+
'\\fR'
|
24
|
+
else
|
25
|
+
"\\fR#{line}\\fP"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset
|
30
|
+
'\\fP'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Manpage
|
35
|
+
attr_accessor :name, :section, :date, :version, :manual
|
36
|
+
attr_reader :format, :buffer
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
@buffer = []
|
40
|
+
@section = 1
|
41
|
+
@format = ManpageFormatter.new
|
42
|
+
@version = nil
|
43
|
+
@date = nil
|
44
|
+
@manual = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def frame_outline
|
48
|
+
frame = ".TH"
|
49
|
+
quote(frame, @name)
|
50
|
+
quote(frame, @section)
|
51
|
+
quote(frame, @date)
|
52
|
+
quote(frame, @version)
|
53
|
+
quote(frame, @manual)
|
54
|
+
frame
|
55
|
+
end
|
56
|
+
|
57
|
+
def section_heading(line)
|
58
|
+
prefixed('.SH', heading(line))
|
59
|
+
end
|
60
|
+
|
61
|
+
def subsection_heading(line)
|
62
|
+
prefixed('.SS', heading(line))
|
63
|
+
end
|
64
|
+
|
65
|
+
def paragraph(line=nil)
|
66
|
+
line = if line.nil?
|
67
|
+
'.P'
|
68
|
+
else
|
69
|
+
".P\n" << line
|
70
|
+
end
|
71
|
+
append(line)
|
72
|
+
end
|
73
|
+
|
74
|
+
def indented_paragraph(item, line)
|
75
|
+
prefixed('.IP', escape(item), escape(line))
|
76
|
+
end
|
77
|
+
|
78
|
+
def hanging_paragraph(line)
|
79
|
+
append(".HP\n" << escape(line))
|
80
|
+
end
|
81
|
+
|
82
|
+
def indented_region
|
83
|
+
append('.RE')
|
84
|
+
end
|
85
|
+
|
86
|
+
def text(line)
|
87
|
+
return if line.nil?
|
88
|
+
append(escape(line))
|
89
|
+
end
|
90
|
+
|
91
|
+
def raw(line)
|
92
|
+
return if line.nil?
|
93
|
+
append(line)
|
94
|
+
end
|
95
|
+
|
96
|
+
def bold(line, type=nil)
|
97
|
+
line = escape(line)
|
98
|
+
case type
|
99
|
+
when nil
|
100
|
+
prefixed('.B', line)
|
101
|
+
when :italics
|
102
|
+
prefixed('.BI', line)
|
103
|
+
when :roman
|
104
|
+
prefixed('.BR', line)
|
105
|
+
else
|
106
|
+
raise Choosy::ConfigurationError.new("Undefined manpage bold type: #{type}")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def italics(line, type=nil)
|
111
|
+
line = escape(line)
|
112
|
+
case type
|
113
|
+
when nil
|
114
|
+
prefixed('.I', line)
|
115
|
+
when :bold
|
116
|
+
prefixed('.IB', line)
|
117
|
+
when :roman
|
118
|
+
prefixed('.IR', line)
|
119
|
+
else
|
120
|
+
raise Choosy::ConfigurationError.new("Undefined manpage italics type: #{type}")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def roman(line, type)
|
125
|
+
line = escape(line)
|
126
|
+
case type
|
127
|
+
when :italics
|
128
|
+
prefixed('.RI', line)
|
129
|
+
when :bold
|
130
|
+
prefixed('.RB', line)
|
131
|
+
else
|
132
|
+
raise Choosy::ConfigurationError.new("Undefined manpage for roman type: #{type}")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def small(line, type=nil)
|
137
|
+
line = escape(line)
|
138
|
+
case type
|
139
|
+
when nil
|
140
|
+
prefixed('.SM', line)
|
141
|
+
when :bold
|
142
|
+
prefixed('.SB', line)
|
143
|
+
else
|
144
|
+
raise Choosy::ConfigurationError.new("Undefined manpage for small type: #{type}")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def comment(line)
|
149
|
+
append('./" ' << line)
|
150
|
+
end
|
151
|
+
|
152
|
+
def line_break
|
153
|
+
append('.br')
|
154
|
+
end
|
155
|
+
|
156
|
+
def nofill(&block)
|
157
|
+
if block_given?
|
158
|
+
append('.nf')
|
159
|
+
yield self
|
160
|
+
append('.fi')
|
161
|
+
else
|
162
|
+
append('.nf')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def fill
|
167
|
+
append('.fi')
|
168
|
+
end
|
169
|
+
|
170
|
+
def term_paragraph(term, para, width=5)
|
171
|
+
append(".TP " << width.to_s << NEWLINE << escape(term) << NEWLINE << escape(para))
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_s(io=nil)
|
175
|
+
io ||= ""
|
176
|
+
io << frame_outline << NEWLINE
|
177
|
+
io << PREFACE
|
178
|
+
@buffer.each do |line|
|
179
|
+
io << line
|
180
|
+
io << NEWLINE
|
181
|
+
end
|
182
|
+
io
|
183
|
+
end
|
184
|
+
|
185
|
+
private
|
186
|
+
# Taken from the Debian best practices
|
187
|
+
PREFACE =<<EOF
|
188
|
+
.ie \\n(.g .ds Aq \\(aq
|
189
|
+
.el .ds Aq '
|
190
|
+
.\\" disable hyphenation
|
191
|
+
.nh
|
192
|
+
.\\" disable justification (adjust text to left margin only)
|
193
|
+
.ad l
|
194
|
+
EOF
|
195
|
+
SQUOTE = ' "'
|
196
|
+
EQUOTE = '"'
|
197
|
+
NEWLINE = "\n"
|
198
|
+
|
199
|
+
def quote(base, val)
|
200
|
+
if val
|
201
|
+
base << SQUOTE << val.to_s << EQUOTE
|
202
|
+
else
|
203
|
+
base << SQUOTE << ' ' << EQUOTE
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def prefixed(tag, quot, line=nil)
|
208
|
+
puts tag if quot.nil?
|
209
|
+
tag << SQUOTE << quot << EQUOTE
|
210
|
+
if line.nil?
|
211
|
+
append(tag)
|
212
|
+
else
|
213
|
+
append(tag << NEWLINE << line)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def append(line)
|
218
|
+
@buffer << line
|
219
|
+
line
|
220
|
+
end
|
221
|
+
|
222
|
+
def escape(line)
|
223
|
+
nline = line.gsub(/-/, "\\-")
|
224
|
+
nline.gsub!(/(\.+)/, '&\1')
|
225
|
+
nline
|
226
|
+
end
|
227
|
+
|
228
|
+
def heading(line)
|
229
|
+
nline = escape(line)
|
230
|
+
nline.upcase!
|
231
|
+
nline.gsub!(/:$/, '')
|
232
|
+
nline
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'choosy/errors'
|
2
|
+
require 'choosy/option'
|
3
|
+
require 'choosy/dsl/option_builder'
|
4
|
+
require 'choosy/printing/base_printer'
|
5
|
+
require 'choosy/printing/manpage'
|
6
|
+
|
7
|
+
module Choosy::Printing
|
8
|
+
class ManpagePrinter < BasePrinter
|
9
|
+
attr_reader :manpage, :name, :synopsis
|
10
|
+
|
11
|
+
def initialize(options={})
|
12
|
+
super(options)
|
13
|
+
|
14
|
+
@name = options[:name] || "NAME"
|
15
|
+
@synopsis = options[:synopsis] || 'SYNOPSIS'
|
16
|
+
|
17
|
+
@manpage = Manpage.new
|
18
|
+
@manpage.section = options[:section] || 1
|
19
|
+
@manpage.date = options[:date]
|
20
|
+
@manpage.manual = options[:manual]
|
21
|
+
@manpage.version = options[:version]
|
22
|
+
end
|
23
|
+
|
24
|
+
def print!(command)
|
25
|
+
if pager?
|
26
|
+
fix_termcap
|
27
|
+
page format!(command), 'groff -Tutf8 -mandoc'
|
28
|
+
else
|
29
|
+
# Fall back to a help printer if there is no pager
|
30
|
+
help = HelpPrinter.new(formatting_options)
|
31
|
+
help.print!(command)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def format_prologue(command)
|
36
|
+
@manpage.name = command_name(command)
|
37
|
+
version_option = command.option_builders[Choosy::DSL::OptionBuilder::VERSION]
|
38
|
+
if version_option && @manpage.version.nil?
|
39
|
+
begin
|
40
|
+
version_option.entity.validation_step.call(nil, nil)
|
41
|
+
rescue Choosy::VersionCalled => e
|
42
|
+
@manpage.version = e.message
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
format_name(command)
|
47
|
+
format_synopsis(command)
|
48
|
+
end
|
49
|
+
|
50
|
+
def format_name(command)
|
51
|
+
if command.summary
|
52
|
+
@manpage.section_heading(@name)
|
53
|
+
@manpage.text("#{command.name} - #{command.summary}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def format_synopsis(command)
|
58
|
+
@manpage.section_heading(@synopsis)
|
59
|
+
@manpage.nofill do |man|
|
60
|
+
usage_wrapped(command, '', columns).each do |line|
|
61
|
+
man.text line
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def format_option(option, formatted_option, indent)
|
67
|
+
@manpage.term_paragraph(formatted_option, option.description, indent.length)
|
68
|
+
end
|
69
|
+
|
70
|
+
def format_command(command, formatted_command, indent)
|
71
|
+
@manpage.term_paragraph(formatted_command, command.summary || "", indent.length)
|
72
|
+
end
|
73
|
+
|
74
|
+
def format_element(item)
|
75
|
+
if item.header?
|
76
|
+
@manpage.section_heading(item.value)
|
77
|
+
else
|
78
|
+
@manpage.paragraph(item.value)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def format_epilogue(command)
|
83
|
+
@manpage.to_s
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
def option_begin
|
88
|
+
@manpage.format.italics
|
89
|
+
end
|
90
|
+
|
91
|
+
def option_end
|
92
|
+
@manpage.format.reset
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -6,26 +6,57 @@ module Choosy::Printing
|
|
6
6
|
DEFAULT_LINE_COUNT = 25
|
7
7
|
DEFAULT_COLUMN_COUNT = 80
|
8
8
|
|
9
|
+
attr_writer :lines, :columns
|
10
|
+
|
9
11
|
def lines
|
10
12
|
@lines ||= find_terminal_size('LINES', 'lines', 0) || DEFAULT_LINE_COUNT
|
11
13
|
end
|
12
14
|
|
13
|
-
def lines=(value)
|
14
|
-
@lines = value
|
15
|
-
end
|
16
|
-
|
17
15
|
def columns
|
18
16
|
@columns ||= find_terminal_size('COLUMNS', 'cols', 1) || DEFAULT_COLUMN_COUNT
|
19
17
|
end
|
20
18
|
|
21
|
-
def columns=(value)
|
22
|
-
@columns = value
|
23
|
-
end
|
24
|
-
|
25
19
|
def color
|
26
20
|
@color ||= Color.new
|
27
21
|
end
|
28
22
|
|
23
|
+
def pager?
|
24
|
+
!pager.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def pager
|
28
|
+
@pager ||= ENV['PAGER'] || ENV['MANPAGER']
|
29
|
+
return @pager if @pager
|
30
|
+
|
31
|
+
@pager = if command_exists?('less')
|
32
|
+
'less -R'
|
33
|
+
elsif command_exists?('more')
|
34
|
+
'more'
|
35
|
+
else
|
36
|
+
''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def page(contents, pipe_command=nil)
|
41
|
+
if pager?
|
42
|
+
if pipe_command
|
43
|
+
pipe(contents, "#{pipe_command} | #{pager}")
|
44
|
+
else
|
45
|
+
pipe(contents, pager)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
pipe(contents, pipe_command)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def pipe(contents, command)
|
53
|
+
puts contents if command.nil?
|
54
|
+
|
55
|
+
IO.popen(command, 'w') do |f|
|
56
|
+
f.puts contents
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
29
60
|
# directly from hirb
|
30
61
|
def command_exists?(command)
|
31
62
|
ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exists? File.join(d, command) }
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/lib/choosy/super_command.rb
CHANGED
@@ -6,14 +6,14 @@ require 'choosy/dsl/super_command_builder'
|
|
6
6
|
|
7
7
|
module Choosy
|
8
8
|
class SuperCommand < BaseCommand
|
9
|
-
attr_accessor :metaname
|
9
|
+
attr_accessor :metaname, :default_command
|
10
10
|
|
11
11
|
def command_builders
|
12
12
|
@command_builders ||= {}
|
13
13
|
end
|
14
14
|
|
15
15
|
def commands
|
16
|
-
@command_builders.values.map {|b| b.
|
16
|
+
@command_builders.values.map {|b| b.entity }
|
17
17
|
end
|
18
18
|
|
19
19
|
def parsimonious=(value)
|
@@ -44,6 +44,15 @@ module Choosy
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def has_default?
|
48
|
+
!@default_command.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
def finalize!
|
52
|
+
super
|
53
|
+
@metaname ||= 'COMMAND'
|
54
|
+
end
|
55
|
+
|
47
56
|
protected
|
48
57
|
def create_builder
|
49
58
|
Choosy::DSL::SuperCommandBuilder.new(self)
|
@@ -58,11 +67,11 @@ module Choosy
|
|
58
67
|
command_name = hc.message
|
59
68
|
|
60
69
|
if command_name == Choosy::DSL::SuperCommandBuilder::SUPER
|
61
|
-
|
70
|
+
printer.print!(self)
|
62
71
|
else
|
63
72
|
builder = command_builders[command_name]
|
64
73
|
if builder
|
65
|
-
|
74
|
+
printer.print!(builder.entity)
|
66
75
|
else
|
67
76
|
$stdout << "#{@name}: #{format_help(command_name)}\n"
|
68
77
|
exit 1
|
data/lib/choosy/super_parser.rb
CHANGED
@@ -52,6 +52,8 @@ module Choosy
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def parse_globals(args)
|
55
|
+
count = args.count
|
56
|
+
|
55
57
|
result = SuperParseResult.new(@super_command)
|
56
58
|
parser = Parser.new(@super_command, true, @terminals)
|
57
59
|
parser.parse!(args, result)
|
@@ -61,6 +63,8 @@ module Choosy
|
|
61
63
|
if result.unparsed.length == 0
|
62
64
|
if @super_command.command_builders[Choosy::DSL::SuperCommandBuilder::HELP]
|
63
65
|
raise Choosy::HelpCalled.new(Choosy::DSL::SuperCommandBuilder::SUPER)
|
66
|
+
elsif count == 0 && @super_command.has_default?
|
67
|
+
result.unparsed << @super_command.default_command.to_s
|
64
68
|
else
|
65
69
|
raise Choosy::SuperParseError.new("requires a command")
|
66
70
|
end
|
@@ -80,7 +84,7 @@ module Choosy
|
|
80
84
|
end
|
81
85
|
end
|
82
86
|
|
83
|
-
command = command_builder.
|
87
|
+
command = command_builder.entity
|
84
88
|
parser = Parser.new(command, false, terminals)
|
85
89
|
command_result = Choosy::ParseResult.new(command, true)
|
86
90
|
parser.parse!(args, command_result)
|
data/lib/choosy/verifier.rb
CHANGED
@@ -34,12 +34,20 @@ module Choosy
|
|
34
34
|
if result.command.arguments
|
35
35
|
arguments = result.command.arguments
|
36
36
|
|
37
|
+
result.args.map! do |value|
|
38
|
+
Converter.convert(arguments.cast_to, value)
|
39
|
+
end
|
40
|
+
|
37
41
|
if result.args.length < arguments.arity.min
|
38
42
|
raise Choosy::ValidationError.new("#{prefix}too few arguments (minimum is #{arguments.arity.min})")
|
39
43
|
elsif result.args.length > arguments.arity.max
|
40
44
|
raise Choosy::ValidationError.new("#{prefix}too many arguments (max is #{arguments.arity.max}): '#{result.args[arguments.arity.max]}'")
|
41
45
|
end
|
42
46
|
|
47
|
+
result.args.each do |val|
|
48
|
+
check(arguments.allowable_values, val)
|
49
|
+
end if arguments.restricted?
|
50
|
+
|
43
51
|
if arguments.validation_step
|
44
52
|
arguments.validation_step.call(result.args, result.options)
|
45
53
|
end
|
data/lib/choosy/version.rb
CHANGED
@@ -1,12 +1,71 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
|
+
require 'time'
|
3
|
+
require 'choosy/errors'
|
2
4
|
|
3
5
|
module Choosy
|
4
6
|
class Version
|
5
|
-
|
6
|
-
MAJOR, MINOR, TINY = CURRENT.scanf('%d.%d.%d')
|
7
|
+
attr_accessor :date_format, :version_file
|
7
8
|
|
8
|
-
def
|
9
|
-
|
9
|
+
def initialize(version_file, date_format='%d/%m/%Y')
|
10
|
+
if !File.file?(version_file)
|
11
|
+
raise Choosy::ConfigurationError.new("No version file given: #{version_file}")
|
12
|
+
end
|
13
|
+
|
14
|
+
@version_file = version_file
|
15
|
+
@date_format = date_format
|
16
|
+
reload!
|
17
|
+
end
|
18
|
+
|
19
|
+
def tiny
|
20
|
+
@contents[VERSION][TINY]
|
21
|
+
end
|
22
|
+
|
23
|
+
def minor
|
24
|
+
@contents[VERSION][MINOR]
|
25
|
+
end
|
26
|
+
|
27
|
+
def major
|
28
|
+
@contents[VERSION][MAJOR]
|
29
|
+
end
|
30
|
+
|
31
|
+
def date
|
32
|
+
@contents[DATE]
|
10
33
|
end
|
34
|
+
|
35
|
+
def reload!
|
36
|
+
@contents = YAML.load_file(@version_file)
|
37
|
+
end
|
38
|
+
|
39
|
+
def version!(kind)
|
40
|
+
kind = kind.to_s
|
41
|
+
unless VERSIONS.include?(kind)
|
42
|
+
raise Choosy::VersionError.new("Wrong versioning schema: #{kind}")
|
43
|
+
end
|
44
|
+
|
45
|
+
VERSIONS.each do |vers|
|
46
|
+
if vers == kind
|
47
|
+
@contents[VERSION][kind] += 1
|
48
|
+
break
|
49
|
+
else
|
50
|
+
@contents[VERSION][vers] = 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@contents[DATE] = Time.now.strftime(@date_format)
|
54
|
+
File.open(@version_file, 'w') do |out|
|
55
|
+
YAML.dump(@contents, out)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
"#{major}.#{minor}.#{tiny}"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
VERSION = 'version'
|
65
|
+
TINY = 'tiny'
|
66
|
+
MINOR = 'minor'
|
67
|
+
MAJOR = 'major'
|
68
|
+
VERSIONS = [TINY, MINOR, MAJOR]
|
69
|
+
DATE = 'date'
|
11
70
|
end
|
12
71
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helpers'
|
2
|
+
require 'choosy/argument'
|
3
|
+
|
4
|
+
module Choosy
|
5
|
+
describe Argument do
|
6
|
+
before :each do
|
7
|
+
@argument = Argument.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe :restricted? do
|
11
|
+
it "should be false when there are no allowable_values" do
|
12
|
+
@argument.restricted?.should be(false)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be true when there are allowable_values" do
|
16
|
+
@argument.allowable_values = [:a]
|
17
|
+
@argument.restricted?.should be(true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe :finalize! do
|
22
|
+
it "should set the arity if not already set" do
|
23
|
+
@argument.finalize!
|
24
|
+
@argument.arity.should eql(0..0)
|
25
|
+
end
|
26
|
+
end#finalize!
|
27
|
+
end
|
28
|
+
end
|
@@ -6,9 +6,13 @@ module Choosy
|
|
6
6
|
before :each do
|
7
7
|
@cmd = Command.new :cmd
|
8
8
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
|
10
|
+
describe :finalize! do
|
11
|
+
it "should set the printer if not already set" do
|
12
|
+
@cmd.finalize!
|
13
|
+
@cmd.printer.should be_a(Choosy::Printing::HelpPrinter)
|
14
|
+
end
|
15
|
+
end#finalize!
|
12
16
|
|
13
17
|
it "should order the options in dependency order" do
|
14
18
|
@cmd.alter do
|
data/spec/choosy/command_spec.rb
CHANGED
@@ -37,7 +37,7 @@ module Choosy
|
|
37
37
|
}.should raise_error(SystemExit)
|
38
38
|
end
|
39
39
|
|
40
|
-
o.should match(
|
40
|
+
o.should match(/--help/)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should make sure that help gets check before other required options" do
|
@@ -52,7 +52,7 @@ module Choosy
|
|
52
52
|
}.should raise_error(SystemExit)
|
53
53
|
end
|
54
54
|
|
55
|
-
o.should match(
|
55
|
+
o.should match(/--help/)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -106,8 +106,9 @@ module Choosy
|
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should be able to parse a good yaml file" do
|
109
|
-
|
110
|
-
y.
|
109
|
+
version_file = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'VERSION.yml')
|
110
|
+
y = Converter.convert(:yaml, version_file)
|
111
|
+
y['version']['major'].should eql(Choosy::Version.new(version_file).major)
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
@@ -5,7 +5,7 @@ module Choosy::DSL
|
|
5
5
|
describe ArgumentBuilder do
|
6
6
|
before :each do
|
7
7
|
@builder = ArgumentBuilder.new
|
8
|
-
@argument = @builder.
|
8
|
+
@argument = @builder.entity
|
9
9
|
end
|
10
10
|
|
11
11
|
describe :required do
|
@@ -25,6 +25,24 @@ module Choosy::DSL
|
|
25
25
|
end
|
26
26
|
end#required
|
27
27
|
|
28
|
+
describe :only do
|
29
|
+
it "should require at least one argument" do
|
30
|
+
attempting {
|
31
|
+
@builder.only
|
32
|
+
}.should raise_error(Choosy::ConfigurationError, /'only'/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should set the allowable_values for an option" do
|
36
|
+
@builder.only :this, :that, :other
|
37
|
+
@argument.allowable_values.should eql([:this, :that, :other])
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should cast to a symbol if not already set" do
|
41
|
+
@builder.only :this, :that, :other
|
42
|
+
@argument.cast_to.should eql(:symbol)
|
43
|
+
end
|
44
|
+
end#only
|
45
|
+
|
28
46
|
describe :metaname do
|
29
47
|
it "should be able to set the name of the metaname" do
|
30
48
|
@builder.metaname 'PARAM'
|
@@ -168,13 +186,6 @@ module Choosy::DSL
|
|
168
186
|
value.should eql('here')
|
169
187
|
end
|
170
188
|
end#validate
|
171
|
-
|
172
|
-
describe :finalize! do
|
173
|
-
it "should set the arity if not already set" do
|
174
|
-
@builder.finalize!
|
175
|
-
@argument.arity.should eql(0..0)
|
176
|
-
end
|
177
|
-
end#finalize!
|
178
189
|
end
|
179
190
|
end
|
180
191
|
|