commander-rb / commander

The complete solution for Ruby command-line executables
MIT License
823 stars 74 forks source link

Provide heredoc helper #25

Closed sts closed 8 years ago

sts commented 8 years ago

It would be great if commander would provide a helper to unintend a String created with a heredoc. Some seem to solve this "elegantly" via a core_ext to String:

class String
  def unindent
    gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
  end
end

command :test do
  message = <<-EOM.unindent
  This is a test message! The left indent
  gets stripped automatically!
  EOM
end
ggilder commented 8 years ago

This is already provided in ActiveSupport, I'd probably suggest just using that: http://edgeguides.rubyonrails.org/active_support_core_extensions.html#strip-heredoc