Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in_directory directory, to execute commands within a particular path #35

Merged
merged 2 commits into from
Jul 19, 2012

Conversation

jmibanez
Copy link
Contributor

This is similar to Fabric's with cd(path) idiom.

This is similar to Fabric's with cd(path) idiom.
@rstacruz
Copy link
Member

Hey JM!

As I mentioned in our chat, this has the minor caveat of these two commands having potentially different results:

# 1:
in_directory('path') {
  queue "a"
  queue "b"
}

# 2:
in_directory('path') { queue "a" }
in_directory('path') { queue "b" }

...because it consolidates all queued commands into one command. One way to fix this would be:

isolated_commands.each do |command|
  queue "(cd #{path} && #{command})"
end

@jmibanez
Copy link
Contributor Author

Heh. Apparently Github noticed my forced update. Go figure.

@jmibanez
Copy link
Contributor Author

@rstacruz Hmm... won't the second case above still have the same behavior even with that change?

In the existing commit, we'd get

   (cd path && (a)) &&
   (cd path && (b))

for the second case, while for the change, we'd still get (as I understand it):

   (cd path && (a)) &&
   (cd path && (b))

For the first case, we'd get for the existing:

   (cd path && (a && b))

and with the change

   ((cd path && a) && (cd path && b))

Is my understanding correct?

@rstacruz
Copy link
Member

...yes, but if you're using it outside a deploy script, commands are joined with simply semicolons ; in effect. In a deploy script, they're joined using &&. (This is essentially what the deploy do .. end helper does: capture queued commands, join them with '&&', then wrap them inside a boilerplate deploy script.)

Hence, this:

# 0:
task :tail do
   queue "ls"
  queue "tail errors.log"
end


# 1:
task :tail do
  in_directory '/var/www' do
    queue "ls"
    queue "tail errors.log"
  end
end

# 2:
task :tail do
  in_directory('/var/www') { queue "ls" }
  in_directory('/var/www') { queue "tail errors.log" }
end

will become:

# 0:
ls ; tail errors.log

# 1:
cd /var/www && (ls && tail errors.log)

#2:
cd /var/www && (ls)
cd /var/www && (tail errors.log)

@jmibanez
Copy link
Contributor Author

Ah. That's the missing part. Queuing up another commit.

This allows us to handle the case where in_directory is called outside
of deploy. See:

 * mina-deploy#35 (comment)
 * mina-deploy#35 (comment)
rstacruz added a commit that referenced this pull request Jul 19, 2012
Add in_directory directory, to execute commands within a particular path
@rstacruz rstacruz merged commit f6a37b8 into mina-deploy:master Jul 19, 2012
@rstacruz
Copy link
Member

There ya go. You can use gem 'mina', github: 'nadarei/mina' until the next version's released. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants