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

Rake task の desc に長文入れると rake --tasks 時に省略されるのはまぁわかるが、 ! を入れるとそこも消される #100

Closed
kachick opened this issue Jun 4, 2021 · 2 comments

Comments

@kachick
Copy link
Owner

kachick commented Jun 4, 2021

タイトルが全てなのだが、これは仕様なのだろうか

@kachick kachick added bug Something isn't working question Further information is requested labels Jun 4, 2021
@kachick
Copy link
Owner Author

kachick commented Jun 4, 2021

https://github.com/ruby/rake/blob/11973e8d31f29aee2e40d874206c9240956f86ed/lib/rake/dsl_definition.rb#L155-L167

    # Describes the next rake task.  Duplicate descriptions are discarded.
    # Descriptions are shown with <code>rake -T</code> (up to the first
    # sentence) and <code>rake -D</code> (the entire description).
    #
    # Example:
    #   desc "Run the Unit Tests"
    #   task test: [:build]
    #     # ... run tests
    #   end
    #
    def desc(description) # :doc:
      Rake.application.last_description = description
    end
❯ bundle exec rake -D release
rake release[remote]
    Create tag v0.1.5 and build and push ruby-ulid-0.1.5.gem to rubygems.org
    To prevent publishing in RubyGems use `gem_push=no rake release`

~/repos/ruby-ulid main
❯ bundle exec rake --tasks release
rake release[remote]  # Create tag v0.1.5 and build and push ruby-ulid-0.1.5.gem to rubygems.org

~/repos/ruby-ulid main
❯ bundle exec rake -D view
rake view_packaging_files
    To prevent #69 anymore!


~/repos/ruby-ulid main
❯ bundle exec rake --tasks view
rake view_packaging_files  # To prevent #69 anymore

なるほど、up to the first sentence であり、全文表示したければ -D をつけろということか。

    # Display the tasks and comments.
    def display_tasks_and_comments # :nodoc:
      displayable_tasks = tasks.select { |t|
        (options.show_all_tasks || t.comment) &&
          t.name =~ options.show_task_pattern
      }
      case options.show_tasks
      when :tasks
        width = displayable_tasks.map { |t| t.name_with_args.length }.max || 10
        if truncate_output?
          max_column = terminal_width - name.size - width - 7
        else
          max_column = nil
        end

        displayable_tasks.each do |t|
          printf("#{name} %-#{width}s  # %s\n",
            t.name_with_args,
            max_column ? truncate(t.comment, max_column) : t.comment)
        end
      when :describe
        displayable_tasks.each do |t|
          puts "#{name} #{t.name_with_args}"
          comment = t.full_comment || ""
          comment.split("\n").each do |line|
            puts "    #{line}"
          end
          puts
        end
      when :lines
        displayable_tasks.each do |t|
          t.locations.each do |loc|
            printf "#{name} %-30s %s\n", t.name_with_args, loc
          end
        end
      else
        fail "Unknown show task mode: '#{options.show_tasks}'"
      end
    end
    # Full collection of comments. Multiple comments are separated by
    # newlines.
    def full_comment
      transform_comments("\n")
    end

    # First line (or sentence) of all comments. Multiple comments are
    # separated by a "/".
    def comment
      transform_comments(" / ") { |c| first_sentence(c) }
    end

    # Get the first sentence in a string. The sentence is terminated
    # by the first period, exclamation mark, or the end of the line.
    # Decimal points do not count as periods.
    def first_sentence(string)
      string.split(/(?<=\w)(\.|!)[ \t]|(\.$|!)|\n/).first
    end
    private :first_sentence

なるほどー、若干釈然としないが、 ! で区切られてしまうのは仕様のようだ。了解いたしました。

ruby/rake#134
ruby/rake@355d1ac

明示的にここで入ったパッチなのか。

ruby/rake#347

で、やっぱ疑問が上がっているみたいだ。ふむー、変更が入った意図としては ruby/rake#106 を直すためだったみたいなのだけど、若干やり方が違うか?しかし、これはまぁ人間の言葉が曖昧というところに落ち着きそうな気がするので、「ちゃんとやれ」と言われたらハイコスト感はあるな・・・

@kachick kachick closed this as completed Jun 4, 2021
@kachick kachick added ruby tips and removed bug Something isn't working question Further information is requested labels Jun 4, 2021
@kachick kachick changed the title Rake task の desc に長文入れると rake --tasks 時に省略されるのはまぁわかるが、文字区切り的なのを入れるとそこも消される Rake task の desc に長文入れると rake --tasks 時に省略されるのはまぁわかるが、 ! を入れるとそこも消される Jun 4, 2021
@kachick
Copy link
Owner Author

kachick commented Jun 5, 2021

ほぼ https://stackoverflow.com/questions/6479013/i-need-a-regex-to-match-first-sentence-of-the-string のパクリだが、

string.slice(/\A.*?[.!?](?=\s[A-Z]|\s?$)(?!.*\))/).slice(/\A(.*?)[\.]?$/, 1)

こんな感じの正規表現だとだいたい大丈夫そうである。が、「怖い」
特に String#slice は nullable だから、仮にこういった正規表現を使うにしてももうちょい丁寧さが必要になりそうではある。
あと rake は ruby 2.2 とかをまだサポート対象にしているようで、 delete_prefix とか余裕で使えないのも地味に面倒。
古い ruby への対応は、テスト環境作るのも面倒なんだよな・・・まぁ、 docker があるというのは「それはそう」

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

No branches or pull requests

1 participant