cmds 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cmds/util.rb +5 -5
- data/lib/cmds/version.rb +1 -1
- data/spec/cmds/prepare_spec.rb +32 -0
- data/spec/cmds/replace_shortcuts_spec.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4dd9eb9dad554191cff2d860c105b44339cdcae
|
4
|
+
data.tar.gz: f89fe5555622db117c1b94abf50307f9758bb062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac624f99ca246ac0f13c101c8f2066110eed0af071ae159e9d6f41bb82dfaa2534c42c4f4636d4c37d77fadfea90edd546025d1975270eaecab676730b2bc6c
|
7
|
+
data.tar.gz: f5fd451da65e260f12bfa4b54b47aef1942e79bcc4c346b330e672133687f55cf702bbd2298ae2c9ca851f7f51ece6293bd5bfc99ba0fe32f2d641fdbbc893f9
|
data/lib/cmds/util.rb
CHANGED
@@ -65,27 +65,27 @@ module Cmds
|
|
65
65
|
template
|
66
66
|
.gsub(
|
67
67
|
# %s => <%= arg %>
|
68
|
-
/(?<=\A
|
68
|
+
/(?<=\A|\=|[[:space:]])\%s(?=\Z|[[:space:]])/,
|
69
69
|
'<%= arg %>'
|
70
70
|
)
|
71
71
|
.gsub(
|
72
|
-
# %%s => %s (
|
72
|
+
# %%s => %s (escaping)
|
73
73
|
/(?<=\A|[[:space:]])(\%+)\%s(?=\Z|[[:space:]])/,
|
74
74
|
'\1s'
|
75
75
|
)
|
76
76
|
.gsub(
|
77
77
|
# %{key} => <%= key %>, %{key?} => <%= key? %>
|
78
|
-
/(?<=\A
|
78
|
+
/(?<=\A|\=|[[:space:]])\%\{([a-zA-Z_]+\??)\}(?=\Z|[[:space:]])/,
|
79
79
|
'<%= \1 %>'
|
80
80
|
)
|
81
81
|
.gsub(
|
82
|
-
# %%{key} => %{key}, %%{key?} => %{key?} (
|
82
|
+
# %%{key} => %{key}, %%{key?} => %{key?} (escaping)
|
83
83
|
/(?<=\A|[[:space:]])(\%+)\%\{([a-zA-Z_]+\??)\}(?=\Z|[[:space:]])/,
|
84
84
|
'\1{\2}\3'
|
85
85
|
)
|
86
86
|
.gsub(
|
87
87
|
# %<key>s => <%= key %>, %<key?>s => <%= key? %>
|
88
|
-
/(?<=\A
|
88
|
+
/(?<=\A|\=|[[:space:]])\%\<([a-zA-Z_]+\??)\>s(?=\Z|[[:space:]])/,
|
89
89
|
'<%= \1 %>'
|
90
90
|
)
|
91
91
|
.gsub(
|
data/lib/cmds/version.rb
CHANGED
data/spec/cmds/prepare_spec.rb
CHANGED
@@ -166,5 +166,37 @@ describe "Cmds.prepare" do
|
|
166
166
|
Cmds.prepare "./test/echo_cmd.rb %<key>s", key: "hello world!"
|
167
167
|
).to eq './test/echo_cmd.rb hello\ world\!'
|
168
168
|
end
|
169
|
+
|
170
|
+
context "% proceeded by =" do
|
171
|
+
it "handles %s" do
|
172
|
+
expect(
|
173
|
+
Cmds.prepare "X=%s ./test/echo_cmd.rb", "hello world!"
|
174
|
+
).to eq 'X=hello\ world\! ./test/echo_cmd.rb'
|
175
|
+
|
176
|
+
expect(
|
177
|
+
Cmds.prepare "./test/echo_cmd.rb --x=%s", "hello world!"
|
178
|
+
).to eq './test/echo_cmd.rb --x=hello\ world\!'
|
179
|
+
end
|
180
|
+
|
181
|
+
it "handles %{key}" do
|
182
|
+
expect(
|
183
|
+
Cmds.prepare "X=%{key} ./test/echo_cmd.rb", key: "hello world!"
|
184
|
+
).to eq 'X=hello\ world\! ./test/echo_cmd.rb'
|
185
|
+
|
186
|
+
expect(
|
187
|
+
Cmds.prepare "./test/echo_cmd.rb --x=%<key>s", key: "hello world!"
|
188
|
+
).to eq './test/echo_cmd.rb --x=hello\ world\!'
|
189
|
+
end
|
190
|
+
|
191
|
+
it "handles %<key>s" do
|
192
|
+
expect(
|
193
|
+
Cmds.prepare "X=%<key>s ./test/echo_cmd.rb", key: "hello world!"
|
194
|
+
).to eq 'X=hello\ world\! ./test/echo_cmd.rb'
|
195
|
+
|
196
|
+
expect(
|
197
|
+
Cmds.prepare "./test/echo_cmd.rb --x=%<key>s", key: "hello world!"
|
198
|
+
).to eq './test/echo_cmd.rb --x=hello\ world\!'
|
199
|
+
end
|
200
|
+
end # % proceeded by =
|
169
201
|
end # shortcuts
|
170
202
|
end # ::sub
|
@@ -115,4 +115,29 @@ describe 'Cmds::replace_shortcuts' do
|
|
115
115
|
["50%savings!"] => "50%savings!",
|
116
116
|
}
|
117
117
|
end
|
118
|
+
|
119
|
+
context "% proceeded by =" do
|
120
|
+
it "should do %s substitution when proceeded by an =" do
|
121
|
+
expect_map meth, {
|
122
|
+
["X=%s"] => "X=<%= arg %>",
|
123
|
+
["hey there=%s"] => "hey there=<%= arg %>",
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
it "should do %{key} substitution when proceeded by an =" do
|
129
|
+
expect_map meth, {
|
130
|
+
["X=%{key}"] => "X=<%= key %>",
|
131
|
+
["hey there=%{key}"] => "hey there=<%= key %>",
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
it "should do %<key>s substitution when proceeded by an =" do
|
137
|
+
expect_map meth, {
|
138
|
+
["X=%<key>s"] => "X=<%= key %>",
|
139
|
+
["hey there=%<key>s"] => "hey there=<%= key %>",
|
140
|
+
}
|
141
|
+
end
|
142
|
+
end # % proceeded by =
|
118
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nrser
|