Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow for omitted and secret arguments on _.system

  • Loading branch information...
commit 6236dd662dfe2214da1717824e60cd6a49c4dde1 1 parent 05d2918
@rubys authored
Showing with 14 additions and 6 deletions.
  1. +3 −1 README.md
  2. +10 −4 lib/wunderbar/builder.rb
  3. +1 −1  lib/wunderbar/version.rb
View
4 README.md
@@ -310,7 +310,9 @@ are sent individually and as they are produced.
`_.system` will run an aritrary command. Lines of output are sent across the
websocket as they are received as JSON encoded hashes with two values: `type`
is one of `stdin`, `stdout` or `stderr`; and `line` which contains the line
-itself.
+itself. If the command is an array, the elements of the array will be escaped
+as Shell command arguments. Nested arrays may be used to hide elements from
+the echoing of the command to stdin. Nil values are omitted.
Options to `_websocket` are provided as a hash:
View
14 lib/wunderbar/builder.rb
@@ -179,16 +179,22 @@ def pdf?
# execute a system command, echoing stdin, stdout, and stderr
def system(command, opts={})
- if command.respond_to? :join
+ if command.respond_to? :flatten
+ flat = command.flatten
+ secret = command - flat
begin
# if available, use escape as it does prettier quoting
require 'escape'
- command = Escape.shell_command(command).untaint
+ echo = Escape.shell_command(command.compact - secret)
+ command = Escape.shell_command(flat.compact).untaint
rescue LoadError
# std-lib function that gets the job done
require 'shellwords'
- command = Shellwords.join(command).untaint
+ echo = Shellwords.join(command.compact - secret)
+ command = Shellwords.join(flat.compact).untaint
end
+ else
+ echo = command
end
require 'open3'
@@ -198,7 +204,7 @@ def system(command, opts={})
stdout = output_class[:stdout] || '_stdout'
stderr = output_class[:stderr] || '_stderr'
- @_builder.tag! tag, command, :class=>stdin unless opts[:echo] == false
+ @_builder.tag! tag, echo, :class=>stdin unless opts[:echo] == false
require 'thread'
semaphore = Mutex.new
View
2  lib/wunderbar/version.rb
@@ -2,7 +2,7 @@ module Wunderbar
module VERSION #:nodoc:
MAJOR = 0
MINOR = 16
- TINY = 1
+ TINY = 2
STRING = [MAJOR, MINOR, TINY].join('.')
end
Please sign in to comment.
Something went wrong with that request. Please try again.