Class: LicenseScout::CLI

Inherits:
Object
  • Object
show all
Includes:
Mixlib::CLI
Defined in:
lib/license_scout/cli.rb

Instance Method Summary collapse

Instance Method Details

#run(argv = ARGV) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/license_scout/cli.rb', line 78

def run(argv = ARGV)
  parse_options(argv)

  LicenseScout::Config.merge!(config)

  Mixlib::Log::Formatter.show_time = false
  LicenseScout::Log.level = LicenseScout::Config.log_level

  LicenseScout::Config.config_files.each do |config_file|
    if config_file =~ /^http/
      require "open-uri" unless defined?(OpenURI)

      LicenseScout::Log.info("[cli] Loading config from #{config_file}")

      Dir.mktmpdir do |dir|
        local_tmp_file = File.join(dir, File.basename(config_file))
        IO.copy_stream(open(config_file), local_tmp_file)
        LicenseScout::Config.from_file(local_tmp_file)
      end
    else
      full_config_file = File.expand_path(config_file)

      if File.exist?(full_config_file)
        LicenseScout::Log.info("[cli] Loading config from #{full_config_file}")
        LicenseScout::Config.from_file(full_config_file)
      else
        LicenseScout::Log.warn("[cli] Could not find #{full_config_file} -- skipping")
      end
    end
  end

  LicenseScout::Config.validate!

  case cli_arguments[0]
  when "export"
    json_file = cli_arguments[1]
    export_format = config[:format]

    exporter = LicenseScout::Exporter.new(json_file, export_format)
    exporter.export
  else
    collector = LicenseScout::Collector.new
    collector.collect

    reporter = LicenseScout::Reporter.new(collector.dependencies)
    reporter.report
  end
  exit 0
rescue Exceptions::FailExit
  exit 1
end