Class: Glark::InputOptions
Constant Summary
Constants included
from OptionUtil
OptionUtil::NONE
Constants inherited
from InputSpec
Glark::InputSpec::VALID_BINARY_FILE_TYPES
Instance Attribute Summary
Attributes inherited from InputSpec
#binary_files, #dir_criteria, #directory, #exclude_matching, #file_criteria, #max_depth, #range, #split_as_path
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
Returns a new instance of InputOptions.
16
17
18
19
|
# File 'lib/glark/input/options.rb', line 16
def initialize optdata
super()
add_as_options optdata
end
|
Instance Method Details
#add_as_options(optdata) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/glark/input/options.rb', line 84
def add_as_options optdata
optdata << {
:res => [ Regexp.new('^ -0 (\d{1,3})? $ ', Regexp::EXTENDED) ],
:set => Proc.new { |md| rs = md ? md[1] : 0; set_record_separator rs }
}
@range.add_as_option optdata
optdata << {
:tags => %w{ -r --recurse },
:set => Proc.new { set_directory("recurse") }
}
optdata << {
:tags => %w{ --directories -d },
:arg => [ :string ],
:set => Proc.new { |val| set_directory val },
}
re = Regexp.new '^[\'\"]?(' + VALID_BINARY_FILE_TYPES.join('|') + ')[\'\"]?$'
optdata << {
:tags => %w{ --binary-files },
:arg => [ :required, :regexp, re ],
:set => Proc.new { |md| @binary_files = md[1] },
:rc => %w{ binary-files },
}
@file_criteria.add_as_options optdata
@dir_criteria.add_as_options optdata
add_opt_true optdata, :exclude_matching, %w{ -M --exclude-matching }
add_opt_false optdata, :split_as_path, %w{ --no-split-as-path }
add_opt_true optdata, :split_as_path, %w{ --split-as-path }
end
|
#config_fields ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/glark/input/options.rb', line 45
def config_fields
fields = {
"binary-files" => binary_files,
"split-as-path" => @split_as_path,
}
fields.merge! @dir_criteria.config_fields
fields.merge! @file_criteria.config_fields
end
|
#create_fileset(files) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/glark/input/options.rb', line 21
def create_fileset files
fsargs = Hash.new
fsargs[:max_depth] = @max_depth
fsargs[:binary_files] = @binary_files
fsargs[:dir_criteria] = @dir_criteria
fsargs[:file_criteria] = @file_criteria
fsargs[:split_as_path] = @split_as_path
FileSet.new files, fsargs
end
|
#dump_fields ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/glark/input/options.rb', line 54
def dump_fields
fields = {
"binary_files" => binary_files,
"directory" => @directory,
"exclude_matching" => @exclude_matching,
"split-as-path" => @split_as_path,
}
fields.merge! @dir_criteria.dump_fields
fields.merge! @file_criteria.dump_fields
fields
end
|
#set_directory(val) ⇒ Object
78
79
80
81
82
|
# File 'lib/glark/input/options.rb', line 78
def set_directory val
@max_depth = val == 'list' ? 0 : nil
@dir_criteria.skip_all = val == 'skip'
end
|
#set_record_separator(sep) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/glark/input/options.rb', line 32
def set_record_separator sep
$/ = if sep && sep.to_i > 0
begin
sep.oct.chr
rescue RangeError
nil
end
else
"\n\n"
end
end
|
#update_fields(fields) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/glark/input/options.rb', line 66
def update_fields fields
@dir_criteria.update_fields fields
@file_criteria.update_fields fields
fields.each do |name, value|
case name
when 'split-as-path'
@split_as_path = to_boolean value
end
end
end
|