Class: Gem::Commands::LicenseCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/license_command.rb

Overview

license gem plugin

Instance Method Summary collapse

Constructor Details

#initializeLicenseCommand

Returns a new instance of LicenseCommand.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubygems/commands/license_command.rb', line 9

def initialize
  super('license', 'Download a license by SPDX id')

  add_option('-m', '--markdown', 'Download as LICENSE.md') do |_, options|
    options[:markdown] = true
  end

  add_option('-s', '--stdout', 'Write to STDOUT instead of LICENSE') do |_, options|
    options[:stdout] = true
  end

  add_option('-o', '--output=PATH', 'Specify an output path') do |value, options|
    options[:output_path] = value
  end

  add_option('-l', '--list', 'View all available licenses') do |_, options|
    options[:list] = true
  end
end

Instance Method Details

#argumentsObject



47
48
49
# File 'lib/rubygems/commands/license_command.rb', line 47

def arguments
  'SPDX_IDENTIFIER   An identifier from SPDX\'s license list https://spdx.org/licenses/'
end

#descriptionObject



43
44
45
# File 'lib/rubygems/commands/license_command.rb', line 43

def description
  'Fetch a LICENSE based on an SPDX identifier'
end

#executeObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubygems/commands/license_command.rb', line 29

def execute
  if options[:list]
    list = Gem::License.fetch_license_list
    just_size = list.collect { |lsc| lsc['licenseId'].length }.max
    list.each do |license|
      say(license['licenseId'].ljust(just_size) + ' - ' + license['name'])
    end
    exit
  end

  id = options[:args].first || abort("USAGE: #{usage}")
  Gem::License.download(id, options)
end

#usageObject



51
52
53
# File 'lib/rubygems/commands/license_command.rb', line 51

def usage
  'gem license SPDX_IDENTIFIER'
end