From c02e03a1798c383863ee87b7a14a66a122db6679 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sat, 30 Jul 2022 00:36:31 +0100 Subject: [PATCH] dev-cmd/contributions: Use methods to get arguments - I got these with hash syntax because I couldn't figure out Sorbet, but there's `args.rbi` to add the CLI args methods to. Nice! - In doing this I realised that `--repositories` is required again, we no longer infer `--repositories=all` from no `--repositories` passed as we did in a previous version of this. --- Library/Homebrew/cli/args.rbi | 9 ++++++++ Library/Homebrew/dev-cmd/contributions.rb | 25 ++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/cli/args.rbi b/Library/Homebrew/cli/args.rbi index 32b1cd8e6e..e0aaee87f1 100644 --- a/Library/Homebrew/cli/args.rbi +++ b/Library/Homebrew/cli/args.rbi @@ -300,6 +300,15 @@ module Homebrew sig { returns(T.nilable(String)) } def screen_saverdir; end + sig { returns(T::Array[String])} + def repositories; end + + sig { returns(T.nilable(String)) } + def from; end + + sig { returns(T.nilable(String)) } + def to; end + sig { returns(T.nilable(T::Array[String])) } def groups; end diff --git a/Library/Homebrew/dev-cmd/contributions.rb b/Library/Homebrew/dev-cmd/contributions.rb index 3e68f32d3d..0911b3d361 100755 --- a/Library/Homebrew/dev-cmd/contributions.rb +++ b/Library/Homebrew/dev-cmd/contributions.rb @@ -40,12 +40,13 @@ module Homebrew sig { returns(NilClass) } def contributions args = contributions_args.parse + return ofail "Please specify `--repositories` to search, or `--repositories=all`." unless args[:repositories].empty? commits = 0 coauthorships = 0 - all_repos = args[:repositories].first == "all" - repos = all_repos ? SUPPORTED_REPOS : args[:repositories] + all_repos = args.repositories.first == "all" + repos = all_repos ? SUPPORTED_REPOS : args.repositories repos.each do |repo| if SUPPORTED_REPOS.exclude?(repo) return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}." @@ -66,12 +67,12 @@ module Homebrew sentence = "Person #{args.named.first} directly authored #{commits} commits " \ "and co-authored #{coauthorships} commits " \ "across #{all_repos ? "all Homebrew repos" : repos.to_sentence}" - sentence += if args[:from] && args[:to] - " between #{args[:from]} and #{args[:to]}" - elsif args[:from] - " after #{args[:from]}" - elsif args[:to] - " before #{args[:to]}" + sentence += if args.from && args.to + " between #{args.from} and #{args.to}" + elsif args.from + " after #{args.from}" + elsif args.to + " before #{args.to}" else " in all time" end @@ -90,8 +91,8 @@ module Homebrew sig { params(repo_path: Pathname, args: Homebrew::CLI::Args).returns(Integer) } def git_log_author_cmd(repo_path, args) cmd = ["git", "-C", repo_path, "log", "--oneline", "--author=#{args.named.first}"] - cmd << "--before=#{args[:to]}" if args[:to] - cmd << "--after=#{args[:from]}" if args[:from] + cmd << "--before=#{args.to}" if args.to + cmd << "--after=#{args.from}" if args.from Utils.safe_popen_read(*cmd).lines.count end @@ -100,8 +101,8 @@ module Homebrew def git_log_coauthor_cmd(repo_path, args) cmd = ["git", "-C", repo_path, "log", "--oneline"] cmd << "--format='%(trailers:key=Co-authored-by:)'" - cmd << "--before=#{args[:to]}" if args[:to] - cmd << "--after=#{args[:from]}" if args[:from] + cmd << "--before=#{args.to}" if args.to + cmd << "--after=#{args.from}" if args.from Utils.safe_popen_read(*cmd).lines.count { |l| l.include?(args.named.first) } end