sys_cmd 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sys_cmd.rb +24 -6
- data/lib/sys_cmd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49cb2627e0466057f34aab03f9b30a963bf200b9
|
4
|
+
data.tar.gz: ffe64d2249bfc28fa85d9dfab03a017970045047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9789c5e5c29b8e56ab83a855fc3d04924e11dc2d854cf70f28ad41cb418ba2d734d9fbff5bbac3dafc2d204b0a1663228805d02901c25335b1b2cb6e22d60e69
|
7
|
+
data.tar.gz: be19e8ca84e0b031d3972d73f05dfad0804c4328c7233aae1b74cf16cbd7912d0eb0af4f26161903bcc60eb104f7aba64a4e44966dca6860e24a54804b7ec05c
|
data/lib/sys_cmd.rb
CHANGED
@@ -201,11 +201,11 @@ module SysCmd
|
|
201
201
|
if command.respond_to?(:shell)
|
202
202
|
@command = command.command
|
203
203
|
@shell = command.shell
|
204
|
-
@
|
204
|
+
@input = command.stdin_data
|
205
205
|
else
|
206
206
|
@command = command
|
207
207
|
@shell = Shell.new(options)
|
208
|
-
@
|
208
|
+
@input = options[:stdin_data]
|
209
209
|
end
|
210
210
|
@output = nil
|
211
211
|
@status = nil
|
@@ -213,7 +213,7 @@ module SysCmd
|
|
213
213
|
@error = nil
|
214
214
|
end
|
215
215
|
|
216
|
-
attr_reader :command, :output, :status, :error_output, :error
|
216
|
+
attr_reader :command, :output, :status, :error_output, :error, :input
|
217
217
|
|
218
218
|
# Execute the command.
|
219
219
|
#
|
@@ -264,7 +264,7 @@ module SysCmd
|
|
264
264
|
else
|
265
265
|
command = [@command]
|
266
266
|
end
|
267
|
-
stdin_data = options[:stdin_data] || @
|
267
|
+
stdin_data = options[:stdin_data] || @input
|
268
268
|
if stdin_data
|
269
269
|
command << { stdin_data: stdin_data }
|
270
270
|
end
|
@@ -310,8 +310,12 @@ module SysCmd
|
|
310
310
|
!error? && @status.success?
|
311
311
|
end
|
312
312
|
|
313
|
-
def to_s
|
314
|
-
|
313
|
+
def to_s(options = {})
|
314
|
+
if @input && options[:with_input]
|
315
|
+
"#{command}#{@shell.here_doc(@input)}"
|
316
|
+
else
|
317
|
+
command
|
318
|
+
end
|
315
319
|
end
|
316
320
|
|
317
321
|
end
|
@@ -406,6 +410,17 @@ module SysCmd
|
|
406
410
|
end
|
407
411
|
end
|
408
412
|
|
413
|
+
def self.here_doc(text, options = {})
|
414
|
+
case os_type(options)
|
415
|
+
when :windows
|
416
|
+
# only valid for PowerShell
|
417
|
+
" @'\n#{text}\n'@\n"
|
418
|
+
else
|
419
|
+
delimiter = options[:delimiter] || 'EOF'
|
420
|
+
" << #{delimiter}\n#{text}\n#{delimiter}\n"
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
409
424
|
class Shell
|
410
425
|
|
411
426
|
def initialize(options = {})
|
@@ -454,6 +469,9 @@ module SysCmd
|
|
454
469
|
applicable
|
455
470
|
end
|
456
471
|
|
472
|
+
def here_doc(data, options = {})
|
473
|
+
SysCmd.here_doc(data, options.merge(os: @type))
|
474
|
+
end
|
457
475
|
end
|
458
476
|
|
459
477
|
# Execute a block of code only on some systems
|
data/lib/sys_cmd/version.rb
CHANGED