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

Using '=' to choose arguments breaks multi-line inputs for type 'string' #138

Open
thmsdmmrtn opened this issue Aug 15, 2023 · 3 comments
Open

Comments

@thmsdmmrtn
Copy link

thmsdmmrtn commented Aug 15, 2023

My code needs to input multi-line strings as a single value.
Entirety of the test code I created to test this issue:

require 'optimist'
opts = Optimist::options do
  opt :foo, 'foobar', short:none, type: :string
end
puts "foo is #{opts[:foo]}"

Command that works:

ruby rubyfile.rb --foo "bar
baz
qux" 

Output of command that works:

foo is bar
baz
qux

Command that produces error:

ruby rubyfile.rb --foo="bar
baz
qux" 

Output of command that produces error:

foo is bar
@agrare
Copy link
Member

agrare commented Aug 16, 2023

cc @kbrock

@nanobowers
Copy link
Collaborator

I was able to fix this by changing this line

-      when /^--(\S+?)=(.*)$/ # long argument with equals
+      when /^--(\S+)=([\s\S]*)/ # long argument with equals

It looks like the . in .* doesn't consider newlines. There's probably a better way... because regex.

@Fryguy
Copy link
Member

Fryguy commented Sep 8, 2023

The original regex is weird anyway. Not sure why it would consume from the = to the end of line?

@Fryguy Fryguy added the bug label Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants