commands: make the description splitting pattern a constant
This commit is contained in:
parent
5c9e073cd5
commit
c7f3e72e6b
@ -32,6 +32,11 @@ module Commands
|
|||||||
"lc" => "livecheck",
|
"lc" => "livecheck",
|
||||||
"tc" => "typecheck",
|
"tc" => "typecheck",
|
||||||
}.freeze
|
}.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)
|
def valid_internal_cmd?(cmd)
|
||||||
require?(HOMEBREW_CMD_PATH/cmd)
|
require?(HOMEBREW_CMD_PATH/cmd)
|
||||||
@ -203,11 +208,7 @@ module Commands
|
|||||||
|
|
||||||
if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path))
|
if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path))
|
||||||
if short
|
if short
|
||||||
# We only consider a dot as a full stop if it is either followed by a
|
cmd_parser.description.split(DESCRIPTION_SPLITTING_PATTERN).first
|
||||||
# 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
|
else
|
||||||
cmd_parser.description
|
cmd_parser.description
|
||||||
end
|
end
|
||||||
@ -219,9 +220,7 @@ module Commands
|
|||||||
match_data = /^#: (?<desc>\w.*+)$/.match(line)
|
match_data = /^#: (?<desc>\w.*+)$/.match(line)
|
||||||
if match_data
|
if match_data
|
||||||
desc = match_data[:desc]
|
desc = match_data[:desc]
|
||||||
# The same splitting logic is used here.
|
return T.must(desc).split(DESCRIPTION_SPLITTING_PATTERN).first if short
|
||||||
# See comment for Ruby commands above.
|
|
||||||
return T.must(desc).split(/\.(?>\s|$)/).first if short
|
|
||||||
|
|
||||||
return desc
|
return desc
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user