Skip to content

Commit

Permalink
Change to adhere to exec arguments types.
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed May 7, 2016
1 parent e25aac1 commit 2e3c514
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/tty/command/cmd.rb
Expand Up @@ -38,7 +38,7 @@ def initialize(env_or_cmd, *args)
else
if command.respond_to?(:to_ary)
@command = sanitize(command[0])
args.unshift(command[1..-1])
args.unshift(*command[1..-1])
else
@command = sanitize(command)
end
Expand Down
11 changes: 9 additions & 2 deletions spec/unit/cmd_spec.rb
Expand Up @@ -32,14 +32,21 @@
expect(cmd.to_command).to eq(%{if [[ $? -eq 0]]; then; echo \"Bash it!\"; fi})
end

it "accepts command with arguments" do
it "accepts command as [cmdname, arg1, ...]" do
cmd = TTY::Command::Cmd.new(:echo, '-n', 'hello')
expect(cmd.command).to eq('echo')
expect(cmd.argv).to eq(['-n', 'hello'])
expect(cmd.to_command).to eq('echo -n hello')
end

it "accepts command with environment" do
it "accepts command as [[cmdname, argv0], arg1, ...]" do
cmd = TTY::Command::Cmd.new([:echo, '-n'], 'hello')
expect(cmd.command).to eq('echo')
expect(cmd.argv).to eq(['-n', 'hello'])
expect(cmd.to_command).to eq('echo -n hello')
end

it "accepts command with environment as [cmdname, arg1, ..., opts]" do
cmd = TTY::Command::Cmd.new(:echo, 'hello', env: {foo: 'bar'})
expect(cmd.to_command).to eq(%{( export FOO=\"bar\" ; echo hello )})
end
Expand Down

0 comments on commit 2e3c514

Please sign in to comment.