aoc_cli 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +11 -7
- data/lib/aoc_cli.rb +0 -3
- data/lib/aoc_cli/database.rb +4 -0
- data/lib/aoc_cli/errors.rb +89 -0
- data/lib/aoc_cli/files.rb +1 -0
- data/lib/aoc_cli/interface.rb +8 -83
- data/lib/aoc_cli/paths.rb +6 -1
- data/lib/aoc_cli/solve.rb +4 -1
- data/lib/aoc_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bee1d6efc3fabf9d4f218f642989d57a3623de2726834c59ec71d4349958725f
|
4
|
+
data.tar.gz: bd8b87f6998e73b607f79e669c051071432ee8e5553171ad78976f8684f2748f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9af542a18643e3a8c642ef1ec70284e76b93b0aef184827f1510e9e02479649724e34fc219a3e193f17de01b07831a5361f4a6c40f30fea1df3de27ff0e11a84
|
7
|
+
data.tar.gz: a7eb8b816eb983a7a346d80ea81e2c711c3a1cc856b57541552de52c4a467170a0d18eed01d990ab5c6400a6c1774357c7f67a8bfe9040f7548be5b39c1cbab6
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
- Add user-agent
|
5
5
|
|
6
6
|
## 20-02-21
|
7
|
-
###0.2.0
|
7
|
+
### 0.2.0
|
8
8
|
- Add calendar tables
|
9
9
|
- Star progress now based off this database rather than meta json
|
10
10
|
- Add cat of calendar from any directory
|
@@ -18,3 +18,8 @@
|
|
18
18
|
- Turn on/off leaderboard stats in calendar file
|
19
19
|
- Git integration
|
20
20
|
- General refactor
|
21
|
+
|
22
|
+
## 22-02-21
|
23
|
+
### 0.2.1
|
24
|
+
- Add day_dir_prefix option
|
25
|
+
- Add functionality to prevent duplicate incorrect attempts
|
data/README.md
CHANGED
@@ -74,7 +74,7 @@ aoc -k $your_key
|
|
74
74
|
|
75
75
|
```
|
76
76
|
|
77
|
-
-
|
77
|
+
- aoc-cli stores this key under the alias 'main' if no custom alias is specified
|
78
78
|
- To store the key under a different alias use the `-u` or `--user` flags followed by the desired alias.
|
79
79
|
- Session keys are stored in the aoc config file located at `~/.config/aoc-cli/aoc.rc`.
|
80
80
|
|
@@ -94,7 +94,7 @@ cookie=>account2=>session=123abc
|
|
94
94
|
|
95
95
|
aoc-cli allows for multiple keys to be stored within the config file.
|
96
96
|
|
97
|
-
To see which alias is currently
|
97
|
+
To see which alias is currently default run `aoc -U` or `aoc --default`
|
98
98
|
|
99
99
|
- You can update the default alias by running
|
100
100
|
|
@@ -139,7 +139,6 @@ There are two types of directories
|
|
139
139
|
2. Day subdirectories
|
140
140
|
- These contain the puzzles, your input and your code
|
141
141
|
|
142
|
-
|
143
142
|
## Initialising the Year
|
144
143
|
|
145
144
|
To begin using the cli you must first initialise the year directory.
|
@@ -187,6 +186,7 @@ This command performs the following actions
|
|
187
186
|
|
188
187
|
All puzzles and inputs are cached in aoc-cli on a per-user basis. This means that if you have previously initialised this day under the same alias before, your puzzle and input will be transferred from the cache locally rather than downloading from the aoc server.
|
189
188
|
|
189
|
+
NB: if you wish to add a prefix to your day subdirectory names, you can add `day_dir_prefix=>$prefix` to your config file
|
190
190
|
|
191
191
|
## Solving Puzzles
|
192
192
|
|
@@ -196,16 +196,19 @@ From the day subdirectory you can attempt to solve puzzles by running the comman
|
|
196
196
|
aoc -s $answer
|
197
197
|
```
|
198
198
|
|
199
|
-
You will then receive one of
|
199
|
+
You will then receive one of four responses
|
200
200
|
|
201
201
|
1. The answer is correct
|
202
202
|
2. The answer is not correct
|
203
|
-
3. You have
|
203
|
+
3. You have already tried this incorrect answer
|
204
|
+
4. You have time to wait before submitting an answer
|
204
205
|
|
205
206
|
If your answer is correct, aoc-cli will automatically update the puzzle instructions and your calendar file. Additionally aoc-cli will calculate how long and how many attempts it took to solve the puzzle (see the Tables section)
|
206
207
|
|
207
208
|
Incorrect attempts will be logged along with any hint as to whether your answer was too high or too low.
|
208
209
|
|
210
|
+
Trying to answer with the same incorrect answer for the second time will throw an error
|
211
|
+
|
209
212
|
If you have sent multiple incorrect attempts AoC will ask you to wait before trying again - be patient!
|
210
213
|
|
211
214
|
|
@@ -299,7 +302,7 @@ These settings can be configured in your config file (see configuration)
|
|
299
302
|
|
300
303
|
## Vim Integration
|
301
304
|
|
302
|
-
|
305
|
+
If you use vim you may wish to set a keybinding to automatically run your code and submit it for validation once you have solved a puzzle.
|
303
306
|
|
304
307
|
Using Ruby as an example, you could add the following line to your .vimrc:
|
305
308
|
|
@@ -311,7 +314,7 @@ Executing leader + ac would then run your program and send the answer to the ser
|
|
311
314
|
|
312
315
|
## Configuration
|
313
316
|
|
314
|
-
aoc-cli can be configured using
|
317
|
+
aoc-cli can be configured using the config file at `~/.config/aoc-cli/aoc.rc`
|
315
318
|
|
316
319
|
To generate an example configuration file you can run `aoc -G` or `aoc --gen-config`. (Note this will throw an error if `~/.config/aoc-cli/aoc.rc` already exists)
|
317
320
|
|
@@ -330,6 +333,7 @@ Lines can be commented out of the rc file by prefixing with `//`
|
|
330
333
|
| Flag | Type | Description | Default |
|
331
334
|
|-------------------|--------|---------------------------------------------------------------|---------|
|
332
335
|
| calendar_file | bool | Write calendar as a markdown file | true |
|
336
|
+
| day_dir_prefix | string | Add prefix to day subdirectory nam | nil |
|
333
337
|
| default | string | Default alias | main |
|
334
338
|
| ignore_md_files | bool | Auto add md files (calendar and puzzles) to gitignore | true |
|
335
339
|
| ignore_meta_files | bool | Auto add meta files to gitignore | true |
|
data/lib/aoc_cli.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'colorize'
|
2
|
-
require 'sqlite3'
|
3
2
|
|
4
3
|
require_relative 'aoc_cli/errors'
|
5
4
|
require_relative 'aoc_cli/interface'
|
@@ -17,6 +16,4 @@ require_relative 'aoc_cli/tables'
|
|
17
16
|
module AocCli
|
18
17
|
Metafile = AocCli::Files::Metafile
|
19
18
|
Prefs = AocCli::Files::Config::Prefs
|
20
|
-
Validate = AocCli::Interface::Validate
|
21
|
-
E = AocCli::Errors
|
22
19
|
end
|
data/lib/aoc_cli/database.rb
CHANGED
@@ -52,6 +52,10 @@ module AocCli
|
|
52
52
|
val:data << 0 << parse_hint(low:low, high:high))
|
53
53
|
self
|
54
54
|
end
|
55
|
+
def duplicate?(ans:)
|
56
|
+
db.select(t:"attempts",
|
57
|
+
where:where.merge({answer:ans})).count > 0
|
58
|
+
end
|
55
59
|
def parse_hint(low:, high:)
|
56
60
|
[ low ? 1 : 0, high ? 1 : 0 ]
|
57
61
|
end
|
data/lib/aoc_cli/errors.rb
CHANGED
@@ -182,5 +182,94 @@ module AocCli
|
|
182
182
|
error
|
183
183
|
end
|
184
184
|
end
|
185
|
+
class AtmptDup < StandardError
|
186
|
+
attr_reader :answer
|
187
|
+
def initialize(answer)
|
188
|
+
@answer = answer
|
189
|
+
end
|
190
|
+
def message
|
191
|
+
<<~error
|
192
|
+
#{ERROR}: You have already tried #{answer.red}
|
193
|
+
To see previous attempts run #{"aoc -a".yellow}
|
194
|
+
error
|
195
|
+
end
|
196
|
+
end
|
185
197
|
end
|
198
|
+
class Validate
|
199
|
+
E = Errors
|
200
|
+
def self.cmd(cmd)
|
201
|
+
raise E::CmdNil if cmd.nil?
|
202
|
+
cmd
|
203
|
+
end
|
204
|
+
def self.user(user)
|
205
|
+
raise E::UserNil if user.nil?
|
206
|
+
raise E::UserInv.new(user) unless user_in_config?(user)
|
207
|
+
user
|
208
|
+
end
|
209
|
+
def self.set_user(user)
|
210
|
+
raise E::UserNil if user.nil?
|
211
|
+
raise E::UserDup.new(user) if user_in_config?(user)
|
212
|
+
user
|
213
|
+
end
|
214
|
+
def self.year(year)
|
215
|
+
raise E::YearNil if year.nil?
|
216
|
+
raise E::YearInv.new(year) if year.to_i < 2015 ||
|
217
|
+
year.to_i > 2020
|
218
|
+
year
|
219
|
+
end
|
220
|
+
def self.day(day)
|
221
|
+
raise E::DayNil if day.nil? || day == 0
|
222
|
+
raise E::DayInv.new(day) if day.to_i < 1 ||
|
223
|
+
day.to_i > 25
|
224
|
+
day
|
225
|
+
end
|
226
|
+
def self.part(part)
|
227
|
+
raise E::PartNil if part.nil?
|
228
|
+
raise E::PuzzComp if part.to_i == 3
|
229
|
+
raise E::PartInv if part.to_i < 1 || part.to_i > 2
|
230
|
+
part
|
231
|
+
end
|
232
|
+
def self.set_key(key)
|
233
|
+
raise E::KeyNil if key.nil?
|
234
|
+
raise E::KeyDup.new(key) if Files::Config::Tools
|
235
|
+
.is_set?(val:"#{key}(\b|$)")
|
236
|
+
raise E::KeyInv unless valid_key?(key)
|
237
|
+
key
|
238
|
+
end
|
239
|
+
def self.key(key)
|
240
|
+
raise E::KeyNil if key.nil?
|
241
|
+
raise E::KeyInv unless valid_key?(key)
|
242
|
+
key
|
243
|
+
end
|
244
|
+
def self.ans(attempt:, ans:)
|
245
|
+
raise E::AnsNil if ans.nil?
|
246
|
+
raise E::AtmptDup.new(ans) if Database::Attempt
|
247
|
+
.new(attempt:attempt).duplicate?(ans:ans)
|
248
|
+
ans
|
249
|
+
end
|
250
|
+
def self.day_dir(day)
|
251
|
+
raise E::DayExist.new(day) if Dir.exist?(day)
|
252
|
+
day
|
253
|
+
end
|
254
|
+
def self.init(dir)
|
255
|
+
raise E::NotInit unless File.exist?("#{dir}/.meta")
|
256
|
+
dir
|
257
|
+
end
|
258
|
+
def self.not_init(dir:, year:)
|
259
|
+
raise E::AlrInit if File.exist?("#{dir}/.meta") &&
|
260
|
+
Metafile.get(:year) != year.to_s
|
261
|
+
dir
|
262
|
+
end
|
263
|
+
def self.no_config
|
264
|
+
raise E::ConfigExist if File.exist?(Paths::Config.path)
|
265
|
+
Paths::Config.path
|
266
|
+
end
|
267
|
+
private
|
268
|
+
def self.valid_key?(key)
|
269
|
+
/session=(?:[a-f0-9]){96}/.match?(key)
|
270
|
+
end
|
271
|
+
def self.user_in_config?(user)
|
272
|
+
Files::Config::Tools.is_set?(key:"cookie=>#{user}")
|
273
|
+
end
|
274
|
+
end
|
186
275
|
end
|
data/lib/aoc_cli/files.rb
CHANGED
data/lib/aoc_cli/interface.rb
CHANGED
@@ -3,14 +3,13 @@ module AocCli
|
|
3
3
|
class Query
|
4
4
|
def initialize
|
5
5
|
ARGV.size > 0 ?
|
6
|
-
run(
|
6
|
+
run(args:Args.new.parse) : Help.print
|
7
7
|
rescue StandardError => e
|
8
8
|
abort e.message
|
9
9
|
end
|
10
|
-
def run(
|
11
|
-
cmd = Commands.const_get(Validate.cmd(
|
12
|
-
.new(
|
13
|
-
.exec
|
10
|
+
def run(args:)
|
11
|
+
cmd = Commands.const_get(Validate.cmd(args.cmd))
|
12
|
+
.new(args.args).exec
|
14
13
|
cmd.respond if cmd.class
|
15
14
|
.instance_methods.include?(:respond)
|
16
15
|
end
|
@@ -20,12 +19,12 @@ module AocCli
|
|
20
19
|
require_relative "help.rb"
|
21
20
|
end
|
22
21
|
end
|
23
|
-
class
|
22
|
+
class Args
|
24
23
|
attr_reader :cmd, :args
|
25
24
|
def initialize
|
26
25
|
@args = {}
|
27
26
|
end
|
28
|
-
def
|
27
|
+
def parse
|
29
28
|
while ARGV.size > 0
|
30
29
|
case ARGV.shift
|
31
30
|
when "-a", "--attempts"
|
@@ -57,7 +56,7 @@ module AocCli
|
|
57
56
|
@cmd = :OpenReddit
|
58
57
|
when "-s", "--solve"
|
59
58
|
@cmd = :DaySolve
|
60
|
-
args[:ans] =
|
59
|
+
args[:ans] = ARGV.shift
|
61
60
|
when "-S", "--stats"
|
62
61
|
@cmd = :StatsTable
|
63
62
|
when "-u", "--user"
|
@@ -70,85 +69,11 @@ module AocCli
|
|
70
69
|
args[:year] = Validate.year(ARGV.shift.to_i)
|
71
70
|
when "-Y", "--year"
|
72
71
|
args[:year] = ARGV.shift.to_i
|
73
|
-
else raise
|
72
|
+
else raise Errors::FlagInv
|
74
73
|
end
|
75
74
|
end
|
76
75
|
self
|
77
76
|
end
|
78
77
|
end
|
79
|
-
class Validate
|
80
|
-
def self.cmd(cmd)
|
81
|
-
raise E::CmdNil if cmd.nil?
|
82
|
-
cmd
|
83
|
-
end
|
84
|
-
def self.user(user)
|
85
|
-
raise E::UserNil if user.nil?
|
86
|
-
raise E::UserInv.new(user) unless user_in_config?(user)
|
87
|
-
user
|
88
|
-
end
|
89
|
-
def self.set_user(user)
|
90
|
-
raise E::UserNil if user.nil?
|
91
|
-
raise E::UserDup.new(user) if user_in_config?(user)
|
92
|
-
user
|
93
|
-
end
|
94
|
-
def self.year(year)
|
95
|
-
raise E::YearNil if year.nil?
|
96
|
-
raise E::YearInv.new(year) if year.to_i < 2015 ||
|
97
|
-
year.to_i > 2020
|
98
|
-
year
|
99
|
-
end
|
100
|
-
def self.day(day)
|
101
|
-
raise E::DayNil if day.nil? || day == 0
|
102
|
-
raise E::DayInv.new(day) if day.to_i < 1 ||
|
103
|
-
day.to_i > 25
|
104
|
-
day
|
105
|
-
end
|
106
|
-
def self.part(part)
|
107
|
-
raise E::PartNil if part.nil?
|
108
|
-
raise E::PuzzComp if part.to_i == 3
|
109
|
-
raise E::PartInv if part.to_i < 1 || part.to_i > 2
|
110
|
-
part
|
111
|
-
end
|
112
|
-
def self.set_key(key)
|
113
|
-
raise E::KeyNil if key.nil?
|
114
|
-
raise E::KeyDup.new(key) if Files::Config::Tools
|
115
|
-
.is_set?(val:"#{key}(\b|$)")
|
116
|
-
raise E::KeyInv unless valid_key?(key)
|
117
|
-
key
|
118
|
-
end
|
119
|
-
def self.key(key)
|
120
|
-
raise E::KeyNil if key.nil?
|
121
|
-
raise E::KeyInv unless valid_key?(key)
|
122
|
-
key
|
123
|
-
end
|
124
|
-
def self.ans(ans)
|
125
|
-
raise E::AnsNil if ans.nil?
|
126
|
-
ans
|
127
|
-
end
|
128
|
-
def self.day_dir(day)
|
129
|
-
raise E::DayExist.new(day) if Dir.exist?(day)
|
130
|
-
day
|
131
|
-
end
|
132
|
-
def self.init(dir)
|
133
|
-
raise E::NotInit unless File.exist?("#{dir}/.meta")
|
134
|
-
dir
|
135
|
-
end
|
136
|
-
def self.not_init(dir:, year:)
|
137
|
-
raise E::AlrInit if File.exist?("#{dir}/.meta") &&
|
138
|
-
Metafile.get(:year) != year.to_s
|
139
|
-
dir
|
140
|
-
end
|
141
|
-
def self.no_config
|
142
|
-
raise E::ConfigExist if File.exist?(Paths::Config.path)
|
143
|
-
Paths::Config.path
|
144
|
-
end
|
145
|
-
private
|
146
|
-
def self.valid_key?(key)
|
147
|
-
/session=(?:[a-f0-9]){96}/.match?(key)
|
148
|
-
end
|
149
|
-
def self.user_in_config?(user)
|
150
|
-
Files::Config::Tools.is_set?(key:"cookie=>#{user}")
|
151
|
-
end
|
152
|
-
end
|
153
78
|
end
|
154
79
|
end
|
data/lib/aoc_cli/paths.rb
CHANGED
@@ -37,6 +37,9 @@ module AocCli
|
|
37
37
|
def create_cache
|
38
38
|
FileUtils.mkdir_p(cache_dir) unless Dir.exist?(cache_dir)
|
39
39
|
end
|
40
|
+
def prefix
|
41
|
+
Prefs.string(key:"day_dir_prefix")
|
42
|
+
end
|
40
43
|
def filename(f:)
|
41
44
|
case f.to_sym
|
42
45
|
when :Input then "input"
|
@@ -48,7 +51,9 @@ module AocCli
|
|
48
51
|
Metafile.type == :DAY
|
49
52
|
end
|
50
53
|
def day_dir
|
51
|
-
day.to_i < 10 ?
|
54
|
+
day.to_i < 10 ?
|
55
|
+
"#{prefix}0#{day}" :
|
56
|
+
"#{prefix}#{day}"
|
52
57
|
end
|
53
58
|
def local_dir
|
54
59
|
in_day? ? "." : "#{day_dir}"
|
data/lib/aoc_cli/solve.rb
CHANGED
@@ -13,7 +13,10 @@ module AocCli
|
|
13
13
|
@year = Validate.year(y)
|
14
14
|
@day = Validate.day(d)
|
15
15
|
@part = Validate.part(p)
|
16
|
-
@answer = Validate.ans(a)
|
16
|
+
@answer = Validate.ans(attempt:self, ans:a)
|
17
|
+
end
|
18
|
+
def exists?
|
19
|
+
Database::Attempt.new(attempt:self)
|
17
20
|
end
|
18
21
|
def raw
|
19
22
|
@raw ||= Tools::Post.new(u:user, y:year, d:day,
|
data/lib/aoc_cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aoc_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Welham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|