forked from codeout/junoser
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
68 lines (53 loc) · 1.51 KB
/
Rakefile
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
require 'bundler/gem_tasks'
require 'junoser/development'
require 'nokogiri'
require 'pathname'
require 'rake/testtask'
xsd_path = File.join(__dir__, 'tmp/junos-18.1.xsd')
rule_path = File.join(__dir__, 'tmp/rule.rb')
ruby_parser_path = File.join(__dir__, 'lib/junoser/parser.rb')
js_parser_path = File.join(__dir__, 'tmp/schema.js')
def open_files(input, output, &block)
i = open(input)
o = open(output, 'w')
yield i, o
i.close
o.close
end
namespace :build do
desc 'Build an intermediate config hierarchy'
task :config do
open_files(xsd_path, rule_path) do |input, output|
Nokogiri::XML(input).root.remove_unused.xpath('/xsd:schema/*').each do |e|
output.puts e.to_config
end
end
end
desc 'Build ruby parser'
task :rule do
open_files(rule_path, ruby_parser_path) do |input, output|
output.puts Junoser::Ruler.new(input).to_rule
end
end
desc 'Build javascript parser'
task :jsrule do
open_files(rule_path, js_parser_path) do |input, output|
output.puts Junoser::JsRuler.new(input).to_rule
end
end
end
task 'find-srx-methods' do
vsrx = File.read('vsrx.rb')
vmx = File.read('lib/junoser/parser.rb')
vsrx.scan(/^ +([0-9a-z_]+) *$/).flatten.uniq.sort.each do |method|
next if ['arg', 'end', 'ipaddr', 'time'].include?(method)
puts method unless vsrx =~ /rule\(:#{method}\)/m || vmx =~ /rule\(:#{method}\)/m
end
end
Rake::TestTask.new do |t|
t.libs << 'test'
t.verbose = true
t.warning = false
end
desc 'Run tests'
task default: :test