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

ARGV is empty inside action block #103

Closed
crawlik opened this issue Aug 16, 2012 · 2 comments
Closed

ARGV is empty inside action block #103

crawlik opened this issue Aug 16, 2012 · 2 comments

Comments

@crawlik
Copy link

crawlik commented Aug 16, 2012

Looks like latest gli 2.0.0 regressed by making ARGV empty after command line parsing

command :test do |c|
  p ARGV => ["-g", "v1,v2", "test"]
  c.action do |global_options,options,args|
    p ARGV => []
  end
end

Noticed that ARGV is cloned in parse_options but clone is never used after that. I assume args_clone should be used as an input by parsers so ARGV value doesn't change.

 def parse_options(args) # :nodoc:
      args_clone = args.clone
@davetron5000
Copy link
Owner

Hmm, I hadn't considered that anyone would be using ARGV directly; args,
passed to the action block should be used instead, but if it's no effort
to preserve ARGV, I might as well.

As a stopgap, you could do

exit run(ARGV.clone)

in your bin file.


Buy My Book: http://www.awesomecommandlineapps.com
My Blog: http://www.naildrivin5.com/blog
Fork me on Github: http://davetron5000.github.com

On Thu, Aug 16, 2012 at 1:36 PM, Alex Vinnik [email protected]:

Looks like latest gli 2.0.0 regressed by making ARGV empty after command
line parsing

command :test do |c|
p ARGV => ["-g", "v1,v2", "test"]
c.action do |global_options,options,args|
p ARGV => []
endend

Noticed that ARGV is cloned in parse_options but clone is never used after
that. I assume args_clone should be used as an input by parsers so ARGV
value doesn't change.

def parse_options(args) # :nodoc:
args_clone = args.clone


Reply to this email directly or view it on GitHubhttps://github.com//issues/103.

@crawlik
Copy link
Author

crawlik commented Aug 16, 2012

I have some code that relies on ARGV in order to get the original command line as it passed by shell for spawning parallel processes with it minus some global options. Plus I think people would agree that global ARGV should not change under any circumstances because it effectively changes starting state of the process.

exit run(ARGV.clone) # this workaround works just fine

Thanks

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

No branches or pull requests

2 participants