class Object

Constants

LICENSES
LicenseName

Public Instance Methods

parse() click to toggle source
# File bin/gen-license, line 60
def parse
  opt = OptionParser.new
  argvLength = ARGV.length
  code = ARGV[0]

  if argvLength == 0
    printHelp
    exit
  end

  if code == '-h'
    printHelp
    exit
  end

  if code == '--list'
    printLicenses
    exit
  end

  if code
    if LICENSES.include?(code)
      s = readTemplate("#{code}")
      writeLicense(s)
      printResult(code)
    else
      printCodeError(code)
    end
    exit
  end

end
printCodeError(code) click to toggle source
# File bin/gen-license, line 44
def printCodeError(code)
  puts "error: argument code: invalid choice: '#{code}' (choose from 'agpl-3.0', 'apache-2.0', 'bsd-2-clause', 'bsd-3-clause', 'epl-2.0', 'gpl-2.0', 'gpl-3.0', 'lgpl-2.1', 'lgpl-3.0', 'mit', 'mpl-2.0', 'unlicenses')"
end
printHelp() click to toggle source
# File bin/gen-license, line 23
def printHelp
puts <<-EOS
usage: gen-license [-h] [--list]
                   [{agpl-3.0,apache-2.0,bsd-2-clause,bsd-3-clause,epl-2.0,gpl-2.0,gpl-3.0,lgpl-2.1,lgpl-3.0,mit,mpl-2.0,unlicenses}]

tools to create license file, support GitHub LICENSE code.

positional arguments:
  {agpl-3.0,apache-2.0,bsd-2-clause,bsd-3-clause,epl-2.0,gpl-2.0,gpl-3.0,lgpl-2.1,lgpl-3.0,mit,mpl-2.0,unlicenses}
                        LICENSE Code, --list to see

optional arguments:
  -h, --help            show this help message and exit
  --list                Show supported LICENSE Codes
EOS
end
printLicenses() click to toggle source
# File bin/gen-license, line 40
def printLicenses
  puts LICENSES
end
printResult(code) click to toggle source
# File bin/gen-license, line 48
def printResult(code)
  puts "#{code} license has been generated"
end
readTemplate(name) click to toggle source
# File bin/gen-license, line 52
def readTemplate(name)
  File.read(File.join(File.dirname(__FILE__), "../licenses/#{name}.txt"), :encoding => Encoding::UTF_8)
end
writeLicense(content) click to toggle source
# File bin/gen-license, line 56
def writeLicense(content)
  File.write("LICENSE", content)
end