-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaoc
executable file
·56 lines (50 loc) · 1.77 KB
/
aoc
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
#!/usr/bin/env ruby
require 'httparty'
require 'dotenv/load'
require 'thor'
require 'benchmark'
lib_files = File.join(File.dirname(__FILE__), 'lib', '*.rb')
src_files = File.join(File.dirname(__FILE__), 'src', '**', '*.rb')
Dir[lib_files].each { |file| require file }
Dir[src_files].each { |file| require file }
# The CLI application
class Aoc < Thor
desc 'download YEAR DAY', 'downloads an input file'
method_option :download, aliases: '-d'
def download(year, day)
PuzzleInput.download(year, day)
end
desc 'bootstrap YEAR DAY', 'prepares a sample project for a given day:
downloads the input, creates a sample source and spec file'
method_option :bootstrap, aliases: '-b'
def bootstrap(year, day)
::PuzzleInput.download(year, day)
Template.create_templates(year, day)
puts "https://adventofcode.com/#{year}/day/#{day}"
end
desc 'run YEAR DAY', 'executes a given day/year'
method_option :run_day, aliases: '-r'
def run_day(year, day)
puzzle = PuzzleSource.create_puzzle(year, day)
input = PuzzleInput.load(year, day)
PuzzleSource.run_part('part 1') { puzzle.part1(input) }
puts
PuzzleSource.run_part('part 2') { puzzle.part2(input) }
end
desc 'part1 YEAR DAY', 'executes the part1 for a given day/year'
method_option :part1
def part1(year, day)
puzzle = PuzzleSource.create_puzzle(year, day)
input = PuzzleInput.load(year, day)
PuzzleSource.run_part('part 1') { puzzle.part1(input) }
end
desc 'part2 YEAR DAY', 'executes the part2 for a given day/year'
method_option :part2
def part2(year, day)
puzzle = PuzzleSource.create_puzzle(year, day)
input = PuzzleInput.load(year, day)
PuzzleSource.run_part('part 2') { puzzle.part2(input) }
end
end
Dotenv.require_keys('AOC_COOKIE', 'AOC_INPUT_DIRECTORY')
Aoc.start