aocli 1.4.4 → 1.5.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: b1b051f8ff01af0cd8c73b87ce71f60e2d168083d6d5c560b5c96cb2631d734b
4
- data.tar.gz: 56a8fc53f52ebb65993baf8e97444fad7154bc68cec266ecd04b4cbe5c9d7320
3
+ metadata.gz: 401260b3c2e7cdde374a92e0fb04dd8e22339d42b1c7b17b1fa493ff632fff47
4
+ data.tar.gz: 3ce43f2fa01ceb2d096f3463f3d74fb1dacbb109c395004bfd80de11e2f6b94d
5
5
  SHA512:
6
- metadata.gz: 938f801d1c451d28279075209c0d3a2d88e235c652fb8f5eb81919cf2589df1eab92e7ea8d6016d93a38147525a20d49a3f72bcc1ab70a38ea05c7191586d6ee
7
- data.tar.gz: e42e540e22ab43c83733f65aef1e725ff06aba142f576bbe3399256942282bc00ed4ed3f2164f537defa69694349543a07d4a777eba4a186716ead2148e7364f
6
+ metadata.gz: 74937e8ee1f6cbbd9739202196bbb6f310ab6215ece6054122fdabf4dbcfb3884f25ade07a515635fb70f59e8301f045f42a4a52bcfb71d36262a9224e955b0c
7
+ data.tar.gz: 050203b32f0b03893bfd4ca79d78f3c710e5367a41ae94312d000313de025636f011823d85cc31d0b3a16a9098b23e758b165a4cc6df821461d5ad12050a4f15
data/.rubocop.yml CHANGED
@@ -11,3 +11,15 @@ Style/StringLiteralsInInterpolation:
11
11
 
12
12
  Layout/LineLength:
13
13
  Max: 120
14
+
15
+ Metrics/BlockLength:
16
+ Enabled: false
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: false
20
+
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ Metrics/AbcSize:
25
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -17,3 +17,7 @@
17
17
  ## [1.4.4] - 2023-11-21
18
18
 
19
19
  - Support year 2023
20
+
21
+ ## [1.4.5] - 2023-11-21
22
+
23
+ - Bump active support version to remove depractor error
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aocli (1.4.4)
5
- activesupport (~> 7.0)
4
+ aocli (1.5.0)
5
+ activesupport (~> 7.0.8)
6
6
  faraday (~> 2.7)
7
7
  nokogiri (~> 1.13)
8
8
  tty-prompt (~> 0.23.1)
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (7.0.4)
13
+ activesupport (7.0.8)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 1.6, < 2)
16
16
  minitest (>= 5.1)
data/README.md CHANGED
@@ -38,6 +38,23 @@ For the example shown, I viewed 2018 day 11 and can see the cookie inside the co
38
38
 
39
39
  ![cookie-example](/public/aocli-cookie-helper.png)
40
40
 
41
+ ## Using your own template file
42
+
43
+ Don't like the default template you got for each challenge? It's just about as basic as it gets so I've made it easy for users
44
+ to create their own and have it be used. Simply create your own template, structured however your prefer
45
+ and optionally insert the two directives `__aocli_load_input__` and `__aocli_problem_description__`. You can leave either off if you
46
+ prefer to either not have the problem description shown or would like to load your input in another way.
47
+
48
+ `__aocli_problem_description__` Will be replaced with the given problems description as a comment
49
+
50
+ `__aocli_load_input__` Will be replaced by the line that loads your input as a string into the `input` variable.
51
+
52
+ Then run the `aocli` command and choose the "Set Template File" option, paste in the full path to your file and it'll be used
53
+ when generating the files for a given day.
54
+
55
+ Partial file path could be used if you expect to run aocli from the same location
56
+ all the time but I'd recommend using the full path just in case.
57
+
41
58
  ## Development
42
59
 
43
60
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -16,7 +16,7 @@ module Aocli
16
16
  class Client
17
17
  attr_reader :conn
