From 4305443c9c5a83815794d1b1610b128b33d4eb22 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Tue, 4 Apr 2023 22:50:40 +0800 Subject: [PATCH 1/3] commands: explain change in command description splitting A comment here would help the reader to understand the need for this splitting logic, which is not so straightforward. Addresses review comment in https://github.com/Homebrew/brew/pull/15146#discussion_r1157361656. Signed-off-by: Ruoyu Zhong --- Library/Homebrew/commands.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index 8eccbb1c86..fd6a39fcf2 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -203,6 +203,10 @@ module Commands if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path)) if short + # We only consider a dot as a full stop if it is either followed by a + # whitespace or at the end of the description. In this way we can + # prevent cutting off a sentence in the middle due to dots in URLs or + # paths. cmd_parser.description.split(/\.(?>\s|$)/).first else cmd_parser.description From 5c9e073cd57ebb5b7681e8254f101af7f216a807 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Tue, 4 Apr 2023 23:04:13 +0800 Subject: [PATCH 2/3] commands: fix completion descriptions for shell commands too This was missed in #15146. Signed-off-by: Ruoyu Zhong --- Library/Homebrew/commands.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index fd6a39fcf2..8d1f6ddf61 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -219,7 +219,9 @@ module Commands match_data = /^#: (?\w.*+)$/.match(line) if match_data desc = match_data[:desc] - return T.must(desc).split(".").first if short + # The same splitting logic is used here. + # See comment for Ruby commands above. + return T.must(desc).split(/\.(?>\s|$)/).first if short return desc end From c7f3e72e6b48ab0138efd532539a30215d58ba88 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Wed, 5 Apr 2023 15:16:38 +0800 Subject: [PATCH 3/3] commands: make the description splitting pattern a constant --- Library/Homebrew/commands.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index 8d1f6ddf61..6b0de992a4 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -32,6 +32,11 @@ module Commands "lc" => "livecheck", "tc" => "typecheck", }.freeze + # This pattern is used to split descriptions at full stops. We only consider a + # dot as a full stop if it is either followed by a whitespace or at the end of + # the description. In this way we can prevent cutting off a sentence in the + # middle due to dots in URLs or paths. + DESCRIPTION_SPLITTING_PATTERN = /\.(?>\s|$)/.freeze def valid_internal_cmd?(cmd) require?(HOMEBREW_CMD_PATH/cmd) @@ -203,11 +208,7 @@ module Commands if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path)) if short - # We only consider a dot as a full stop if it is either followed by a - # whitespace or at the end of the description. In this way we can - # prevent cutting off a sentence in the middle due to dots in URLs or - # paths. - cmd_parser.description.split(/\.(?>\s|$)/).first + cmd_parser.description.split(DESCRIPTION_SPLITTING_PATTERN).first else cmd_parser.description end @@ -219,9 +220,7 @@ module Commands match_data = /^#: (?\w.*+)$/.match(line) if match_data desc = match_data[:desc] - # The same splitting logic is used here. - # See comment for Ruby commands above. - return T.must(desc).split(/\.(?>\s|$)/).first if short + return T.must(desc).split(DESCRIPTION_SPLITTING_PATTERN).first if short return desc end