Class: Udb::CliCommands::List
- Inherits:
-
SubCommandBase
- Object
- Thor
- SubCommandBase
- Udb::CliCommands::List
- Defined in:
- lib/udb/cli.rb
Instance Method Summary collapse
Instance Method Details
#csrs ⇒ Object
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 |
# File 'lib/udb/cli.rb', line 264 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
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/udb/cli.rb', line 162 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
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 248 249 250 251 252 253 254 255 |
# File 'lib/udb/cli.rb', line 203 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.possible_extensions.map(&:params).flatten.uniq(&:name).sort end if [: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 [: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 [: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 |