Commit c4291dd

mo khan <mo.khan@gmail.com>
2019-12-28 00:55:05
Extract method to parse a ruby Gemfile.lock
1 parent ba74e7d
Changed files (1)
lib
spandx
commands
lib/spandx/commands/scan.rb
@@ -1,5 +1,6 @@
 # frozen_string_literal: true
 
+require 'json'
 require_relative '../command'
 
 module Spandx
@@ -11,8 +12,23 @@ module Spandx
       end
 
       def execute(input: $stdin, output: $stdout)
-        # Command logic goes here ...
-        output.puts "OK"
+        if @lockfile.nil?
+          output.puts "OK"
+        else
+          full_path = File.expand_path(@lockfile)
+          output.puts JSON.pretty_generate(build_report_for(full_path))
+        end
+      end
+
+      private
+
+      def build_report_for(lockfile)
+        report = { version: '1.0', packages: [] }
+        parser = ::Bundler::LockfileParser.new(IO.read(lockfile))
+        parser.dependencies.each do |key, value|
+          report[:packages].push(name: key, version: value.to_spec.version.to_s)
+        end
+        report
       end
     end
   end