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

Why does Rake not allow exclamation points (bang: !) in the description? #347

Open
esotericpig opened this issue Apr 17, 2020 · 2 comments

Comments

@esotericpig
Copy link

In 2016, a pull request pull/134 was made to not allow exclamation points, but why was this?

The following won't work:

desc 'Benchmark ?: vs !!'
task :benchmark do |task|
end

desc 'Overwrite files; dangerous!'
task :overwrite do |task|
end

rake -T produces:

rake benchmark        # Benchmark ?: vs
rake overwrite        # Overwrite files; dangerous

Is there a workaround for this? A way to escape them?

Thanks.

System

  • ruby 2.7.0p0 (2019-12-25 revision 647ee6f091)
  • rake (13.0.1)
@diasjorge
Copy link

I found the problem here: https://github.com/ruby/rake/blob/master/lib/rake/task.rb#L338-L344
In my case, the task name has "!" like "pause!" which is a valid task name but in the description I can't use it.

@esotericpig
Copy link
Author

I found the problem here: https://github.com/ruby/rake/blob/master/lib/rake/task.rb#L338-L344 In my case, the task name has "!" like "pause!" which is a valid task name but in the description I can't use it.

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:

  1. Change first_sentence to split only on newlines and then strip (the method, not you).
  2. If the length is longer than 50 or something (because I assume this was implemented due to the line being longer than the width of the terminal), then either split the current way or just remove trailing words until fits.

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants