Class: Glark::InfoOptions
Constant Summary
Constants included
from OptionUtil
OptionUtil::NONE
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from OptionUtil
#add_opt, #add_opt_arg, #add_opt_blk, #add_opt_false, #add_opt_int, #add_opt_str, #add_opt_true, #colorize, #set, #set_var, #to_boolean
Constructor Details
#initialize(colors, optdata) ⇒ InfoOptions
Returns a new instance of InfoOptions.
16
17
18
19
20
21
|
# File 'lib/glark/app/info/options.rb', line 16
def initialize colors, optdata
@colors = colors
@explain = false
add_as_options optdata
end
|
Instance Attribute Details
#colors ⇒ Object
Returns the value of attribute colors.
13
14
15
|
# File 'lib/glark/app/info/options.rb', line 13
def colors
@colors
end
|
#explain ⇒ Object
Returns the value of attribute explain.
14
15
16
|
# File 'lib/glark/app/info/options.rb', line 14
def explain
@explain
end
|
Instance Method Details
#add_as_options(optdata) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/glark/app/info/options.rb', line 65
def add_as_options optdata
add_opt_blk(optdata, %w{ -V --version }) { show_version }
add_opt_blk(optdata, %w{ --verbose }) { Logue::Log.verbose = true }
add_opt_blk(optdata, %w{ -? --help }) { Help.new.show_usage; exit 0 }
add_opt_blk(optdata, %w{ --man }) { Help.new.show_man; exit 0 }
add_opt_true optdata, :explain, %w{ --explain }
add_opt_blk(optdata, %w{ -q -s --quiet --messages }) { Logue::Log.quiet = true }
add_opt_blk(optdata, %w{ -Q -S --no-quiet --no-messages }) { Logue::Log.quiet = false }
end
|
#config_fields ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/glark/app/info/options.rb', line 23
def config_fields
{
"known-nontext-files" => FileType.nontext_extensions.sort.join(' '),
"known-text-files" => FileType.text_extensions.sort.join(' '),
"quiet" => Logue::Log.quiet,
"verbose" => Logue::Log.verbose,
}
end
|
#dump_fields ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/glark/app/info/options.rb', line 32
def dump_fields
{
"explain" => @explain,
"known_nontext_files" => FileType.nontext_extensions.join(", "),
"known_text_files" => FileType.text_extensions.join(", "),
"quiet" => Logue::Log.quiet,
"ruby version" => RUBY_VERSION,
"verbose" => Logue::Log.verbose,
"version" => Glark::VERSION,
}
end
|
#show_version ⇒ Object
77
78
79
80
81
82
|
# File 'lib/glark/app/info/options.rb', line 77
def show_version
puts Glark::PACKAGE + ", version " + Glark::VERSION
puts "Written by Jeff Pace ([email protected])."
puts "Released under the Lesser GNU Public License."
exit 0
end
|
#update_fields(fields) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/glark/app/info/options.rb', line 44
def update_fields fields
fields.each do |name, values|
case name
when "known-nontext-files"
values.last.split.each do |ext|
FileType.set_nontext ext
end
when "known-text-files"
values.last.split.each do |ext|
FileType.set_text ext
end
when "quiet"
Logue::Log.quiet = to_boolean(values.last)
when "verbose"
Logue::Log.verbose = to_boolean(values.last) ? 1 : nil
when "verbosity"
Logue::Log.verbose = values.last.to_i
end
end
end
|