-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
85 lines (78 loc) · 2.54 KB
/
main.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
49
50
51
52
53
54
55
56
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
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'get_rbs'
require 'commander/import'
require 'rubyXL'
require 'rubyXL/convenience_methods'
get_rbs 'table', 'parser', 'shortcut_parser', 'comment_parser', 'main_module',
from: 'program_files'
TEST_FILES = {
txt: './tests/test.txt',
pas: './tests/test.pas',
xlsx: './tests/test.xlsx'
}.freeze
##
# CLI
program :name, 'Barmaley'
program :version, '1.0.0'
program :description, 'Table maker for labs'
# Let me play a while!
command :hello do |c|
c.syntax = './main.rb hello SOMEONE'
c.summary = 'Says hello to SOMEONE'
c.description = 'Says hello to SOMEONE'
c.option '--from SOMEBODY', String, 'Say hello to SOMEONE from SOMEBODY'
c.action do |args, options|
options.default from: nil
if args.any?
print 'Hello'
print " from #{options.from}" unless options.from.nil?
print ", #{args.join(', ')}"
else
print 'Hello to who?'
end
puts
end
end
command :parse do |c|
c.syntax = './main.rb parse FILE'
c.summary = 'Finds tables in FILE'
c.description = "Finds tables like \nhello: world\nbegin: coding\ndo: end"
c.option '--to FILE', String, 'Print table to FILE', default: nil
c.action do |args, options|
options.default to: nil, as: nil
options.to.nil? && raise(ArgumentError, "'--to' empty. What file should I write to? ")
case File.extname(options.to)
when '.xlsx' then Parser.parse_to_xlsx(*args, to: options.to)
when 'txt' then Parser.parse_to_txt(*args, to: options.to)
else
raise(ArgumentError, "'--to' is not XLSX or TXT, it's #{File.extname(options.to)}")
end
end
end
command :shortparse do |c|
c.syntax = './main.rb shortparse FILE'
c.summary = 'Parses files to get tables with shortcuts'
c.description = "'Class-Name-Meaning-Type-Structure-Diapazone-Format'"\
' tables are parced when given as: c name:t[diapazone](s)"format"'
c.option '--to FILE', String, 'Print table to FILE'
c.option '--silent', 'Asks for silence', default: false
c.action do |args, options|
file = args[0]
if file.nil?
file = './tests/test.py'
puts "File not specified, running test file #{file}"
sleep 1
end
options.to ||= "#{File.dirname(file)}/#{File.basename(file, '.*')}.xlsx"
workbook = RubyXL::Workbook.new
table = Table.new
sheet = workbook[0]
Parser.parse_comments(file).each do |line|
table.add(Parser.shortcut_parse(line))
end
puts table unless options.silent
Parser.table_to_sheet(table, sheet)
workbook.write(options.to)
end
end