advent_of_code_cli 0.1.1 → 0.1.3

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: c7358ae00fcb5ac752f1512f4c643f8d4244bffc3952217d3e1de47095f14c46
4
- data.tar.gz: c769d144252d13015b46a01be1d7f0198242d5903872a5c9881b08a6f4dfbeb5
3
+ metadata.gz: 874bcb2472449a2b367b4276efabaf1c7b15a19857c0e331d16bf3cd6da7e700
4
+ data.tar.gz: 36f956b45bb8849b1b17880132842f16194209d3cfaff592be643b98da4d7ca2
5
5
  SHA512:
6
- metadata.gz: ade57a3e3a2b96b465acf42ea7ccbdd89e2347d32791180faade8a3e3ff0dac1d8eefeca5f0fe30b358af7fb6c0062cb4b26daf88ad8e07b20c57447210eabaf
7
- data.tar.gz: d5154c39abd8732678b0b17f3e64f345d2787cebb3c0ff47619c770fa8d28a085ce3feacfaf0b1081e6b50a1ae8ec7a97e31994e641f78ddbed88305dd343eb0
6
+ metadata.gz: 3387033c1bf3c5f5edd4cd335647c64d3722ba0ffd5a6f716e7ec895d6e789a537d67b181cc44d29d1c99eec79590b3fe69a3627fe4d19e3eeedf180d1b091b1
7
+ data.tar.gz: e952fb854364b9bfbcfdd6a84e194476c038ed176fde60903818dce824899c570b84cb256819e46f6afe5438402551adef59bc0825520d85adfce1819c9e8d2a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advent_of_code_cli (0.1.1)
4
+ advent_of_code_cli (0.1.3)
5
5
  thor (>= 1.2.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,33 +1,116 @@
1
- # AdventOfCodeCli
1
+ # 🎄 Advent of Code CLI
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/advent_of_code_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ > ⚠️ **Note:** This tool is under active development. I built in in a couple hours with no automated tests. Things may change between versions!
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ A little CLI tool that scaffolds and runs [Advent of Code](https://advent-of-code.com) solutions in Ruby.
6
6
 
7
- ## Installation
7
+ This project is heavily based on [advent-of-code-rust](https://github.com/arturopala/advent-of-code-rust). Go check it out!
8
8
 
9
- Install the gem and add to the application's Gemfile by executing:
9
+ ## Installation
10
10
 
11
- $ bundle add advent_of_code_cli
11
+ Add this line to your application's `Gemfile`:
12
12
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
13
+ ```ruby
14
+ gem "advent_of_code_cli"
15
+ ```
14
16
 
15
- $ gem install advent_of_code_cli
17
+ Run `bundle install`.
16
18
 
17
19
  ## Usage
18
20
 
19
- TODO: Write usage instructions here
21
+ ### Scaffold
20
22
 
21
- ## Development
23
+ This command will set up the files for any day of Advent of Code. It takes a nubmer between 1 and 25 as an argument.
22
24
 
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+ ```bash
26
+ bundle exec aoc_cli scaffold 1
27
+ ```
24
28
 
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+ This will result in the following output:
26
30
 
27
- ## Contributing
31
+ ```
32
+ Creating file: 01.rb...
33
+ Creating inputs directory...
34
+ Creating file: inputs/01.txt...
35
+ Creating examples directory...
36
+ Creating examples/01 directory...
37
+ ```
38
+
39
+ The file `01.rb` will have the following structure:
40
+
41
+ ```rb
42
+ module Day01
43
+ class << self
44
+ def part_one(input)
45
+ raise NotImplementedError
46
+ end
47
+
48
+ def part_two(input)
49
+ raise NotImplementedError
50
+ end
51
+ end
52
+ end
53
+ ```
54
+
55
+ I would love to make this structure configurable in the future.
56
+
57
+ ### Download
58
+
59
+ This command will download the input for a given day.
60
+
61
+ In order for this to work, you must provide your Advent of Code session cookie to the program in an environment variable:
62
+
63
+ ```bash
64
+ export AOC_COOKIE=your-cookie
65
+ ```
66
+
67
+ Once the environment variable is set, you can request your personal input for any day.
68
+
69
+ ```bash
70
+ bundle exec aoc_cli download 1
71
+ ```
28
72
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/advent_of_code_cli.
73
+ This will create the following output:
30
74
 
31
- ## License
75
+ ```
76
+ Fetching input...
77
+ Writing input to inputs/01.txt...
78
+ Done!
79
+ ```
80
+
81
+ By default, the CLI will request the input for this year, but you can request previous years' input by passing a `--year` flag.
82
+
83
+ ```bash
84
+ bundle exec aoc_cli download 1 --year 2021
85
+ ```
86
+
87
+ ### Solve
88
+
89
+ This command will run your solution to a certain day's puzzle.
90
+
91
+ ```
92
+ bundle exec aoc_cli solve 1
93
+ ```
94
+
95
+ This will create the following output:
96
+
97
+ ```
98
+ Reading input...
99
+ Loading solution...
100
+
101
+ Running part one...
102
+ Part one result: 10000
103
+ Took 0.000259 seconds to solve
104
+
105
+ Running part two...
106
+ Part two result: 10000
107
+ Took 0.00026 seconds to solve
108
+
109
+ Done!
110
+ ```
111
+
112
+ This command expects files to be in the format provided by the `scaffold` command. Once again, I would love to make this configurable but haven't gotten around to it yet.
113
+
114
+ ## Contributing
32
115
 
33
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
116
+ Issues and code contributions are welcome! Happy Advent of Code to all who celebrate! 🎁
@@ -31,11 +31,11 @@ module AdventOfCode
31
31
  private
32
32
 
33
33
  def cookie
34
- @cookie ||= File.read("cookie.txt").strip
34
+ @cookie ||= ENV["AOC_COOKIE"]
35
35
  end
36
36
 
37
37
  def cookie_present?
38
- File.exist?("cookie.txt")
38
+ ENV.key?("AOC_COOKIE")
39
39
  end
40
40
 
41
41
  def fetch_input
@@ -10,7 +10,7 @@ module AdventOfCode
10
10
  raise MissingSolutionError unless File.exist?(solution_file_name)
11
11
 
12
12
  say "Reading input..."
13
- input = File.read(input_file_name).strip
13
+ input = File.readlines(input_file_name, chomp: true)
14
14
 
15
15
  say "Loading solution..."
16
16
  load(solution_file_name)
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "commands/command"
4
- require_relative "commands/cookie"
5
4
  require_relative "commands/download"
6
5
  require_relative "commands/scaffold"
7
6
  require_relative "commands/solve"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdventOfCode
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -20,11 +20,6 @@ module AdventOfCode
20
20
  rescue_invalid_day_error
21
21
  end
22
22
 
23
- desc "cookie VALUE", "store your Advent of Code cookie with value VALUE in the cookie.txt file"
24
- def cookie(value)
25
- AdventOfCode::Commands::Cookie.new(value: value).execute
26
- end
27
-
28
23
  desc "download DAY", "download your input for day DAY"
29
24
  option :year, default: Time.now.year.to_s
30
25
  def download(day)
@@ -32,7 +27,7 @@ module AdventOfCode
32
27
  rescue AdventOfCode::InvalidDayError
33
28
  rescue_invalid_day_error
34
29
  rescue AdventOfCode::MissingCookieError
35
- say "Error: Cannot find cookie in cookie.txt file.", :red
30
+ say "Error: Cannot find cookie in the AOC_COOKIE environment variable.", :red
36
31
  end
37
32
 
38
33
  desc "solve DAY", "run your solutions for day DAY"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advent_of_code_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emily Samp
@@ -44,7 +44,6 @@ files:
44
44
  - lib/advent_of_code_cli.rb
45
45
  - lib/advent_of_code_cli/commands.rb
46
46
  - lib/advent_of_code_cli/commands/command.rb
47
- - lib/advent_of_code_cli/commands/cookie.rb
48
47
  - lib/advent_of_code_cli/commands/download.rb
49
48
  - lib/advent_of_code_cli/commands/scaffold.rb
50
49
  - lib/advent_of_code_cli/commands/solve.rb
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AdventOfCode
4
- module Commands
5
- class Cookie
6
- def initialize(value:)
7
- @value = value
8
- end
9
-
10
- def execute
11
- say "Creating cookie.txt file..."
12
- File.open("cookie.txt", "w") do |file|
13
- file.puts @value
14
- end
15
-
16
- say "Done!", :green
17
- end
18
- end
19
- end
20
- end