260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
# File 'lib/udb/cli.rb', line 260
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.params_with_value + cfg_arch.params_without_value
end
if options[:output_format] == "ascii"
table = ::Terminal::Table.new(
headings: ["Name", "Defined By", "description"],
rows: params.map { |p| [p.name, p.defined_by_condition.to_s, p.description] },
)
table.style = { all_separators: true }
out.puts table
elsif options[:output_format] == "yaml"
yaml = []
params.each do |p|
yaml << { "name" => p.name, "exts" => p.defined_by_condition.to_s, "description" => p.description }
end
out.puts YAML.dump(yaml)
elsif options[:output_format] == "json"
yaml = []
params.each do |p|
yaml << { "name" => p.name, "exts" => p.defined_by_condition.to_s, "description" => p.description }
end
out.puts JSON.dump(yaml)
end
end
|