Class: Gem::Commands::LicenseCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
License
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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubygems/commands/license_command.rb', line 11

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

  add_option('-f', '--format', 'Attempt to fill in values like year, author, and program name') do |_, options|
    options[:format] = true
  end
end

Instance Method Details

#argumentsObject



53
54
55
# File 'lib/rubygems/commands/license_command.rb', line 53

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

#descriptionObject



49
50
51
# File 'lib/rubygems/commands/license_command.rb', line 49

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

#executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubygems/commands/license_command.rb', line 35

def execute
  if options[:list]
    list = 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}")
  download(id, options)
end

#usageObject



57
58
59
# File 'lib/rubygems/commands/license_command.rb', line 57

def usage
  'gem license SPDX_IDENTIFIER'
end