Skip to content

Commit 3e14bd2

Browse files
committed
Namespace function shell_escape()
1 parent 7f5f58d commit 3e14bd2

File tree

3 files changed

+36
-22
lines changed

3 files changed

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

3-
# @summary
4-
# Escapes a string so that it can be safely used in a Bourne 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-
#
9-
# This function behaves the same as ruby's Shellwords.shellescape() function.
3+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
4+
5+
# @summary DEPRECATED. Use the namespaced function [`stdlib::shell_escape`](#stdlibshell_escape) instead.
106
Puppet::Functions.create_function(:shell_escape) do
11-
# @param string
12-
# The string to escape
13-
#
14-
# @return
15-
# An escaped string that can be safely used in a Bourne shell command line.
16-
dispatch :shell_escape do
17-
param 'Any', :string
7+
dispatch :deprecation_gen do
8+
repeated_param 'Any', :args
189
end
19-
20-
def shell_escape(string)
21-
require 'shellwords'
22-
23-
Shellwords.shellescape(string.to_s)
10+
def deprecation_gen(*args)
11+
call_function('deprecation', 'shell_escape', 'This function is deprecated, please use stdlib::shell_escape instead.')
12+
call_function('stdlib::shell_escape', *args)
2413
end
2514
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
# @summary
4+
# Escapes a string so that it can be safely used in a Bourne 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+
#
9+
# This function behaves the same as ruby's Shellwords.shellescape() function.
10+
Puppet::Functions.create_function(:'stdlib::shell_escape') do
11+
# @param string
12+
# The string to escape
13+
#
14+
# @return
15+
# An escaped string that can be safely used in a Bourne shell command line.
16+
dispatch :shell_escape do
17+
param 'Any', :string
18+
end
19+
20+
def shell_escape(string)
21+
require 'shellwords'
22+
23+
Shellwords.shellescape(string.to_s)
24+
end
25+
end

spec/functions/shell_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 'shell_escape' do
5+
describe 'stdlib::shell_escape' do
66
it { is_expected.not_to be_nil }
77

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

1313
describe 'stringification' do

0 commit comments

Comments
 (0)