5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/end_of_life/options.rb', line 5
def self.from(argv)
options = {product: Product.find("ruby"), max_eol_date: Date.today, skip_archived: true}
OptionParser.new do |parser|
options[:parser] = parser
parser.banner = "Usage: end_of_life [options]"
product_names = EndOfLife.products.map(&:name)
parser.on("-p NAME", "--product NAME", /#{product_names.join("|")}/i, "Sets the product to scan for (default: ruby). Supported products are: #{product_names.join(", ")}.") do |name|
options[:product] = Product.find(name)
end
parser.on("--exclude=NAME,NAME2", Array, "Exclude repositories containing a certain word in its name. You can specify up to five words.") do |excludes|
options[:excludes] = excludes.first(5)
end
parser.on("--public-only", "Searches only public repositories") do
options[:visibility] = :public
end
parser.on("--private-only", "Searches only private repositories") do
options[:visibility] = :private
end
parser.on("--repo=USER/REPO", "--repository=USER/REPO", "Searches a specific repository") do |repository|
options[:repository] = repository
end
parser.on("--org=ORG,ORG2...", "--organization=ORG,ORG2", Array, "Searches within specific organizations") do |organizations|
options[:organizations] = organizations
end
parser.on("-u NAME", "--user=NAME", "Sets the user used on the repository search") do |user|
options[:user] = user
end
parser.on("--max-eol-days-away NUMBER", "Sets the maximum number of days away a version can be from EOL. It defaults to 0.") do |days|
options[:max_eol_date] = Date.today + days.to_i.abs
end
parser.on("--include-archived", "Includes archived repositories on the search") do
options[:skip_archived] = false
end
parser.on("-v", "--version", "Displays end_of_life version") do
options[:command] = :version
end
parser.on("-h", "--help", "Displays this help") do
options[:command] = :help
end
end.parse!(argv)
options
rescue OptionParser::ParseError => e
{command: :print_error, error: e}
end
|