commander-rb / commander

The complete solution for Ruby command-line executables
MIT License
822 stars 74 forks source link

Usage without ARGV #81

Closed paul-mesnilgrente closed 4 years ago

paul-mesnilgrente commented 4 years ago

Hi,

Is it possible to use this library with a custom Array instead of ARGV? I couldn't find any example of it and I can't figure out the code :/

ggilder commented 4 years ago

Answered in #76 but copying here:

Right now I think the best solution to this would be what Commander's own specs use - take a look at #new_command_runner in spec/spec_helper.rb which includes this line:

Commander::Runner.instance_variable_set :"@singleton", Commander::Runner.new(args)

That allows you to run specs with arbitrary arguments by passing them in to a setup method.

I know that's a little clunky — if you're motivated enough to submit a pull request to provide a better interface, I'd be glad to take a look!

Hope that helps!