aoc_cli 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24c94cfdcb4cde6a75876adf800bd44f835807df5bfab2ea0039e122fe6cc385
4
- data.tar.gz: b0b7e88af483fb95d1f497a984befeaf753e498ff7a2be4dc382859d7a67648f
3
+ metadata.gz: 3acf7f6fddbd91d2dbdb7e3407eafd03cdb3881c4accd09449c6781f0079ab6b
4
+ data.tar.gz: d117b869b63189c82829f81009c6c9081bb1beb2c61575340c230275ec54c9c2
5
5
  SHA512:
6
- metadata.gz: bd6c31e93df159af99140002bd6d49ef15cd56eb194f3df9b79355180310586e831420203960988ea4376bb9779dbf5f2599f77e9ce1cc82ecc309d514fcf160
7
- data.tar.gz: 93ccea0cfb58bce12f45676defa5294a85b1abea90cd24a41afa9ad1a8b20491d11d4765b0328c2bfed534ac7ef052c503e6d51b7837e8a2061d39cd5644a9fa
6
+ metadata.gz: a1b18d80a79c09e48edc79d181cd3512cc274ab267f9d4448696f84db1e71a7a3a2c556f83044b15c538c2584e4a675cbdab3ab561c51b9f9e35de3d62b75455
7
+ data.tar.gz: 1ee697aa72eb8022b9fddf6d2a3b200c9ee548c56cbc32578330edc22c67ec1ec6e16255edcdbca741f382224a26dec4858a4b89a70d040f019634070bd32e8f
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  tags
2
+ pkg/**
3
+ pkg
data/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
- 17-02-21
2
- 0.1.2
1
+ ## 17-02-21
2
+ ### 0.1.2
3
3
  - Add changelog
4
4
  - Add user-agent
5
+
6
+ ## 20-02-21
7
+ ###0.2.0
8
+ - Add calendar tables
9
+ - Star progress now based off this database rather than meta json
10
+ - Add cat of calendar from any directory
11
+ - Auto generate config file
12
+ - Better key validation
13
+ - Better default alias handling
14
+ - List all aliases
15
+ - Rehaul of year initialisation
16
+ - Expand config integration
17
+ - Ability to turn on/off calendar writing
18
+ - Turn on/off leaderboard stats in calendar file
19
+ - Git integration
20
+ - General refactor
data/Gemfile CHANGED
@@ -1,12 +1,4 @@
1
- # frozen_string_literal: true
2
-
3
1
  source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in aoc_cli.gemspec
6
2
  gemspec
7
3
 
8
4
  gem "rake", "~> 13.0"
9
- #gem "pandoc-ruby"
10
- #gem "curb"
11
- #gem "colorize"
12
- #gem "rspec"
data/README.md CHANGED
@@ -4,6 +4,17 @@
4
4
 
5
5
  A command-line interface to interact with Advent of Code puzzles, built in Ruby.
6
6
 
7
+ ## New to 0.2.0
8
+ - Calendar progress tables
9
+ - Quick-print calendar from any directory
10
+ - Configuration expansion
11
+ - Auto-generate config file
12
+ - Turn on/off creation of calendar file
13
+ - Turn on/off leaderboard stats in calendar file
14
+ - Basic git integration
15
+ - Better key validation
16
+ - Better default alias handling
17
+ - General bug fixes
7
18
 
8
19
  ## Main Features
9
20
  - Download puzzles as markdown and raw inputs directly from the command line
@@ -11,6 +22,7 @@ A command-line interface to interact with Advent of Code puzzles, built in Ruby.
11
22
  - Track progress through your calendar file which is automatically updated as you progress
12
23
  - View data about how you answer puzzles, for example your previous attempts, how long it takes to solve a puzzle successfully and how many attempts it took you
13
24
  - Inputs and puzzles are cached locally to prevent strain on AoC server
25
+ - Automatic git initialisation
14
26
  - Hot keys to open solution megathreads in Reddit if you get stuck
15
27
  - Support for multiple AoC accounts by use of session-key aliases
16
28
 
@@ -19,6 +31,7 @@ A command-line interface to interact with Advent of Code puzzles, built in Ruby.
19
31
 
20
32
  - aoc-cli uses Pandoc, make sure it is [installed](https://pandoc.org/installing.html)
21
33
  - Homebrew users can run `brew install pandoc`
34
+ - Mac OS users need to make sure developer tools is installed (thank you yspreen)
22
35
 
23
36
  Install gem
24
37
 
@@ -45,7 +58,7 @@ Open developer tools and open the network tab. Refresh the page and you should s
45
58
  It will contain a field that looks something like:
46
59
 
47
60
  ```
48
- cookie: session=ALPHANUMERIC STRING
61
+ cookie: session=HEXADECIMAL_STRING
49
62
  ```
50
63
 
51
64
  This is unique to your account, and allows aoc-cli to interact with the AoC server - do not share this!
@@ -61,28 +74,26 @@ aoc -k $your_key
61
74
 
62
75
  ```
63
76
 
64
- - AoC-cli stores this key under the alias 'main' by default.
77
+ - AoC-cli stores this key under the alias 'main' if no custom alias is specified
65
78
  - To store the key under a different alias use the `-u` or `--user` flags followed by the desired alias.
66
79
  - Session keys are stored in the aoc config file located at `~/.config/aoc-cli/aoc.rc`.
67
80
 
68
- - Keys can be stored manually in your config file using the format:
81
+ Keys can also be stored manually in your config file using the format:
69
82
 
70
- ```bash
83
+ ```
71
84
  cookie=>$alias=>$key
72
85
  ```
73
86
 
74
87
  For example:
75
88
 
76
- ```bash
77
- cookie=>account2=>1234abc
89
+ ```
90
+ cookie=>account2=>session=123abc
78
91
  ```
79
92
 
80
93
  ### Default Alias
81
94
 
82
95
  aoc-cli allows for multiple keys to be stored within the config file.
83
96
 
84
- By default, the key under the "main" alias is used when initialising year directories and another alias is not specified
85
-
86
97
  To see which alias is currently deafult run `aoc -U` or `aoc --default`
87
98
 
88
99
  - You can update the default alias by running
@@ -91,16 +102,31 @@ To see which alias is currently deafult run `aoc -U` or `aoc --default`
91
102
  aoc -U $new_default_alias
92
103
  ```
93
104
 
94
- For example:
105
+ By default, aoc-cli will determine the default alias in the following order of precedence
106
+
107
+ - The alias explicitly set by `default=>$alias` in your config file or by using the `-U` command
108
+ - The `main` alias (if it exists)
109
+ - The first key in your config file
110
+
111
+ ### Use Case
112
+
113
+ Say for example you wanted to learn a new language and decided to try out Advent of Code from scratch to get stuck in. You could set up a new account and grab the session key, which for example is `abc123`
114
+
115
+ Lets use Ruby as our new language. You could then store this new key under the alias `ruby`
95
116
 
96
117
  ```bash
97
- aoc -U account2
118
+ aoc -k session=abc123 -u ruby
98
119
  ```
99
120
 
100
- Alternatively you could add the following line to your config file
121
+ You could then set `ruby` as your default alias so that you do not have to specify `-u ruby` explicitly when initialising a year directory each time
101
122
 
102
123
  ```bash
103
- default=>account2
124
+ aoc -U ruby
125
+ ```
126
+ Alternatively you could add the following line to your config file
127
+
128
+ ```
129
+ default=>ruby
104
130
  ```
105
131
 
106
132
  ## Usage
@@ -118,19 +144,19 @@ There are two types of directories
118
144
 
119
145
  To begin using the cli you must first initialise the year directory.
120
146
 
121
- aoc-cli will intialise within your current working directory, so first create a directory for the year and cd into it
147
+ aoc-cli will intialise within your current working directory, so first create a directory for the year and change directory into it
122
148
 
123
149
  ```bash
124
150
  mkdir 2020
125
151
  cd 2020
126
152
  ```
127
- - Initialise the year directory using the command
153
+ Initialise the year directory using the command
128
154
 
129
155
  ```bash
130
156
  aoc -y 2020
131
157
  ```
132
158
 
133
- This will set the session key for the year directory to the default alias. To use a different AoC account run:
159
+ This will set the session key for the year directory to the default alias. To use a different alias run:
134
160
 
135
161
  ```bash
136
162
  aoc -y 2020 -u $alias
@@ -138,8 +164,9 @@ aoc -y 2020 -u $alias
138
164
 
139
165
  This command will create necessary metafiles, download the year calendar and fill it with your current progress (if any). This is stored in a markdown file in the year directory.
140
166
 
141
- By default, your stats in the leaderboard are also added to this file.
167
+ By default, your stats in the leaderboard are also added to this file. This can be changed - see Configuration
142
168
 
169
+ aoc-cli can also intialise a git directory on year intialisation (turned off by default)
143
170
 
144
171
  ## Initialising a Day
145
172
 
@@ -158,7 +185,7 @@ This command performs the following actions
158
185
  - Fetches raw puzzle input
159
186
  - The time you downloaded the puzzle is logged
160
187
 
161
- 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 this alias before, your puzzle and input will be transferred from the cache locally rather than downloading from the aoc server.
188
+ 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.
162
189
 
163
190
 
164
191
  ## Solving Puzzles
@@ -184,18 +211,20 @@ If you have sent multiple incorrect attempts AoC will ask you to wait before try
184
211
 
185
212
  ## Tables
186
213
 
187
- aoc-cli uses a local database to store information about your progress with puzzles. There are two main databases of use:
214
+ aoc-cli uses a local database to store information about your progress with puzzles. This tracks data on:
188
215
 
189
216
  1. Your attempts
190
217
  2. Your stats
218
+ 3. Your progress in the year
191
219
 
220
+ This data can be visualised in terminal-friendly tables
192
221
 
193
222
  ### Attempts
194
223
 
195
224
  Previous attempts for a puzzle can be viewed from the day directory by the use of the command
196
225
 
197
226
  ```bash
198
- aoc -a
227
+ aoc -a (--attempts)
199
228
  ```
200
229
 
201
230
  To specify which attempts to show from outside the day subdirectory you can use the command
@@ -208,34 +237,66 @@ Data is shown in a formatted table with incorrect attempts shown in red and the
208
237
 
209
238
  ![](https://github.com/apexatoll/aoc-files/blob/master/attempts.png)
210
239
 
240
+ You need to specify the part explicitly using `-p` or `--part` to view attempts for puzzles that are already completed
241
+
211
242
  ### Stats
212
243
 
213
244
  aoc-cli also tracks data related to your performance in puzzles, namely:
214
245
  - The time taken to complete a puzzle
215
246
  - How many attempts it took
216
247
 
217
- To view this, run the following command from the day subdirectory
248
+ To view stats on a specific puzzle run the following command from the day subdirectory
218
249
 
219
250
  ```bash
220
- aoc -S
251
+ aoc -S (--stats)
221
252
  ```
222
253
 
223
- To view the stats for the year as a whole run the same command from the year directory. Flags can be also be added manually for showing data for other users, years and days in a similar way to that of the attempts table
254
+ To view the stats for the year as a whole run the same command from the year directory.
255
+
256
+ Flags can be also be added manually for showing data for other users, years and days in a similar way to that of the attempts table
224
257
 
225
258
  ![](https://github.com/apexatoll/aoc-files/blob/master/stats.png)
226
259
 
227
- ## Reddit Integration
260
+ ### Progress
228
261
 
229
- You can run the command `aoc -R` from the day subdirectory, or by manual flags to open the solution megathread for the specified day in Reddit
262
+ To view your progress in the year you can run the commands
230
263
 
231
- If one is installed, aoc-cli will default to opening the thread within a reddit-cli such as RTV or TTRV. If one isn't found however, the thread will be opened within your default browser.
264
+ ```bash
265
+ aoc -c (--simple-cal)
266
+ ```
267
+
268
+ This will print a simple table showing your stars for each day. This is created on year initialisation and updated as you complete puzzles
232
269
 
233
- To always open megathread in your browser run
270
+ If you have calendar_file set to true in your configuration (default setting), you can quickly print your calendar file by using the command
234
271
 
235
272
  ```bash
236
- aoc -B true
273
+ aoc -C (--fancy-cal)
237
274
  ```
238
275
 
276
+ ![calendars](https://github.com/apexatoll/aoc-files/blob/master/calendars.gif)
277
+
278
+ ## Reddit Integration
279
+
280
+ ![reddit](https://github.com/apexatoll/aoc-files/blob/master/reddit.gif)
281
+
282
+ You can run the command `aoc -R (--reddit)` from the day subdirectory, or by manual flags to open the solution megathread for the specified day in Reddit
283
+
284
+ If one is installed, aoc-cli will default to opening the thread within a
285
+ reddit-cli such as [rtv](https://github.com/michael-lazar/rtv) or [ttrv](https://github.com/tildeclub/ttrv).
286
+
287
+ If one isn't found however, the thread will be opened within your default browser.
288
+
289
+ To open the reddit megathread in your browser, regardless of whether you have a CLI installed, run `aoc -B (--browser)`
290
+
291
+ ## Git Integration
292
+
293
+ aoc-cli currently supports basic integration with git. At present aoc-cli can:
294
+ - Initialise a git directory on year initialisation
295
+ - Create a gitignore file
296
+ - Configurable to add markdown and metafiles by default
297
+
298
+ These settings can be configured in your config file (see configuration)
299
+
239
300
  ## Vim Integration
240
301
 
241
302
  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.
@@ -247,39 +308,63 @@ autocmd filetype ruby nmap <silent><leader>ac :! aoc -s $(ruby %)<CR>
247
308
  ```
248
309
 
249
310
  Executing leader + ac would then run your program and send the answer to the server for verification (as long as your program only outputs an answer and no other text).
250
-
251
- Do not send endless attempts - only send when you are comfortable with your answer!
252
311
 
312
+ ## Configuration
253
313
 
254
- ## All Flags
314
+ aoc-cli can be configured using a the config file at `~/.config/aoc-cli/aoc.rc`
315
+
316
+ 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)
255
317
 
256
- | Flag Short | Flag Long | Action |
257
- |------------|----------------|-------------------------------------------|
258
- | `-a` | `--attempts` | Print attempts table |
259
- | `-b` | `--in-browser` | Open reddit in browser |
260
- | `-d` | `--init-day` | Initialise day subdirectory |
261
- | `-h` | `--help` | Show help screen |
262
- | `-k` | `--key` | Store session key |
263
- | `-p` | `--part` | Specify part for aoc command |
264
- | `-r` | `--refresh` | Refresh calendar (year dir) |
265
- | | | Refresh puzzle (day subdir) |
266
- | `-s` | `--solve` | Solve puzzle |
267
- | `-u` | `--user` | Specify alias for aoc command |
268
- | `-y` | `--init-year` | Initialise year directory |
269
- | `-B` | `--browser` | View reddit browser setting (no argument) |
270
- | | | Set reddit browser (with argument) |
271
- | `-D` | `--day` | Specify day for aoc command |
272
- | `-R` | `--reddit` | Open solution megathread |
273
- | `-S` | `--stats` | Print stats table |
274
- | `-U` | `--default` | View default alias (no argument) |
275
- | | | Set default alias (with argument) |
276
- | `-Y` | `--year` | Specify year for aoc command |
318
+ There is also an example aoc.rc file in the `sample` directory of this repo
277
319
 
320
+ Settings are added to the aoc-cli config file in the format
321
+
322
+ ```
323
+ setting_name=>setting
324
+ ```
325
+
326
+ Lines can be commented out of the rc file by prefixing with `//`
327
+
328
+ ### List of Configurable Options
329
+
330
+ | Flag | Type | Description | Default |
331
+ |-------------------|--------|---------------------------------------------------------------|---------|
332
+ | calendar_file | bool | Write calendar as a markdown file | true |
333
+ | default | string | Default alias | main |
334
+ | ignore_md_files | bool | Auto add md files (calendar and puzzles) to gitignore | true |
335
+ | ignore_meta_files | bool | Auto add meta files to gitignore | true |
336
+ | init_git | bool | Initialise a git repository on year initialisation | false |
337
+ | lb_in_calendar | bool | Include leaderboard stats in calendar file | true |
338
+ | reddit_in_browser | bool | Always open reddit links in browser | false |
339
+ | unicode_tables | bool | Display tables in unicode format. Otherwise ascii format used | true |
340
+
341
+
342
+ ## All Flags
343
+
344
+ | Flag Short | Flag Long | Action |
345
+ |------------|----------------|------------------------------------------------------|
346
+ | `-a` | `--attempts` | Print attempts table |
347
+ | `-B` | `--browser` | View reddit megathread in your browser |
348
+ | `-c` | `--simple-cal` | Print simplified calendar progress |
349
+ | `-C` | `--fancy-cal` | Print styled calendar (requires calendar_file=>true) |
350
+ | `-d` | `--init-day` | Initialise day subdirectory |
351
+ | `-D` | `--day` | Manual day specification for aoc command |
352
+ | `-G` | `--gen-config` | Write example config file |
353
+ | `-h` | `--help` | Show help screen |
354
+ | `-k` | `--key` | Store session key |
355
+ | `-p` | `--part` | Manual part specification for aoc command |
356
+ | `-r` | `--refresh` | Refresh calendar (year dir) |
357
+ | | | Refresh puzzle (day subdir) |
358
+ | `-R` | `--reddit` | Open solution megathread |
359
+ | `-s` | `--solve` | Solve puzzle |
360
+ | `-S` | `--stats` | Print stats table |
361
+ | `-u` | `--user` | Specify alias for aoc command |
362
+ | `-U` | `--default` | View default alias, list all aliases (no argument) |
363
+ | `-y` | `--init-year` | Initialise year directory |
364
+ | `-Y` | `--year` | Specify year for aoc command |
278
365
 
279
366
  ## Acknowledgments
280
367
 
281
368
  I am in no way affiliated with AoC, but I would like to take this opportunity to thank the creator Eric Wastl for the taking the time and great effort to produce these fantastic puzzles!
282
369
 
283
- Please note that requests are hard-coded to be throttled to a maximum of 1 HTTP request per 5 seconds. This is to ensure that the AoC server is not overloaded with requests. Please do not try and change this - it is to protect the server!
284
-
285
370
  Please let me know if there are any bugs or issues with the cli within the issues section - I will try to address them as quickly as I can
data/aoc_cli.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
  spec.add_dependency("colorize")
25
25
  spec.add_dependency("curb")
26
- spec.add_dependency("json")
26
+ spec.add_dependency("git")
27
27
  spec.add_dependency("pandoc-ruby")
28
28
  spec.add_dependency("sqlite3")
29
29
  spec.add_dependency("terminal-table")
data/bin/setup CHANGED
@@ -3,6 +3,5 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
- bundle install
7
6
 
8
- # Do any other automated setup that you need to do here
7
+ bundle install
data/lib/aoc_cli.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'colorize'
2
- require 'json'
3
2
  require 'sqlite3'
4
3
 
5
4
  require_relative 'aoc_cli/errors'
@@ -17,6 +16,7 @@ require_relative 'aoc_cli/tables'
17
16
 
18
17
  module AocCli
19
18
  Metafile = AocCli::Files::Metafile
19
+ Prefs = AocCli::Files::Config::Prefs
20
20
  Validate = AocCli::Interface::Validate
21
21
  E = AocCli::Errors
22
22
  end
@@ -7,36 +7,34 @@ module AocCli
7
7
  @user, @key = args[:user], args[:key]
8
8
  end
9
9
  def exec
10
- Files::Cookie.new(u:user).store(key:key)
10
+ Files::Config::Cookie.store(user:user, key:key)
11
11
  self
12
12
  end
13
13
  def respond
14
14
  puts "Key added successfully"
15
15
  end
16
16
  def defaults
17
- {user:Files::Config.new.def_acc}
17
+ { user:"main" }
18
18
  end
19
19
  end
20
20
  class YearInit
21
- attr_reader :user, :year
21
+ attr_reader :user, :year, :git
22
22
  def initialize(args)
23
23
  args = defaults.merge(args).compact
24
- @user, @year = args[:user], args[:year]
24
+ @user, @year, @git = args[:user], args[:year], args[:git]
25
25
  end
26
26
  def exec
27
- Year::Init
28
- .new(u:user, y:year)
29
- .write
30
- Year::Stars
31
- .new(u:user, y:year)
32
- .write.update_meta
27
+ Year::Meta.new(u:user, y:year).write
28
+ Year::Progress.new(u:user, y:year).write.init_calendar_db
29
+ Year::GitWrap.new if git
33
30
  self
34
31
  end
35
32
  def respond
36
- puts "Year initialised"
33
+ puts "Year #{year} initialised"
37
34
  end
38
35
  def defaults
39
- {user:Files::Config.new.def_acc}
36
+ { user:Prefs.default_alias,
37
+ git:Prefs.bool(key:"init_git") }
40
38
  end
41
39
  end
42
40
  class DayInit
@@ -48,19 +46,13 @@ module AocCli
48
46
  @day = args[:day]
49
47
  end
50
48
  def exec
51
- Day::Init
52
- .new(u:user, y:year, d:day)
53
- .mkdir
54
- .write
55
- #.init_db
56
- Day::Pages
57
- .new(u:user, y:year, d:day)
58
- .write
49
+ Day::Init.new(u:user, y:year, d:day).mkdir.meta
50
+ Day::Pages.new(u:user, y:year, d:day).load
59
51
  self
60
52
  end
61
53
  def defaults
62
- {user:Metafile.get(:user),
63
- year:Metafile.get(:year)}
54
+ { user:Metafile.get(:user),
55
+ year:Metafile.get(:year) }
64
56
  end
65
57
  def respond
66
58
  puts "Day #{day} initialised"
@@ -98,74 +90,54 @@ module AocCli
98
90
  @browser = args[:browser]
99
91
  end
100
92
  def exec
101
- Day::Reddit.new(y:year, d:day, b:browser).open
93
+ Tools::Reddit.new(y:year, d:day, b:browser).open
102
94
  self
103
95
  end
104
96
  def defaults
105
- {year:Metafile.get(:year),
106
- day:Metafile.get(:day),
107
- browser:Files::Config
108
- .new.get_bool(key:"browser")}
97
+ { year:Metafile.get(:year),
98
+ day:Metafile.get(:day),
99
+ browser:Prefs.bool(key:"reddit_in_browser") }
109
100
  end
110
101
  end
111
- class DefaultUser
102
+ class DefaultAlias
112
103
  attr_reader :user, :mode
113
104
  def initialize(args)
114
105
  @user = args[:user]
115
106
  @mode = user.nil? ? :get : :set
116
107
  end
117
108
  def exec
118
- case mode
119
- when :get then get_default
120
- when :set then set_default end
109
+ set if mode == :set && alias_valid
121
110
  self
122
111
  end
123
- def get_default
124
- puts "Current default alias: "\
125
- "#{(Files::Config.new
126
- .get_line(key:"default") || "main")
127
- .to_s.yellow}"
128
- end
129
- def set_default
130
- Files::Config.new.mod_line(
131
- key:"default",
132
- val:Validate.user(user))
133
- puts "Default account succesfully changed to "\
134
- "#{user.yellow}"
112
+ def respond
113
+ case mode
114
+ when :get then current
115
+ when :set then update end
135
116
  end
136
- end
137
- class DefaultReddit
138
- attr_reader :value, :mode
139
- def initialize(args)
140
- @value = args[:value]
141
- @mode = value.nil? ? :get : :set
117
+ private
118
+ def set
119
+ Files::Config::Tools
120
+ .mod_line(key:"default", val:Validate.user(user))
142
121
  end
143
- def exec
144
- case mode
145
- when :get then get_default
146
- when :set then set_default
147
- end
122
+ def current
123
+ puts <<~aliases
124
+ Default alias: #{Prefs.default_alias.yellow}
125
+ All aliases: #{Prefs.list_aliases.map{|a| a.blue}
126
+ .join(", ")}
127
+ aliases
148
128
  end
149
- def get_default
150
- puts "Always open Reddit in browser? "\
151
- "#{Files::Config.new
152
- .get_bool(key:"browser")
153
- .to_s.yellow}"
129
+ def alias_valid
130
+ Validate.key(Files::Config::Cookie.key(user:user))
154
131
  end
155
- def set_default
156
- Files::Config.new.mod_line(
157
- key:"browser", val:value)
158
- puts "Reddit browser setting changed to "\
159
- "#{value.yellow}"
132
+ def update
133
+ puts "Default alias changed to: #{user.yellow}"
160
134
  end
161
135
  end
162
136
  class Refresh
163
- attr_reader :dir
164
137
  def initialize(args)
165
- @dir = Metafile.type
166
138
  end
167
139
  def exec
168
- case dir
140
+ case Metafile.type
169
141
  when :DAY then Day.refresh
170
142
  when :ROOT then Year.refresh end
171
143
  self
@@ -181,8 +153,7 @@ module AocCli
181
153
  @part = args[:part]
182
154
  end
183
155
  def exec
184
- Tables::Attempts
185
- .new(u:user, y:year, d:day, p:part).show
156
+ Tables::Attempts.new(u:user, y:year, d:day, p:part).print
186
157
  self
187
158
  end
188
159
  def defaults
@@ -211,5 +182,51 @@ module AocCli
211
182
  day:Metafile.get(:day) }
212
183
  end
213
184
  end
185
+ class CalendarTable
186
+ attr_reader :user, :year
187
+ def initialize(args)
188
+ args = defaults.merge(args).compact
189
+ @user = Validate.user(args[:user])
190
+ @year = Validate.year(args[:year])
191
+ end
192
+ def exec
193
+ Tables::Calendar.new(u:user, y:year).print
194
+ end
195
+ def defaults
196
+ { user:Metafile.get(:user),
197
+ year:Metafile.get(:year) }
198
+ end
199
+ end
200
+ class PrintCal
201
+ attr_reader :path, :year
202
+ def initialize(args)
203
+ args = defaults.merge(args).compact
204
+ @year = Validate.year(args[:year])
205
+ end
206
+ def path
207
+ case Metafile.type
208
+ when :DAY then "../#{year}.md"
209
+ when :ROOT then "#{year}.md"
210
+ end
211
+ end
212
+ def exec
213
+ Prefs.bool(key:"calendar_file") ?
214
+ system("cat #{path} | less") :
215
+ puts("You have disabled calendar files")
216
+ end
217
+ def defaults
218
+ {year:Metafile.get(:year)}
219
+ end
220
+ end
221
+ class GenerateConfig
222
+ def initialize(args) end
223
+ def exec
224
+ Files::Config::Example.write
225
+ self
226
+ end
227
+ def respond
228
+ puts "Default config written to #{Paths::Config.path.blue}"
229
+ end
230
+ end
214
231
  end
215
232
  end