File tree 3 files changed +13
-6
lines changed
3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change 1
1
local cache = require " aoc.cache"
2
2
local curl = require " plenary.curl"
3
- local inspect = require " vim.inspect"
4
3
local cfg = require " aoc.config"
5
4
6
5
--- @class APIWrapper
@@ -22,12 +21,12 @@ local validate_args = function(day, year)
22
21
local d = tonumber (day )
23
22
local y = tonumber (year )
24
23
25
- if d < 1 or d > 31 then
26
- vim .api .nvim_err_writeln (" Invalid day: " .. d )
24
+ if not d or d < 1 or d > 31 then
25
+ vim .api .nvim_err_writeln (" Invalid day: " .. day )
27
26
return false
28
27
end
29
28
30
- if y < 2015 or y > tonumber (os.date " %Y" ) then
29
+ if not y and y < 2015 or y > tonumber (os.date " %Y" ) then
31
30
vim .api .nvim_err_writeln (" Invalid year: " .. year )
32
31
return false
33
32
end
Original file line number Diff line number Diff line change 1
- local inspect = require " vim.inspect"
2
-
3
1
--- @class PuzzleCache
4
2
local M = {}
5
3
Original file line number Diff line number Diff line change @@ -5,6 +5,14 @@ local cache = require "aoc.cache"
5
5
--- @class AOC
6
6
local M = {}
7
7
8
+ --- Strip input of any leading/trailing spaces
9
+ --- @param s string
10
+ --- @return string
11
+ local trim = function (s )
12
+ s , _ = string.gsub (s , " %s+" , " " )
13
+ return s
14
+ end
15
+
8
16
--- @param args any
9
17
M .setup = function (args )
10
18
cfg .init (args )
@@ -14,6 +22,8 @@ M.setup = function(args)
14
22
local year = vim .fn .input " Year: "
15
23
vim .api .nvim_out_write " \n "
16
24
25
+ day = trim (day )
26
+ year = trim (year )
17
27
api .save_puzzle_input (day , year )
18
28
end , {})
19
29
You can’t perform that action at this time.
0 commit comments