delano / rye

Safe, parallel access to Unix shells from Ruby
http://delano.github.com/rye
MIT License
234 stars 32 forks source link

Rye::Cmd.add_command breaks for programs with "-" in them (method must match program name) #60

Open jphackworth opened 9 years ago

jphackworth commented 9 years ago

I wanted to add ssh-keygen to the list of whitelisted commands.

Rye::Cmd.add_command :ssh_keygen, "/usr/bin/ssh-keygen"

But received the following error:

irb(main):004:0> Rye::Cmd.add_command :ssh_keygen, "/usr/bin/ssh-keygen"                                               
=> #<Proc:0x00000000a70d00@/var/lib/gems/2.0.0/gems/rye-0.9.12/lib/rye/cmd.rb:354 (lambda)>
irb(main):005:0> Rye.shell :ssh_keygen, "--help"                                                                       
Rye::CommandNotFound: ssh_keygen
        from /var/lib/gems/2.0.0/gems/rye-0.9.12/lib/rye.rb:193:in `prepare_command'
        from /var/lib/gems/2.0.0/gems/rye-0.9.12/lib/rye.rb:236:in `shell'
        from (irb):5
        from /usr/bin/irb2.0:12:in `<main>'

I finally realised that the method has to match the program name, which isn't helpful when the program name contains a dash ("-"), like ssh-keygen does.

What I've had to do is:

$ sudo ln -s /usr/bin/ssh-keygen /usr/bin/sshkeygen
...
$ irb2.0
irb(main):001:0> require 'rye'
=> true
irb(main):002:0> Rye::Cmd.add_command :sshkeygen, "/usr/bin/sshkeygen"
=> #<Proc:0x00000000f47d38@/var/lib/gems/2.0.0/gems/rye-0.9.12/lib/rye/cmd.rb:354 (lambda)>
irb(main):003:0> Rye.shell :sshkeygen, "--blah"
=> [, unknown option -- -; usage: sshkeygen [options]; Option

(Which now works)

delano commented 9 years ago

Ya, I can see how that would be annoying.

If you send a pull request, I'll bring it in.