-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPDX2Lite.rb
48 lines (42 loc) · 968 Bytes
/
SPDX2Lite.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require './SPDX_parser'
require './SPDXLite_generator'
require './SPDXLite_TagValue_generator'
require './SPDXLite_xlsx_generator'
require 'optparse'
params = {}
opt = OptionParser.new
opt.version = [1, 2]
opt.banner = 'Usage: SPDX2Lite.rb [option] YOURSPDXFILE'
opt.on('-x OUTPUTFILE', 'output xlsx file') # { |v| p v }
opt.on('-n PAD', 'define padding character(s)') # { |v| p v }
begin
opt.parse!(ARGV, into: params)
#p ARGV
#p params
rescue
puts opt.help
exit(-1)
end
if ARGV.length != 1
puts opt.help
exit(-2)
end
f = File.open(ARGV[0])
parser = SPDXParser.new(f)
if !params[:x].nil?
if File.extname(params[:x]) == ''
filename = params[:x] + '.xlsx'
else
filename = params[:x]
end
if !params[:n].nil?
pad = params[:n]
else
pad = '-'
end
g = SPDXLiteXlsxGenerator.new(filename, pad)
else
g = SPDXLiteTagValueGenerator.new
end
g.fill_value(parser.context, parser.tag, parser.value) until parser.parse.nil?
g.finalize