18
18
  def initialize
19
- @cookie = Aocli::CookieRetriever.call
19
+ @cookie = Aocli::Config.value_for(:cookie)
20
20
  @conn = initialise_conn_object
21
21
  raise(StandardError, "No cookie is set") unless @cookie
22
22
  end
data/lib/aocli/cli.rb CHANGED
@@ -1,21 +1,25 @@
1
+ require "byebug"
1
2
 
2
- require"byebug"
3
3
  module Aocli
4
4
  class Cli
5
5
  def initialize
6
- @options = {cookie: Aocli::CookieRetriever.call}
6
+ @options = Aocli::Config.load_config
7
7
  @prompt = TTY::Prompt.new
8
8
  end
9
9
 
10
10
  def run
11
11
  prompt_for_command
12
- get_all_command_options
12
+ prompt_command_options
13
13
  # Aocli::Commands::StartDay
14
14
  # Aocli::Commands::SaveCookie
15
+ # Aocli::Commands::RemoveCookie
16
+ # Aocli::Commands::SetTemplatePath
17
+ # Aocli::Commands::RemoveTemplatePath
15
18
  options[:command].constantize.run!(options)
16
19
  end
17
20
 
18
21
  private
22
+
19
23
  attr_accessor :options, :prompt
20
24
  attr_reader :cookie
21
25
 
@@ -23,12 +27,16 @@ module Aocli
23
27
  options[:command] = prompt.select("What would you like to do?", command_options)
24
28
  end
25
29
 
26
- def get_all_command_options
30
+ def prompt_command_options
27
31
  case options[:command]
28
32
  when "Aocli::Commands::StartDay"
29
33
  set_start_day_options
30
34
  when "Aocli::Commands::SaveCookie"
31
35
  set_save_cookie_options
36
+ when "Aocli::Commands::SetTemplatePath"
37
+ set_template_path_options
38
+ when "Aocli::Commands::RemoveCookie", "Aocli::Commands::RemoveTemplatePath"
39
+ nil
32
40
  when "Exit"
33
41
  exit
34
42
  else
@@ -38,16 +46,17 @@ module Aocli
38
46
 
39
47
  def command_options
40
48
  @command_options ||= [
49
+ requires_config(:cookie, {name: "Start day", value: "Aocli::Commands::StartDay"}),
41
50
  {name: "Save Cookie", value: "Aocli::Commands::SaveCookie"},
42
- requires_cookie({name: "Start day", value: "Aocli::Commands::StartDay"}),
51
+ requires_config(:cookie, {name: "Unset cookie", value: "Aocli::Commands::RemoveCookie"}),
52
+ {name: set_template_prompt, value: "Aocli::Commands::SetTemplatePath"},
53
+ requires_config(:template_path, {name: "Unset template file", value: "Aocli::Commands::RemoveTemplatePath"}),
43
54
  {name: "Exit", value: "Exit"},
44
55
  ]
45
- # TODO:
46
- # requires_cookie({name: "Remove cookie file", value: "Aocli::Commands::RemoveCookieFile"}),
47
56
  end
48
57
 
49
- def requires_cookie(hash)
50
- hash.merge(options[:cookie] ? {} : {disabled: "(No cookie has been set yet)"})
58
+ def requires_config(required_config, hash)
59
+ hash.merge(options[required_config] ? {} : {disabled: "(No #{required_config} has been set yet)"})
51
60
  end
52
61
 
53
62
  def set_start_day_options
@@ -60,5 +69,17 @@ module Aocli
60
69
  def set_save_cookie_options
61
70
  options[:cookie] = prompt.ask("Paste your cookie and it will be saved:")
62
71
  end
72
+
73
+ def set_template_path_options
74
+ options[:template_path] = prompt.ask("Paste the full file path to your template file:")
75
+ end
76
+
77
+ def set_template_prompt
78
+ base_prompt = "Set Template File"
79
+ if options[:template_path]
80
+ base_prompt += " -> Currently set to '#{options[:template_path]}'"
81
+ end
82
+ base_prompt
83
+ end
63
84
  end
