Fix multi-word argument handling in foreman run.
This commit is contained in:
1 parent
4a13122082
commit
3ea5de42aa
5 files changed
+26
-15
No files matched your search
+3
-7
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
#/ Usage: foreman-runner [-d <dir>] <command>
|
#/ Usage: foreman-runner [-d <dir>] <command> [<args>...]
|
||||||
#/
|
#/
|
||||||
#/ Run a command with exec, optionally changing directory first
|
#/ Run a command with exec, optionally changing directory first
|
||||||
|
|
||||||
@@ -27,10 +27,6 @@ done
|
|||||||
|
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
command=$1
|
[ -z "$1" ] && usage
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
exec "$@"
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec $1
|
|
||||||
+3
-2
@@ -2,6 +2,7 @@ require "foreman"
|
|||||||
require "foreman/helpers"
|
require "foreman/helpers"
|
||||||
require "foreman/engine"
|
require "foreman/engine"
|
||||||
require "foreman/export"
|
require "foreman/export"
|
||||||
|
require "shellwords"
|
||||||
require "thor"
|
require "thor"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
@@ -59,12 +60,12 @@ class Foreman::CLI < Thor
|
|||||||
puts "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
|
puts "valid procfile detected (#{engine.procfile.process_names.join(', ')})"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "run COMMAND", "Run a command using your application's environment"
|
desc "run COMMAND [ARGS...]", "Run a command using your application's environment"
|
||||||
|
|
||||||
def run(*args)
|
def run(*args)
|
||||||
engine.apply_environment!
|
engine.apply_environment!
|
||||||
begin
|
begin
|
||||||
exec args.join(" ")
|
exec args.shelljoin
|
||||||
rescue Errno::EACCES
|
rescue Errno::EACCES
|
||||||
error "not executable: #{args.first}"
|
error "not executable: #{args.first}"
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ private
|
|||||||
$stdout.reopen writer
|
$stdout.reopen writer
|
||||||
$stderr.reopen writer
|
$stderr.reopen writer
|
||||||
reader.close
|
reader.close
|
||||||
exec Foreman.runner, "-d", basedir, command
|
exec Foreman.runner, "-d", basedir, *command.shellsplit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
[ reader, pid ]
|
[ reader, pid ]
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ describe "Foreman::CLI", :fakefs do
|
|||||||
before { write_procfile }
|
before { write_procfile }
|
||||||
|
|
||||||
describe "and a command" do
|
describe "and a command" do
|
||||||
let(:command) { ["ls", "-l"] }
|
let(:command) { ["ls", "-l", "foo bar"] }
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
stub(subject).exec
|
stub(subject).exec
|
||||||
@@ -160,8 +160,8 @@ describe "Foreman::CLI", :fakefs do
|
|||||||
ENV["FOO"].should be_nil
|
ENV["FOO"].should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should runute the command as a string" do
|
it "should exec the argument list as a shell command" do
|
||||||
mock(subject).exec(command.join(" "))
|
mock(subject).exec(command.shelljoin)
|
||||||
subject.run *command
|
subject.run *command
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -121,11 +121,25 @@ describe Foreman::Process do
|
|||||||
output.should include('777')
|
output.should include('777')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should handle arguments' do
|
it 'should handle multi-word arguments (old test)' do
|
||||||
pending
|
# TODO: This test used to be marked pending; it now passes,
|
||||||
|
# but is very slow. The next test is a fast replacement.
|
||||||
run %{ sh -c "trap '' TERM; sleep 10" }
|
run %{ sh -c "trap '' TERM; sleep 10" }
|
||||||
subject.should be_alive
|
subject.should be_alive
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should handle multi-word arguments' do
|
||||||
|
# We have to be a little clever here since Foreman will always
|
||||||
|
# print a status message that includes the command.
|
||||||
|
run %{ sh -c 'echo abcdef | tr a-c x | tr d-f y' }
|
||||||
|
output.should include('xxxyyy')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not clobber "$x"-subexpressions' do
|
||||||
|
pending 'this conflicts with the variable interpolation hack'
|
||||||
|
run %{ sh -c 'echo \$abcdef | tr \$ %' }
|
||||||
|
output.should include('%abcdef')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user