rails / thor

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

Use `#run` to send multiline arguments #770

Open jensljungblad opened 2 years ago

jensljungblad commented 2 years ago

Ran into a problem when converting a Ruby script to Thor.

With Ruby's system method, you can easily pass arguments that contain line-breaks:

body = <<-BODY.strip_heredoc
  String that
  spans multiple
  lines
BODY

# This works:
system("gh", "pr", "create", "--base", "master", "--title", title, "--body", body)

# Using Thor's `run` method does not:
run("gh pr create --base master --title #{title} --body #{body}")

Is there any way to use the run method in this type of scenario?

dorner commented 2 years ago

Not sure - it looks like Thor uses system to run this command: https://github.com/rails/thor/blob/main/lib/thor/actions.rb#L248

Maybe try fiddling with this and see if you can come up with a PR to fix?