dev-cmd/contributions: Use a named arg for required repositories
- This is apparently "more in-keeping with how we do required arguments (never requiring flags)" across Homebrew. - New usage: `brew contributions me@issyl0.co.uk all`, `brew contributions me@issyl0.co.uk brew,core`
This commit is contained in:
parent
c02e03a179
commit
ae73f28d0f
@ -17,9 +17,13 @@ module Homebrew
|
|||||||
sig { returns(CLI::Parser) }
|
sig { returns(CLI::Parser) }
|
||||||
def contributions_args
|
def contributions_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
usage_banner "`contributions` [<email>]"
|
usage_banner "`contributions` <email> <repo1,repo2|all>"
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Contributions to Homebrew repos for a user.
|
Contributions to Homebrew repos for a user.
|
||||||
|
|
||||||
|
The second argument is a comma-separated list of repos to search.
|
||||||
|
Specify <all> to search all repositories.
|
||||||
|
Supported repositories: #{SUPPORTED_REPOS.join(", ")}.
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
flag "--from=",
|
flag "--from=",
|
||||||
@ -28,25 +32,20 @@ module Homebrew
|
|||||||
flag "--to=",
|
flag "--to=",
|
||||||
description: "Date (ISO-8601 format) to stop searching contributions."
|
description: "Date (ISO-8601 format) to stop searching contributions."
|
||||||
|
|
||||||
comma_array "--repositories=",
|
named_args [:email, :repositories], min: 2, max: 2
|
||||||
description: "The Homebrew repositories to search for contributions in. " \
|
|
||||||
"Comma separated. Pass `all` to search all repositories. " \
|
|
||||||
"Supported repositories: #{SUPPORTED_REPOS.join(", ")}."
|
|
||||||
|
|
||||||
named_args :email, number: 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(NilClass) }
|
sig { returns(NilClass) }
|
||||||
def contributions
|
def contributions
|
||||||
args = contributions_args.parse
|
args = contributions_args.parse
|
||||||
return ofail "Please specify `--repositories` to search, or `--repositories=all`." unless args[:repositories].empty?
|
|
||||||
|
|
||||||
commits = 0
|
commits = 0
|
||||||
coauthorships = 0
|
coauthorships = 0
|
||||||
|
|
||||||
all_repos = args.repositories.first == "all"
|
all_repos = args.named.last == "all"
|
||||||
repos = all_repos ? SUPPORTED_REPOS : args.repositories
|
repos = all_repos ? SUPPORTED_REPOS : args.named.last.split(",")
|
||||||
|
|
||||||
repos.each do |repo|
|
repos.each do |repo|
|
||||||
if SUPPORTED_REPOS.exclude?(repo)
|
if SUPPORTED_REPOS.exclude?(repo)
|
||||||
return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
|
return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user