64
85
  end
@@ -0,0 +1,13 @@
1
+ module Aocli
2
+ module Commands
3
+ module RemoveCookie
4
+ def self.run!(_options = nil)
5
+ Aocli::Config.remove_config(:cookie)
6
+
7
+ puts <<~MSG
8
+ ### Cookie has been removed ###
9
+ MSG
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Aocli
2
+ module Commands
3
+ module RemoveTemplatePath
4
+ def self.run!(_options = nil)
5
+ current_path = Aocli::Config.value_for(:template_path)
6
+ Aocli::Config.remove_config(:template_path)
7
+
8
+ puts <<~MSG
9
+ ### '#{current_path} is no longer set as your template file ###
10
+ MSG
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,8 +2,7 @@ module Aocli
2
2
  module Commands
3
3
  module SaveCookie
4
4
  def self.run!(options)
5
- Aocli::FileUtils.touch_file(Aocli::Values::CONFIG_FILE_PATH)
6
- File.write(Aocli::Values::CONFIG_FILE_PATH, {cookie: options[:cookie]}.to_yaml)
5
+ Aocli::Config.add_config(key: :cookie, value: options[:cookie])
7
6
 
8
7
  puts <<~MSG
9
8
  ### Cookie saved to #{Aocli::Values::CONFIG_FILE_PATH} ###
@@ -0,0 +1,13 @@
1
+ module Aocli
2
+ module Commands
3
+ module SetTemplatePath
4
+ def self.run!(options)
5
+ Aocli::Config.add_config(key: :template_path, value: options[:template_path])
6
+
7
+ puts <<~MSG
8
+ ### The template at '#{options[:template_path]}' will now be used ###
9
+ MSG
10
+ end
11
+ end
12
+ end
13
+ end
@@ -23,6 +23,7 @@ module Aocli
23
23
  end
24
24
 
25
25
  private
26
+
26
27
  attr_reader :date, :output_destination, :main_file_path, :input_file_path
27
28
 
28
29
  def main_content
@@ -31,15 +32,22 @@ module Aocli
31
32
  day: date.day,
32
33
  )
33
34
 
