junoser 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4593e83820c87e14eb51c1bc781a7ef739a30fd81ddbb0438a144b637897d8bc
4
- data.tar.gz: 9334a3f8c869085ac0d435f48b0cbc3add246b105f49215d72b355a8d2880dc6
3
+ metadata.gz: 3a3ba4fa96e3b50240e889334a924403ae8cf4f508c1e86120450aa0760fe75f
4
+ data.tar.gz: 6f034ac0b34aff7aed1f7aed0d87b902996ae1cdbbc0d0f6ed2896f50caaf939
5
5
  SHA512:
6
- metadata.gz: c7c4846a31f13cb84d6c82d08c6dd07b21cfa4941799bfff38f82e353db29bc8ffb8c8663b7b29cb658bc37eba9b49802d09c15c5c07ada303bdf7fee1654ca8
7
- data.tar.gz: 1802d0a8ba430e735d4f5f6c96264adf71396c30010a7fc8d620ad5ccb040b15595bd9e0f88f5db5ccd6c4fc980887d7f25f74a29ff539a0477467b8c4c2ba09
6
+ metadata.gz: ef0675b148025de1a36a95ec7bcd0ea92863a6740c6122ba6c675e02400ae7ab0cc59237083a4d01c11a56b8c070285b4817d7067fd702f7cd07990d4616cd19
7
+ data.tar.gz: c5cb5388660e8dd1605e39e7f1a02a2f7b118841d60927865e86ceea1d53c7a92b92390c552f60d3f33ea7d6dd8c7df94151e70a26a26bd0fe48e1d49029abb9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.3.10] - 2020-01-09
2
+
3
+ ### Added
4
+
5
+ * Experimentally support "insert" statement
6
+
7
+ ### Fixed
8
+
9
+ * junoser-squash unexpectedly kept statements intact due to tokenization bug
10
+ * junoser-squash unexpectedly removed "deactivate" statements
11
+ * "deactivate" to "inactive:" translation during "junoser -s"
12
+
1
13
  ## [0.3.9] - 2019-11-17
2
14
 
3
15
  ### Fixed
@@ -15,14 +27,14 @@
15
27
 
16
28
  ## [0.3.7] - 2019-09-03
17
29
 
18
- ### Fixed
19
-
20
- * "apply-groups" translation between "display set" and structured form
21
-
22
30
  ### Added
23
31
 
24
32
  * Support "deactivate ... apply-groups"
25
33
 
34
+ ### Fixed
35
+
36
+ * "apply-groups" translation between "display set" and structured form
37
+
26
38
 
27
39
  ## [0.3.6] - 2019-08-25
28
40
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- junoser (0.3.9)
4
+ junoser (0.3.10)
5
5
  parslet
6
6
 
7
7
  GEM
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Shintaro Kojima
3
+ Copyright (c) 2020 Shintaro Kojima
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -67,4 +67,4 @@ Or send a pull request to fix.
67
67
 
68
68
  ## Copyright and License
69
69
 
70
- Copyright (c) 2019 Shintaro Kojima. Code released under the [MIT license](LICENSE.txt).
70
+ Copyright (c) 2020 Shintaro Kojima. Code released under the [MIT license](LICENSE.txt).
@@ -78,7 +78,7 @@ module Junoser
78
78
  def match(str)
79
79
  each do |statement, store|
80
80
  # NOTE: return the first object
81
- return [statement, store] if str =~ /^#{Regexp.escape(statement)}(\b|$)/
81
+ return [statement, store] if str =~ /^#{Regexp.escape(statement)}((?= )|$)/
82
82
  end
83
83
 
84
84
  []
@@ -87,7 +87,7 @@ module Junoser
87
87
  def inverse_match(str)
88
88
  each do |statement, store|
89
89
  # NOTE: return the first object
90
- return [statement, store] if statement =~ /^#{str}\b/
90
+ return [statement, store] if statement =~ /^#{str}(?= )/
91
91
  end
92
92
 
93
93
  []
@@ -2,62 +2,12 @@ require 'junoser'
2
2
  require 'parslet'
3
3
 
4
4
  module Junoser
