[ruby-core:118856] [Ruby master Feature#6648] Provide a standard API for retrieving all command-line flags passed to Ruby

Issue #6648 has been updated by Dan0042 (Daniel DeLorme). byroot (Jean Boussier) wrote in #note-36:
As for the API, my two cents is that it would make the most sense in `Process`. e.g. `Process.argv`, such as:
I don't mind using "Process", but the "argv" name is really ambiguous. For the command `ruby --yjit script.rb --arg` we'd have: main(char **argv) => ["ruby", "--yjit", "script.rb", "--arg"] Process.argv => ["--yjit", "script.rb", "--arg"] ARGV => ["--arg"] Process.argv0 => "script.rb" (not element 0 of any of the 3 arrays above) The name "argv" already has 3 different conflicting meanings, so adding a 4th one is a bit too much imho. byroot (Jean Boussier) wrote in #note-38:
Needs a bit of polish (e.g. doc and spec), but that's essentially what I think we should do: https://github.com/ruby/ruby/pull/11370
This works great for re-executing the current process, but not for the original problem described in OP to "launch subprocess Ruby instances with the same settings". It's definitely a bit more complicated to extract just ["--yjit"] from the example above, and requires to change `proc_options` in ruby.c ...I'll try to see if I can whip up something. ---------------------------------------- Feature #6648: Provide a standard API for retrieving all command-line flags passed to Ruby https://bugs.ruby-lang.org/issues/6648#change-109424 * Author: headius (Charles Nutter) * Status: Assigned * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- Currently there are no standard mechanisms to get the flags passed to the currently running Ruby implementation. The available mechanisms are not ideal: * Scanning globals and hoping they have not been tweaked to new settings * Using external wrappers to launch Ruby * ??? Inability to get the full set of command-line flags, including flags passed to the VM itself (and probably VM-specific) makes it impossible to launch subprocess Ruby instances with the same settings. A real world example of this is "((%bundle exec%))" when called with a command line that sets various flags, a la ((%jruby -Xsome.vm.setting --1.9 -S bundle exec%)). None of these flags can propagate to the subprocess, so odd behaviors result. The only option is to put the flags into an env var (((|JRUBY_OPTS|)) or ((|RUBYOPT|))) but this breaks the flow of calling a simple command line. JRuby provides mechanisms to get all its command line options, but they require calling Java APIs from Ruby's API set. Rubinius provides its own API for accessing comand-line options, but I do not know if it includes VM-level flags as well as standard Ruby flags. I know there is a (({RubyVM})) namespace in the 2.0 line. If that namespace is intended to be general-purpose for VM-level features, it would be a good host for this API. Something like... ``` class << RubyVM def vm_args; end # returns array of command line args *not* passed to the target script def script; end # returns the script being executed...though this overlaps with $0 def script_args; end # returns args passed to the script...though this overlaps with ARGV, but that is perhaps warranted since ARGV can be modified (i.e. you probably want the original args) end ``` -- https://bugs.ruby-lang.org/
participants (1)
-
Dan0042 (Daniel DeLorme)