Skip to content

Commit bdf3ff1

Browse files
committed
Namespace function batch_escape()
1 parent 3bc89c3 commit bdf3ff1

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

lib/puppet/functions/batch_escape.rb

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
# frozen_string_literal: true
22

3-
# @summary
4-
# Escapes a string so that it can be safely used in a batch shell command line.
5-
#
6-
# >* Note:* that the resulting string should be used unquoted and is not intended for use in double quotes nor in single
7-
# quotes.
3+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
4+
5+
# @summary DEPRECATED. Use the namespaced function [`stdlib::batch_escape`](#stdlibbatch_escape) instead.
86
Puppet::Functions.create_function(:batch_escape) do
9-
# @param string
10-
# The string to escape
11-
#
12-
# @return
13-
# An escaped string that can be safely used in a batch command line.
14-
dispatch :batch_escape do
15-
param 'Any', :string
7+
dispatch :deprecation_gen do
8+
repeated_param 'Any', :args
169
end
17-
18-
def batch_escape(string)
19-
result = ''
20-
21-
string.to_s.chars.each do |char|
22-
result += case char
23-
when '"' then '""'
24-
when '$', '\\' then "\\#{char}"
25-
else char
26-
end
27-
end
28-
29-
%("#{result}")
10+
def deprecation_gen(*args)
11+
call_function('deprecation', 'batch_escape', 'This function is deprecated, please use stdlib::batch_escape instead.')
12+
call_function('stdlib::batch_escape', *args)
3013
end
3114
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
# @summary
4+
# Escapes a string so that it can be safely used in a batch shell command line.
5+
#
6+
# >* Note:* that the resulting string should be used unquoted and is not intended for use in double quotes nor in single
7+
# quotes.
8+
Puppet::Functions.create_function(:'stdlib::batch_escape') do
9+
# @param string
10+
# The string to escape
11+
#
12+
# @return
13+
# An escaped string that can be safely used in a batch command line.
14+
dispatch :batch_escape do
15+
param 'Any', :string
16+
end
17+
18+
def batch_escape(string)
19+
result = ''
20+
21+
string.to_s.chars.each do |char|
22+
result += case char
23+
when '"' then '""'
24+
when '$', '\\' then "\\#{char}"
25+
else char
26+
end
27+
end
28+
29+
%("#{result}")
30+
end
31+
end

spec/functions/batch_escape_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
require 'spec_helper'
44

5-
describe 'batch_escape' do
5+
describe 'stdlib::batch_escape' do
66
it { is_expected.not_to eq(nil) }
77

88
describe 'signature validation' do
9-
it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'batch_escape' expects 1 argument, got none}) }
10-
it { is_expected.to run.with_params('foo', 'bar').and_raise_error(ArgumentError, %r{'batch_escape' expects 1 argument, got 2}) }
9+
it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'stdlib::batch_escape' expects 1 argument, got none}) }
10+
it { is_expected.to run.with_params('foo', 'bar').and_raise_error(ArgumentError, %r{'stdlib::batch_escape' expects 1 argument, got 2}) }
1111
end
1212

1313
describe 'stringification' do

0 commit comments

Comments
 (0)