Class: Udb::CliCommands::List
- Inherits:
-
SubCommandBase
- Object
- Thor
- SubCommandBase
- Udb::CliCommands::List
- Defined in:
- lib/udb/cli.rb
Instance Method Summary collapse
Methods inherited from SubCommandBase
Instance Method Details
#csrs ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/udb/cli.rb', line 334 def csrs raise ArgumentError, "Arch directory does not exist: #{[:arch]}" unless File.directory?([:arch]) cfg_file = if File.file?([:config]) Pathname.new([:config]) elsif File.file?("#{[:config_dir]}/#{[:config]}.yaml") Pathname.new("#{[:config_dir]}/#{[:config]}.yaml") else raise ArgumentError, "Cannot find config: #{[:config]}" end resolver = Udb::Resolver.new( std_path_override: Pathname.new([:arch]), custom_path_override: Pathname.new([:arch_overlay]), gen_path_override: Pathname.new([:gen]) ) cfg_arch = resolver.cfg_arch_for(cfg_file.realpath) count = 0 cfg_arch.csrs.each do |csr| puts csr.name count += 1 end count end |
#extensions ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/udb/cli.rb', line 232 def extensions raise ArgumentError, "Arch directory does not exist: #{[:arch]}" unless File.directory?([:arch]) out = if [:output] == "-" $stdout else File.open([:output], "w") end cfg_file = if File.file?([:config]) Pathname.new([:config]) elsif File.file?("#{[:config_dir]}/#{[:config]}.yaml") Pathname.new("#{[:config_dir]}/#{[:config]}.yaml") else raise ArgumentError, "Cannot find config: #{[:config]}" end resolver = Udb::Resolver.new( std_path_override: Pathname.new([:arch]), gen_path_override: Pathname.new([:gen]), custom_path_override: Pathname.new([:arch_overlay]) ) cfg_arch = resolver.cfg_arch_for(cfg_file.realpath) cfg_arch.possible_extensions.each do |ext| out.puts ext.name end end |
#parameters ⇒ Object
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 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/udb/cli.rb', line 273 def parameters raise ArgumentError, "Arch directory does not exist: #{[:arch]}" unless File.directory?([:arch]) out = if [:output] == "-" $stdout else File.open([:output], "w") end cfg_file = if File.file?([:config]) Pathname.new([:config]) elsif File.file?("#{[:config_dir]}/#{[:config]}.yaml") Pathname.new("#{[:config_dir]}/#{[:config]}.yaml") else raise ArgumentError, "Cannot find config: #{[:config]}" end resolver = Udb::Resolver.new( std_path_override: Pathname.new([:arch]), gen_path_override: Pathname.new([:gen]), custom_path_override: Pathname.new([:arch_overlay]) ) cfg_arch = resolver.cfg_arch_for(cfg_file.realpath) params = if [:extensions] cfg_arch.possible_extensions.select { |e| [:extensions].include?(e.name) }.map(&:params).flatten.uniq(&:name).sort else cfg_arch.params_with_value + cfg_arch.params_without_value end if [: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 [: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 [: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 |