5
- class DeleteTransformer < Parslet::Transform
6
- rule(config: simple(:config)) do
7
- "(#{config.to_s} .*"
8
- end
9
-
10
- rule(config: sequence(:configs)) do
11
- configs.join("\n")
12
- end
13
-
14
- rule(arg: simple(:arg)) do
15
- arg
16
- end
17
-
18
- rule(label: simple(:label)) do
19
- ")#{Regexp.escape(label.to_s)}"
20
- end
21
-
22
- rule(label: simple(:label), child: simple(:child)) do
23
- "#{Regexp.escape(label.to_s)} #{child}"
24
- end
25
-
26
- rule(label: simple(:label), child: sequence(:children)) do
27
- %[#{Regexp.escape(label.to_s)} #{children.join(' ')}]
28
- end
29
-
30
- rule(statement: simple(:statement), argument: simple(:argument)) do
31
- "#{statement} #{argument}"
32
- end
33
-
34
- rule(statement: simple(:statement), argument: sequence(:arguments)) do
35
- %[#{statement} #{arguments.join(' ')}]
36
- end
37
-
38
- rule(oneline: simple(:str)) do
39
- str
40
- end
41
-
42
- rule(oneline: sequence(:strs)) do
43
- strs.join(' ')
44
- end
45
-
46
- rule(enum: simple(:str)) do
47
- str
48
- end
49
-
50
- rule(enum: sequence(:strs)) do
51
- strs.join(' ')
52
- end
53
- end
54
-
55
5
  class Squash
56
6
  def initialize(io_or_string)
57
7
  @input = io_or_string
58
8
  @lines = []
59
9
  @parser = Junoser::Parser.new
60
- @transformer = DeleteTransformer.new
10
+ @transformer = Junoser::Transformer.new
61
11
  end
62
12
 
63
13
  def transform
@@ -65,11 +15,14 @@ module Junoser
65
15
  config.each do |l|
66
16
  l.strip!
67
17
  case l
68
- when /^set /
69
- @lines << l
70
- when /^delete /
71
- to_delete = @parser.parse(l.gsub(/^delete /, 'set '))
72
- delete_lines @transformer.apply(to_delete)
18
+ when /^(set|deactivate) /
19
+ @lines << l
20
+ when /^delete /
21
+ delete_lines delete_pattern(l.gsub(/^delete /, 'set '))
22
+ when /^insert (.*) before (.*)/
23
+ insert_before insert_pattern("set #{$1}"), $2
24
+ when /^insert (.*) after (.*)/
25
+ insert_after insert_pattern("set #{$1}"), $2
73
26
  end
74
27
  end
75
28
 
@@ -80,7 +33,7 @@ module Junoser
80
33
  private
81
34
 
82
35
  def remove_subcommand(lines)
83
- lines.each_with_index do |l,i|
36
+ lines.each_with_index do |l, i|
84
37
  lines[i..-1].each do |l2|
85
38
  if l.include?(l2) and l != l2
86
39
  lines.delete(l2)
@@ -94,5 +47,48 @@ module Junoser
94
47
  l.sub!(/#{pattern}/) { $1 }
95
48
  end
96
49
  end
50
+
51
+ def split_last_token(line)
52
+ tokens = join_arg(@transformer.apply(@parser.parse(line))).split("\n")
53
+ tokens.map! { |t|
54
+ t.gsub!(/arg\((.*)\)/) { "#$1" } # Strip arg
55
+ Regexp.escape(t.strip)
56
+ }
57
+
58
+ [tokens[0..-2].join(' '), tokens.last]
59
+ end
60
+
61
+ # Ported from lib/junoser/display/config_store.rb
62
+ def join_arg(str)
63
+ str.gsub!(/\narg\((.*)\)$/) { " #$1" }
64
+ str.gsub!(/arg\((.*)\)/) { "#$1" }
65
+ str
66
+ end
67
+
68
+ def delete_pattern(line)
69
+ line, last_token = split_last_token(line)
70
+ "(#{line}\s+)#{last_token}.*"
71
+ end
72
+
73
+ def insert_pattern(line)
74
+ line, last_token = split_last_token(line)
75
+ "(#{line})\s+#{last_token}"
76
+ end
77
+
78
+ def insert_before(pattern_to_insert, key_token)
79
+ key_pattern = pattern_to_insert.sub(/\).*/) { ") #{key_token}" }
80
+
81
+ lines_to_insert = @lines.select { |l| l =~ /#{pattern_to_insert}/ }
82
+ @lines.reject! { |l| l =~ /#{pattern_to_insert}/ }
83
+
84
+ key_index = @lines.index { |l| l =~ /#{key_pattern}/ }
85
+ @lines.insert(key_index, lines_to_insert).flatten!
86
+ end
87
+
88
+ def insert_after(pattern_to_insert, key_token)
89
+ @lines.reverse!
90
+ insert_before pattern_to_insert, key_token
91
+ @lines.reverse!
92
+ end
97
93
  end
98
94
  end
@@ -1,3 +1,3 @@
1
1
  module Junoser
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junoser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-17 00:00:00.000000000 Z
11
+ date: 2020-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.0.4
153
+ rubygems_version: 3.1.2
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: PEG parser for JUNOS configuration.