sys_cmd 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0abba95b366a7cea45fc88aed525ce584b7210c1
4
- data.tar.gz: 3b46e79596aaf87f60869895ed7b203cb9efbc34
3
+ metadata.gz: 49cb2627e0466057f34aab03f9b30a963bf200b9
4
+ data.tar.gz: ffe64d2249bfc28fa85d9dfab03a017970045047
5
5
  SHA512:
6
- metadata.gz: 27a762ff57a7dc59365329bb486c076da0ac3b3bde8f525bc118dc19853a0eaca23acfc2188ad4d1bca89388aa0a377c99ee59e6b71423f06a509e152c2e80b1
7
- data.tar.gz: eb1a4ac756232ab6488791331bf72bc69b74181107b3ac4eba0e95e49b47752eb73284df264ac52a77bdf3340fcb87721acb4b2e9841a9799f46b925d9384003
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
- @stdin_data = command.stdin_data
204
+ @input = command.stdin_data
205
205
  else
206
206
  @command = command
207
207
  @shell = Shell.new(options)
208
- @stdin_data = options[:stdin_data]
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] || @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
- command
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
@@ -1,3 +1,3 @@
1
1
  module SysCmd
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys_cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Goizueta