Sha256: 235bb47969e16a334c84a512796ef0ec48a744f2f188aad1fda78b9187e70f23

Contents?: true

Size: 885 Bytes

Versions: 3

Compression:

Stored size: 885 Bytes

Contents

require 'optparse'

require 'pf2'
require 'pf2/reporter'

module Pf2
  class CLI
    def self.run(...)
      new.run(...)
    end

    def run(argv)
      options = {}
      option_parser = OptionParser.new do |opts|
        opts.on('-v', '--version', 'Prints version') do
          puts Pf2::VERSION
          exit
        end

        opts.on('-h', '--help', 'Prints this help') do
          puts opts
        end

        opts.on('-o', '--output FILE', 'Output file') do |path|
          options[:output_file] = path
        end
      end
      option_parser.parse!(argv)

      profile = JSON.parse(File.read(ARGV[0]), symbolize_names: true, max_nesting: false)
      report = JSON.generate(Pf2::Reporter.new(profile).emit)

      if options[:output_file]
        File.write(options[:output_file], report)
      else
        puts report
      end

      return 0
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pf2-0.4.0 lib/pf2/cli.rb
pf2-0.3.0 lib/pf2/cli.rb
pf2-0.2.0 lib/pf2/cli.rb