Commit 40787f5
Changed files (8)
lib
spandx
cli
lib/spandx/cli/commands/scan.rb
@@ -56,7 +56,7 @@ module Spandx
end
def with_printer(output)
- printer = ::Spandx::Core::Printer.for(@options[:format])
+ printer = ::Spandx::Cli::Printer.for(@options[:format])
printer.print_header(output)
yield printer
ensure
lib/spandx/cli/printers/csv.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Spandx
+ module Cli
+ module Printers
+ class Csv < Printer
+ def match?(format)
+ format.to_sym == :csv
+ end
+
+ def print_line(dependency, io)
+ io.puts(CSV.generate_line(dependency.to_a))
+ end
+ end
+ end
+ end
+end
lib/spandx/cli/printers/json.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Spandx
+ module Cli
+ module Printers
+ class Json < Printer
+ def match?(format)
+ format.to_sym == :json
+ end
+
+ def print_line(dependency, io)
+ io.puts(Oj.dump(dependency.to_h))
+ end
+ end
+ end
+ end
+end
lib/spandx/cli/printers/table.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module Spandx
+ module Cli
+ module Printers
+ class Table < Printer
+ HEADINGS = ['Name', 'Version', 'Licenses', 'Location'].freeze
+
+ def match?(format)
+ format.to_sym == :table
+ end
+
+ def print_header(_io)
+ @dependencies = SortedSet.new
+ end
+
+ def print_line(dependency, _io)
+ @dependencies << dependency
+ end
+
+ def print_footer(io)
+ io.puts(to_table(@dependencies.map(&:to_a)))
+ end
+
+ private
+
+ def to_table(rows)
+ Terminal::Table.new(headings: HEADINGS) do |table|
+ rows.each { |row| table.add_row(row) }
+ end
+ end
+ end
+ end
+ end
+end
lib/spandx/core/printer.rb → lib/spandx/cli/printer.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Spandx
- module Core
+ module Cli
class Printer
def match?(_format)
raise ::Spandx::Error, :match?
@@ -16,7 +16,7 @@ module Spandx
def print_footer(io); end
class << self
- include Registerable
+ include Core::Registerable
def for(format)
find { |x| x.match?(format) } || new
lib/spandx/core/csv_printer.rb
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-module Spandx
- module Core
- class CsvPrinter < Printer
- def match?(format)
- format.to_sym == :csv
- end
-
- def print_line(dependency, io)
- io.puts(CSV.generate_line(dependency.to_a))
- end
- end
- end
-end
lib/spandx/core/json_printer.rb
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-module Spandx
- module Core
- class JsonPrinter < Printer
- def match?(format)
- format.to_sym == :json
- end
-
- def print_line(dependency, io)
- io.puts(Oj.dump(dependency.to_h))
- end
- end
- end
-end
lib/spandx/core/table_printer.rb
@@ -1,33 +0,0 @@
-# frozen_string_literal: true
-
-module Spandx
- module Core
- class TablePrinter < Printer
- HEADINGS = ['Name', 'Version', 'Licenses', 'Location'].freeze
-
- def match?(format)
- format.to_sym == :table
- end
-
- def print_header(_io)
- @dependencies = SortedSet.new
- end
-
- def print_line(dependency, _io)
- @dependencies << dependency
- end
-
- def print_footer(io)
- io.puts(to_table(@dependencies.map(&:to_a)))
- end
-
- private
-
- def to_table(rows)
- Terminal::Table.new(headings: HEADINGS) do |table|
- rows.each { |row| table.add_row(row) }
- end
- end
- end
- end
-end