Skip to content
This repository
Browse code

Allow for omitted and secret arguments on _.system

  • Loading branch information...
commit 6236dd662dfe2214da1717824e60cd6a49c4dde1 1 parent 05d2918
Sam Ruby authored May 17, 2012
4  README.md
Source Rendered
@@ -310,7 +310,9 @@ are sent individually and as they are produced.
310 310
 `_.system` will run an aritrary command.  Lines of output are sent across the
311 311
 websocket as they are received as JSON encoded hashes with two values: `type`
312 312
 is one of `stdin`, `stdout` or `stderr`; and `line` which contains the line
313  
-itself.
  313
+itself.  If the command is an array, the elements of the array will be escaped
  314
+as Shell command arguments.  Nested arrays may be used to hide elements from
  315
+the echoing of the command to stdin.  Nil values are omitted.
314 316
 
315 317
 Options to `_websocket` are provided as a hash:  
316 318
 
14  lib/wunderbar/builder.rb
@@ -179,16 +179,22 @@ def pdf?
179 179
 
180 180
     # execute a system command, echoing stdin, stdout, and stderr
181 181
     def system(command, opts={})
182  
-      if command.respond_to? :join
  182
+      if command.respond_to? :flatten
  183
+        flat = command.flatten
  184
+        secret = command - flat
183 185
         begin
184 186
           # if available, use escape as it does prettier quoting
185 187
           require 'escape'
186  
-          command = Escape.shell_command(command).untaint
  188
+          echo = Escape.shell_command(command.compact - secret)
  189
+          command = Escape.shell_command(flat.compact).untaint
187 190
         rescue LoadError
188 191
           # std-lib function that gets the job done
189 192
           require 'shellwords'
190  
-          command = Shellwords.join(command).untaint
  193
+          echo = Shellwords.join(command.compact - secret)
  194
+          command = Shellwords.join(flat.compact).untaint
191 195
         end
  196
+      else
  197
+        echo = command
192 198
       end
193 199
 
194 200
       require 'open3'
@@ -198,7 +204,7 @@ def system(command, opts={})
198 204
       stdout = output_class[:stdout] || '_stdout'
199 205
       stderr = output_class[:stderr] || '_stderr'
200 206
 
201  
-      @_builder.tag! tag, command, :class=>stdin unless opts[:echo] == false
  207
+      @_builder.tag! tag, echo, :class=>stdin unless opts[:echo] == false
202 208
 
203 209
       require 'thread'
204 210
       semaphore = Mutex.new
2  lib/wunderbar/version.rb
@@ -2,7 +2,7 @@ module Wunderbar
2 2
   module VERSION #:nodoc:
3 3
     MAJOR = 0
4 4
     MINOR = 16
5  
-    TINY  = 1
  5
+    TINY  = 2
6 6
 
7 7
     STRING = [MAJOR, MINOR, TINY].join('.')
8 8
   end

0 notes on commit 6236dd6

Please sign in to comment.
Something went wrong with that request. Please try again.