-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rb
106 lines (86 loc) · 2.72 KB
/
build.rb
1
2
3
4
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# frozen_string_literal: true
# Explicitly load dotenv at the beginning to ensure environment variables are loaded
begin
require 'dotenv'
Dotenv.load
puts 'Loaded environment from .env file'
rescue LoadError
puts "Warning: dotenv gem not found. Make sure it's installed with 'gem install dotenv'"
end
require_relative 'lib/lottery_factor_tool'
require 'optparse'
# Command-line argument parser
class CommandLineParser
def self.parse(args)
options = initialize_default_options
parser = create_option_parser(options)
parser.parse!(args)
validate_options(options, parser)
options[:database] ||= 'repo.db'
options
end
def self.initialize_default_options
{
time_range: 30,
top_display_count: 6,
force: false,
}
end
def self.create_option_parser(options)
OptionParser.new do |opts|
opts.banner = 'Usage: ruby build.rb [options]'
define_repository_option(opts, options)
define_database_option(opts, options)
define_time_range_option(opts, options)
define_output_option(opts, options)
define_force_option(opts, options)
define_top_display_option(opts, options)
end
end
def self.define_repository_option(opts, options)
opts.on('-r', '--repo REPO',
"The GitHub repository in 'username/repo' format (required)") do |repo|
options[:repo] = repo
end
end
def self.define_database_option(opts, options)
opts.on('-d', '--database FILENAME',
'The SQLite database filename (default: repo.db)') do |filename|
options[:database] = filename
end
end
def self.define_time_range_option(opts, options)
opts.on('-t', '--time-range DAYS', Integer, 'The time range in days (default: 30)') do |days|
options[:time_range] = days
end
end
def self.define_output_option(opts, options)
opts.on('-o', '--output FILENAME',
'The output HTML filename (default: owner-repo-lottery.html)') do |output|
options[:output] = output
end
end
def self.define_force_option(opts, options)
opts.on('-f', '--force', 'Force fetching new data even if recent data exists') do
options[:force] = true
end
end
def self.define_top_display_option(opts, options)
opts.on('--top-display COUNT', Integer,
'Number of top contributors to display individually (default: 6)') do |count|
options[:top_display_count] = count
end
end
def self.validate_options(options, parser)
return unless options[:repo].nil?
puts 'Error: Repository (-r) is required.'
puts parser.help
exit 1
end
end
# Main execution
if __FILE__ == $PROGRAM_NAME
options = CommandLineParser.parse(ARGV)
tool = LotteryFactorTool.new(options)
tool.run
end