rush> home.ping 'www.yahoo.co.jp'
rush> home.rm '-f', home['*.bak']
rush> home.svn :status
rush> home.e 'ps ax | grep ruby'
I know this syntax is not useful, but it is a good temporary solution.
--
Chihiro Ito <source...@gmail.com>
Yes, it's called "bash". (This exists only in the git repo, not the
current gem, 0.1.)
So you can do:
Rush::Box.new('www.example.com').bash('/etc/init.d/apache2 restart')
Ping won't work unless you specify a limited duration with -c - the
bash command above is equivalent to backtics in that it doesn't return
until the entire thing is done. This is actually a design choice; I
want rush to be stateless, and to deal in terms of complete request
and return objects. Rather than the stream of characters approach
used by the standard unix shell.
At some point if we find ourselves wanting to do long-running
commands, or things that produce ongoing output, we can think about
how to build a framework for that which still works in discrete
chunks. In the case of ping, those chunks would probably be the
individual icmp results (normally 1 per line in the ping shell
command).
But if we were to implement ping, I think I'd rather just have it
always do exactly one packet. Then if you wanted ongoing output in
your shell, you can do:
loop { puts box.ping('example.com').inspect; sleep 1 }
Actually, you can do this today like so:
loop { puts box.bash('ping example.com -c 1'); sleep 1 }
This will work seamlessly both locally and remotely.
Adam
Interesting. This isn't the direction I want to go with rush in
general, but as a short-term solution for making it useable for
everyday work, it seems like a good choice. This makes me think I
should probably come up with some sort of plugin architecture to make
it easier to share stuff like this, although copy-and-paste into
commands.rb or env.rb isn't too bad.
I do think there are probably a series of commands that we might want
to pass through straight to the shell along with the arguments.
Rather than method_missing them, I'd want to define them explicitly.
Off the top of my head, some of these are: rake, svn, git, ping (with
the implied -c 1), curl, and mongrel_rails.
It gets a lot more interesting when you customize it a little bit
though. For example, it wouldn't be hard to write an svn method which
works like this:
dir['**/*.rb'].svn(:add)
Adam
Yes, I agree. I hope to discard the method_missing too ;)
> This makes me think I should probably come up with some sort of plugin architecture
Great! It's just what I want. If you plan to replace shell-commands
with ruby methods, plugin architecture is necessary to cover various
needs. Additionally, it makes me happy that the plugin architecture
supports adding a new tab-completion.
> dir['**/*.rb'].svn(:add)
It seems more 'rushy' way :) but it is not appropriate for some
commands (make for example). So, I decided to implement both of them.
If you append ! suffix to the method name, it works like you
mentioned.
dir['**/*.rb'].svn!(:add)
furthermore, I have added the following features.
* Redirect stdout
if you append ? suffix, you can get the stdout data through the return value.
rush> home.echo?('foo').inspect
"foo\n"
* Redirect with block
If you pass a block, it will be executed with stdout data per line.
rush> home.echo("foo\nbar") do |line| p line end
"foo"
"bar"
* Ignoring preceding under score
To select an explicit defined method or method_missing, preceding
under score of the method name is ignored.
rush> home._ls '-a'
. .. .bash_history .bash_logout .rush bin
* Type command-line option easily
If you pass a symbol, first @ or @@ will be replaced with - or --
respectively. Only in the latter case, camelcase will be converted to
hyphen delimited.
rush> home._ls :@a, :@@fileType # equal to home._ls '-a', '--file-type'
./ ../ .bash_history .bash_logout .rush/ bin/
You might think this feature is useless but single quote and double
quote are hard to type on japanese keyboard since they are mapped to
shift-7 and shift-2.