rails / thor

Thor is a toolkit for building powerful command-line interfaces.
http://whatisthor.com/
MIT License
5.11k stars 552 forks source link

Multiple word parameter like "eric pugh" becomes ["eric","pugh"] with 1.1.0 #753

Closed epugh closed 3 years ago

epugh commented 3 years ago

Parameters that are made up of multiple words, wrapped in double quotes, seem to be treated as seperate parameters.

So for this definition:

  option :administrator, type: :boolean, aliases: '-a'
  def create email, name, password

  end

Is throwing an error because the parameter for name is "Eric Pugh" but Thor thinks I am giving four parameters:

➜  quepid git:(master) bin/docker r thor user:create -a foo@example.com 'Eric Pugh' password
Creating quepid_app_run ... done
ERROR: "thor create" was called with arguments ["foo@example.com", "Eric", "Pugh", "password"]
epugh commented 3 years ago

I looked briefly at the specs, and it doesn't appear there is a test for "Eric Pugh" type pattern.

epugh commented 3 years ago

I was previosly using 0.19.4 and then upgraded to 1.1.0 as part of migrating to Rails 5.

epugh commented 3 years ago

OMG... So, turns out not to be a thor issue.... I am passing this thor command into a Docker environment. bin/docker r is a ruby script that takes the params in, and runs the script. By escaping the \" it works. I have some sort of escaping issue in my bin/docker r command.

bin/docker r thor user:create foo@example.com \"Eric Pugh\" mysuperstrongpassword 
epugh commented 3 years ago

For the next person, here is my use of shellwords to deal with escaping: https://github.com/o19s/quepid/pull/340/commits/badc6f1d3487f2e323778cbd932acd819c601660