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

Fix handling of double dashes (--) in crystal eval command #15474

Closed
wants to merge 2 commits into from

Conversation

kojix2
Copy link
Contributor

@kojix2 kojix2 commented Feb 14, 2025

This pull request has two fixes to the behavior of the eval command.

  1. The eval command will now allow you to pass command line arguments to a program using a single double hyphen.
  2. When more than one argument is given, they will be joined with “;” instead of “ ”

1 double dash issue

crystal eval 'puts ARGV' -- meow neigh

Expected behavior

["meow", "neigh"]

Actual behavior

syntax error in eval:1
Error: unexpected token: "meow"

Workaround

By using two double dashes, you can pass arguments to the program as expected.

crystal eval 'puts ARGV' -- -- meow neigh

The reason for this behavior is that the OptionParser stops at “--” by default, and removes “--”. Therefore, you need to use unknown_args to distinguish between arguments that were before “--” and arguments that were after “--”.

In the forum, I received a comment that this is probably not the intended behavior.

2 join arguments with “;” instead of “”.

crystal eval "puts 0" "puts 1"

Expected behavior (for kojix2)

0
1

Actual behavior

syntax error in eval:1
Error: unexpected token: "puts"

Personally, I feel that this behavior is preferable.
In many programming languages, only one argument is accepted.

python3 -c "print(0)" -c "print(1)"
0

In Ruby, multiple arguments are accepted.

ruby -e "puts 0" -e "puts 1"
0
1

However, if the opinion that the current behavior should be maintained for compatibility or other reasons is stronger, I can fully understand that.


Also, there are no tests for this pull request. If tests are necessary, please let me know where and what kind of tests should be written.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:cli labels Feb 14, 2025
@straight-shoota
Copy link
Member

Could you please split off the argument join into a separate PR? The changes are related in the code they affect, but they're different issues and should be considered independently.
Thanks.

@kojix2
Copy link
Contributor Author

kojix2 commented Feb 14, 2025

Thanks. I did it.

@straight-shoota
Copy link
Member

FTR, you could've just reverted the second commit in this PR. But creating a new one is fine as well. 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants