-
Notifications
You must be signed in to change notification settings - Fork 613
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
Why does Rake not allow exclamation points (bang: !) in the description? #347
Comments
I found the problem here: https://github.com/ruby/rake/blob/master/lib/rake/task.rb#L338-L344 |
Yes, not to be rude, but I already mentioned the pull request, which points to that: https://github.com/ruby/rake/pull/134/files But I don't know why this was designed this way. However, this did remind me that there is a workaround: rake -D This shows the full description. Here's my re-design proposal:
Here's example code. It might not be the fastest way, but just a proposal. MAX_LEN = 50
def first_sentence(str)
str = str.split("\n").first.rstrip
len = str.length
if len > MAX_LEN
# First, try to remove trailing words.
words = str.split(/(\s+)/) # Grouping () keeps the spaces.
index = words.length
# Do ">= 1" not 0, else empty string "" because chops off all words.
while len > MAX_LEN && (index -= 1) >= 1
len -= words[index].length
end
if len <= MAX_LEN
# It worked, so glue the correct number of words/spaces back together.
str = words[0...index].join
else
# It didn't work, so just slice it.
str = str[0...MAX_LEN]
end
# Strip away any spacing leftover between words.
str = str.rstrip
# Just some styling (optional).
str = "#{str}..."
end
str
end
#=> hello
puts first_sentence("hello\nworld")
#=> hello world!
puts first_sentence("hello world!")
#=> hello world this is a long sentence that will get...
puts first_sentence("hello world this is a long sentence that will get cut off")
#=> hellowordlthisisalongwordthathasnospacesidontknoww...
puts first_sentence("hellowordlthisisalongwordthathasnospacesidontknowwhywhatwasithinking") |
In 2016, a pull request pull/134 was made to not allow exclamation points, but why was this?
The following won't work:
rake -T
produces:Is there a workaround for this? A way to escape them?
Thanks.
System
The text was updated successfully, but these errors were encountered: