Thanks Lee.

If I drop down below the DSL level, to just require SSHKit, is that an easy 
API to work with, and is it documented somewhere? When I search for SSHKit, 
the examples always use the DSL. (If it's not documented, I can drop into 
the DSL code to see how it's using SSHKit easily enough.)

I did notice that I didn't have these scoping issues using the DSL from a 
raw ruby script, so I'll look into a Thor alternative, like you suggested.

As far as choosing Thor, I've written a handful of scripts over the years, 
and have used ARGV, Rake, OptionParser, and Thor for scripts with 
arguments. Of those, Thor seems to give the most robust CLI for the least 
amount of code. The exit code issue would be a nonstarter for many cases, 
but something I'm not too worried about with this script. I also don't like 
using a tool via inheritance like Thor requires. However, there are pros 
and cons to all of the solutions I've tried, so I accept the trade offs.

Rake is a fantastic option, particularly when there are task dependencies. 
I prefer the Thor CLI interface to the one provided by Rake. My mind 
doesn't map well to the task argument square bracket syntax of Rake. Also, 
I prefer flag arguments to positional arguments. I'm not a Rake expert, if 
it provides flag arguments, I'd gladly stand corrected.

On Friday, May 16, 2014 1:19:39 AM UTC-6, Lee Hambley wrote:
>
> >  The problem is that I don't have access to the options variable once I 
> use the SSHKit DSL methods. Has anybody used SSHKit with Thor and been able 
> to access options?
>
> Sorry, it's not possible. As you mentioned it's a scoping problem, 
> everything in SSHKit is instance-evaluated in a the context of the 
> SSHKit::Coordinator, and/or an SSHKit commend instance.
>
> You may have some luck injecting a module into the SSHKit instance, but 
> honestly I wouldn't bother. Capistrano 2 suffered from DSL overload, where 
> faux convenience DSLs replaced equally useful, and more sane pure Ruby, 
> Thor suffers the same way. 
>
> If you want command line integration, use something written with sympathy 
> for the language https://github.com/davetron5000/gli, or Rake.
>
> Might I ask, why are you using Thor. We spent a lot of time evaluating 
> different task DSLs, Thor was eliminated first, as the following returns 
> with exit status 0, which is plainly broken: (this is the smallest problem 
> with Thor.) We chose Rake because it's stable, installed everywhere, and 
> sane.
>
> class Echo < Thor
>   def echo
>     raise RuntimeError
>   end
> end
> > thor echo:echo
>
> Lee Hambley
> --
> http://lee.hambley.name/
> +49 (0) 170 298 5667
>
>
> On 16 May 2014 01:43, Jay Mitchell <[email protected] <javascript:>>wrote:
>
>> I would like to use SSHKit in a Thor script. The problem is that I don't 
>> have access to the options variable once I use the SSHKit DSL methods. Has 
>> anybody used SSHKit with Thor and been able to access options? / Are there 
>> known scoping workarounds with SSHKit?
>>
>>
>> *Code:*
>> # Echo.thor
>> require 'sshkit'
>> require 'sshkit/dsl'
>>
>> class Echo < Thor
>>
>>   HOST = SSHKit::Host.new('some_user@some_box')
>>
>>   desc 'echo', 'Simple example'
>>   method_option :echo, desc: 'Thing to echo.'
>>   def echo
>>     # options variable is available here...
>>     puts "options[:echo]: #{options[:echo]}"
>>     on HOST do
>>       # ...but not here.
>>       execute :echo, options[:echo]
>>     end
>>   end
>> end
>>
>> *Result:*
>>
>> >thor echo:echo --echo Timmy
>> options[:echo]: Timmy
>> D:/Code/link/scripts/phalanx/echo.thor:15:in `block in echo': undefined 
>> local variable or method `options' for #<SSHKit::Backend::Netssh:0x2e4ef20> 
>> (NameError)
>>         from 
>> C:/Ruby200/lib/ruby/gems/2.0.0/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:54:in
>>  
>> `instance_exec'
>>         from 
>> C:/Ruby200/lib/ruby/gems/2.0.0/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:54:in
>>  
>> `run'
>>         from 
>> C:/Ruby200/lib/ruby/gems/2.0.0/gems/sshkit-1.4.0/lib/sshkit/runners/parallel.rb:12:in
>>  
>> `block (2 levels) in execute'
>>
>> Versions:
>>
>>    - Ruby 2.0.0p353 (Windows 8) and 2.1.1p76 (Mac Mavericks with RbEnv)
>>    - Capistrano N/A
>>    - SSHKit 1.4.0
>>    - Thor 0.19.1 (Windows) and 0.14.6 (Mac)
>>    
>> Platform:
>>
>>    - Tried both Windows 8 and Mac Mavericks.
>>    - Target machine is Ubuntu, but shouldn't be a factor.
>>    
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Capistrano" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web, visit 
>> https://groups.google.com/d/msgid/capistrano/f692a609-fc7a-44e5-a58f-91e085b19c3a%40googlegroups.com<https://groups.google.com/d/msgid/capistrano/f692a609-fc7a-44e5-a58f-91e085b19c3a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/capistrano/b1e1e44c-8673-4b55-ac12-be13b8a4965b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to