195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/udb/cli.rb', line 195
def parameters
raise ArgumentError, "Arch directory does not exist: #{options[:arch]}" unless File.directory?(options[:arch])
out =
if options[:output] == "-"
$stdout
else
File.open(options[:output], "w")
end
cfg_file =
if File.file?(options[:config])
Pathname.new(options[:config])
elsif File.file?("#{options[:config_dir]}/#{options[:config]}.yaml")
Pathname.new("#{options[:config_dir]}/#{options[:config]}.yaml")
else
raise ArgumentError, "Cannot find config: #{options[:config]}"
end
resolver =
Udb::Resolver.new(
std_path_override: Pathname.new(options[:arch]),
gen_path_override: Pathname.new(options[:gen]),
custom_path_override: Pathname.new(options[:arch_overlay])
)
cfg_arch = resolver.cfg_arch_for(cfg_file.realpath)
params =
if options[:extensions]
cfg_arch.possible_extensions.select{ |e| options[:extensions].include?(e.name) }.map(&:params).flatten.uniq(&:name).sort
else
cfg_arch.possible_extensions.map(&:params).flatten.uniq(&:name).sort
end
if options[:output_format] == "ascii"
table = ::Terminal::Table.new(
headings: ["Name", "Extension(s)", "description"],
rows: params.map { |p| [p.name, p.exts.map(&:name).join(", "), p.desc] },
)
table.style = { all_separators: true }
out.puts table
elsif options[:output_format] == "yaml"
yaml = []
params.each do |p|
yaml << { "name" => p.name, "exts" => p.exts.map(&:name), "description" => p.desc }
end
out.puts YAML.dump(yaml)
elsif options[:output_format] == "json"
yaml = []
params.each do |p|
yaml << { "name" => p.name, "exts" => p.exts.map(&:name), "description" => p.desc }
end
out.puts JSON.dump(yaml)
end
end
|