6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/crucigrama/cli/generate.rb', line 6
def options_parser
@options_parser ||= OptionParser.new do |opts|
opts.banner = "Usage: #{Crucigrama::CLI.cli_command} generate options"
opts.separator ""
opts.separator "Options:"
opts.on("-l", "--lemary LEMARY", "Uses LEMARY as words source") do |lemary|
begin
@options[:lemary] = File.read(lemary).split("\n")
rescue Exception => exc
STDERR.puts exc.message
end
end
opts.on("-d", "--dimensions DIMENSIONS", "Generates crossword of DIMENSIONS size",
"in nxn format (10x10 by default)") do |dimensions|
unless match = /(\d)+x(\d)+/.match(dimensions)
STDERR.puts "Incorrect dimensions format, it must be nxn (for example 10x11)"
exit 1
end
@options[:dimensions] = Hash[[:horizontal, :vertical].collect.with_index do |direction, i|
[direction, match[i].to_i]
end]
end
opts.on("-o", "--output FILE", "Dumps the generated crossword to FILE") do |file|
@options[:file] = file
end
opts.on("--[no-]definitions", "Asks for definitions for the generated crossword") do |definitions|
@options[:definitions] = definitions
end
opts.on("--[no-]reverse-words", "Allow reverse words for the generated crossword") do |value|
@options[:allow_reverse] = value
end
opts.separator ""
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("--version", "Show version") do
puts Crucigrama::VERSION
exit
end
end
end
|