34
- content = Aocli::FileUtils.insert_lines(
35
+ problem_description = "Part One Description\n" + problem_description
36
+
37
+ template_file = Aocli::Config.value_for(:template_path) || File.join(__dir__, "../content/main.txt")
38
+ unless File.exist?(template_file)
39
+ template_file = File.join(__dir__, "../content/main.txt")
40
+ end
41
+
42
+ content = Aocli::FileUtils.replace_line(
43
+ File.read(template_file),
44
+ "__aocli_problem_description__",
35
45
  Aocli::FileUtils.wrap_lines(problem_description).split("\n").map { _1 == "" ? "#" : "# #{_1}" },
36
- into: File.read(File.join(__dir__, "../content/main.txt")),
37
- after: "##### Part One Description #####",
38
46
  )
39
47
 
40
48
  Aocli::FileUtils.replace_line(
41
49
  content,
42
- "# __load_input__",
50
+ "__aocli_load_input__",
43
51
  'input = File.read(__FILE__.gsub("main.rb", "input.txt"))'
44
52
  )
45
53
  end
@@ -0,0 +1,28 @@
1
+ module Aocli
2
+ module Config
3
+ module_function
4
+
5
+ def add_config(key:, value:)
6
+ config = load_config.merge({key => value})
7
+ File.write(Aocli::Values::CONFIG_FILE_PATH, config.to_yaml)
8
+ end
9
+
10
+ def value_for(key)
11
+ load_config[key]
12
+ end
13
+
14
+ def load_config
15
+ unless File.exist?(Aocli::Values::CONFIG_FILE_PATH)
16
+ Aocli::FileUtils.touch_file(Aocli::Values::CONFIG_FILE_PATH)
17
+ end
18
+
19
+ YAML.load_file(Aocli::Values::CONFIG_FILE_PATH, fallback: {})
20
+ end
21
+
22
+ def remove_config(key)
23
+ config = load_config
24
+
25
+ File.write(Aocli::Values::CONFIG_FILE_PATH, config.except(key).to_yaml)
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,4 @@
1
- ##### Part One Description #####
1
+ __aocli_problem_description__
2
2
 
3
3
  def self.parse_input(input)
4
4
  # Parse input
@@ -13,6 +13,7 @@ def part_two(input)
13
13
  # Solve part two
14
14
  end
15
15
 
16
- # __load_input__
16
+ __aocli_load_input__
17
+
17
18
  puts "Part One: #{part_one(parse_input(input))}"
18
19
  puts "Part Two: #{part_two(parse_input(input))}"
data/lib/aocli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aocli
4
- VERSION = "1.4.4"
4
+ VERSION = "1.5.0"
5
5
  end
data/lib/aocli.rb CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  require("aocli/advent_of_code")
4
4
  require("aocli/cli")
5
+ require("aocli/config")
6
+ require("aocli/commands/set_template_path")
5
7
  require("aocli/commands/save_cookie")
8
+ require("aocli/commands/remove_cookie")
9
+ require("aocli/commands/remove_template_path")
6
10
  require("aocli/commands/start_day")
7
11
  require("aocli/file_utils")
8
12
  require("aocli/version")
9
- require("aocli/cookie_retriever")
10
13
  require("aocli/values")
11
14
 
12
15
  require("fileutils")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aocli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Astley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '7.0'
19
+ version: 7.0.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '7.0'
26
+ version: 7.0.8
27
27
  - !ruby/object:Gem::Dependency
28
- name: nokogiri
28
+ name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.13'
33
+ version: '2.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.13'
40
+ version: '2.7'
41
41
  - !ruby/object:Gem::Dependency
42
- name: tty-prompt
42
+ name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.23.1
47
+ version: '1.13'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.23.1
54
+ version: '1.13'
55
55
  - !ruby/object:Gem::Dependency
56
- name: faraday
56
+ name: tty-prompt
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.7'
61
+ version: 0.23.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.7'
68
+ version: 0.23.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: byebug
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -173,10 +173,13 @@ files:
173
173
  - lib/aocli/advent_of_code.rb
174
174
  - lib/aocli/advent_of_code/client.rb
175
175
  - lib/aocli/cli.rb
176
+ - lib/aocli/commands/remove_cookie.rb
177
+ - lib/aocli/commands/remove_template_path.rb
176
178
  - lib/aocli/commands/save_cookie.rb
179
+ - lib/aocli/commands/set_template_path.rb
177
180
  - lib/aocli/commands/start_day.rb
181
+ - lib/aocli/config.rb
178
182
  - lib/aocli/content/main.txt
179
- - lib/aocli/cookie_retriever.rb
180
183
  - lib/aocli/file_utils.rb
181
184
  - lib/aocli/values.rb
182
185
  - lib/aocli/version.rb
@@ -205,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
208
  - !ruby/object:Gem::Version
206
209
  version: '0'
207
210
  requirements: []
208
- rubygems_version: 3.2.32
211
+ rubygems_version: 3.3.25
209
212
  signing_key:
210
213
  specification_version: 4
211
214
  summary: Command line application to retrieve advent of code challenges
@@ -1,18 +0,0 @@
1
- require("yaml")
2
-
3
- module Aocli
4
- module CookieRetriever
5
- module_function
6
-
7
- def call
8
- return unless file_exists?
9
-
10
- config = YAML.load_file(Aocli::Values::CONFIG_FILE_PATH)
11
- config[:cookie]
12
- end
13
-
14
- def file_exists?
15
- File.file?(Aocli::Values::CONFIG_FILE_PATH)
16
- end
17
- end
18
- end