Class: LicenseFinder::CLI::Main

Inherits:
Base
  • Object
show all
Extended by:
Rootcommand
Defined in:
lib/license_finder/cli/main.rb

Constant Summary collapse

FORMATS =
{
  'text' => TextReport,
  'html' => HtmlReport,
  'markdown' => MarkdownReport,
  'csv' => CsvReport,
  'xml' => XmlReport,
  'json' => JsonReport,
  'junit' => JunitReport
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rootcommand

subcommand

Class Method Details

.format_optionObject

Method options which are shared between report and action_item



50
51
52
53
54
55
# File 'lib/license_finder/cli/main.rb', line 50

def self.format_option
  method_option :format,
                desc: 'Emit detailed info about what LicenseFinder is doing',
                default: 'text',
                enum: FORMATS.keys
end

.shared_optionsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/license_finder/cli/main.rb', line 57

def self.shared_options
  method_option :debug,
                aliases: '-d',
                type: :boolean,
                desc: 'Emit detailed info about what LicenseFinder is doing'

  method_option :prepare,
                aliases: '-p',
                type: :boolean,
                desc: 'Prepares the project first for license_finder',
                default: false,
                required: false

  method_option :prepare_no_fail,
                type: :boolean,
                desc: 'Prepares the project first for license_finder but carries on despite any potential failures',
                default: false,
                required: false

  method_option :recursive,
                aliases: '-r',
                type: :boolean,
                default: false,
                desc: 'Recursively runs License Finder on all sub-projects'

  method_option :aggregate_paths,
                aliases: '-a',
                type: :array,
                desc: "Generate a single report for multiple projects. Ex: --aggregate_paths='path/to/project1' 'path/to/project2'"

  method_option :quiet,
                aliases: '-q',
                type: :boolean,
                desc: 'Silences progress report',
                required: false

  method_option :columns,
                desc: "For text or CSV reports, which columns to print. Pick from: #{CsvReport::AVAILABLE_COLUMNS}",
                type: :array

  method_option :use_spdx_id,
                type: :boolean,
                desc: 'For reports, use the SPDX identifier instead of license name (useful to match license with other standard tools)',
                default: false
end

Instance Method Details

#action_itemsObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/license_finder/cli/main.rb', line 119

def action_items
  finder = LicenseAggregator.new(config, aggregate_paths)
  any_packages = finder.any_packages?
  unapproved = finder.unapproved
  restricted = finder.restricted

  # Ensure to start output on a new line even with dot progress indicators.
  printer.say "\n"

  unless any_packages
    printer.say 'No dependencies recognized!', :red
    exit 0
  end

  if unapproved.empty?
    printer.say 'All dependencies are approved for use', :green
  else
    unless restricted.empty?
      printer.say 'Restricted dependencies:', :red
      printer.say report_of(restricted)
    end

    other_unapproved = unapproved - restricted
    unless other_unapproved.empty?
      printer.say 'Dependencies that need approval:', :yellow
      printer.say report_of(other_unapproved)
    end

    exit 1
  end
end

#diff(file1, file2) ⇒ Object



173
174
175
176
177
178
# File 'lib/license_finder/cli/main.rb', line 173

def diff(file1, file2)
  f1 = IO.read(file1)
  f2 = IO.read(file2)
  report = DiffReport.new(Diff.compare(f1, f2))
  save? ? save_report(report, config.save_file) : printer.say(report)
end

#project_rootsObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/license_finder/cli/main.rb', line 105

def project_roots
  config.strict_matching = true
  project_path = config.project_path.to_s || Pathname.pwd.to_s
  paths = aggregate_paths
  filtered_project_roots = Scanner.remove_subprojects(paths)

  filtered_project_roots << project_path if aggregate_paths.include?(project_path) && !filtered_project_roots.include?(project_path)

  printer.say(filtered_project_roots)
end

#reportObject



159
160
161
162
163
# File 'lib/license_finder/cli/main.rb', line 159

def report
  finder = LicenseAggregator.new(config, aggregate_paths)
  report = report_of(finder.dependencies)
  save? ? save_report(report, config.save_file) : printer.say(report)
end

#versionObject



166
167
168
# File 'lib/license_finder/cli/main.rb', line 166

def version
  puts LicenseFinder::VERSION
end