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

Allow arguments to be hardcoded strings with - and = characters #14

Open
AlexB52 opened this issue Feb 20, 2024 · 0 comments
Open

Allow arguments to be hardcoded strings with - and = characters #14

AlexB52 opened this issue Feb 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@AlexB52
Copy link

AlexB52 commented Feb 20, 2024

Describe the problem

I'm looking to define options with arguments that can take a command to run in a process. Something like this

my-cli 'rake TEST=<test>'

arguments using = character aren't parsed as arguments and get set to nil.

Steps to reproduce the problem

require "bundler/inline"

gemfile do
  source "https://rubygems.org"

  gem "tty-option"
  gem "minitest"
end

require "tty-option"
require "minitest/autorun"

class MyOptions
  include TTY::Option

  argument :command
end

class TestHardcodedString < Minitest::Test
  def test_special_characters_as_arguments
    options = MyOptions.new
    options.parse(["rake TEST=<test>"])

    # ASSERTION FAILS
    assert_equal "rake TEST=<test>", options.params[:command]
  end

  def test_reference_without_equal_sign
    options = MyOptions.new
    options.parse(["rake test <test>"])

    # ASSERTION PASSES
    assert_equal "rake test <test>", options.params[:command]
  end
end

Result

# Running:

.F

Finished in 0.001068s, 1872.6592 runs/s, 1872.6592 assertions/s.

  1) Failure:
TestHardcodedString#test_special_characters_as_arguments [tty-option-hardcoded-string-for-command.rb:25]:
Expected: "rake TEST=<test>"
  Actual: nil

2 runs, 2 assertions, 1 failures, 0 errors, 0 skips

Actual behaviour
options.params[:command] => nil

Expected behaviour
options.params[:command] => 'rake TEST=<test>'

Context

It currently happens because the regex for arguments prevents the use of = and - characters
https://github.com/piotrmurach/tty-option/blob/master/lib/tty/option/parser/param_types.rb#L8

While the pull request #13 is not the right fix it does show tests that illustrate why the regex does not parse and = and - characters

Describe your environment

  • OS version: mac 14.2.1
  • Ruby version: 3.1
  • TTY::Option version: 0.3.0
@AlexB52 AlexB52 added the bug Something isn't working label Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant