elver

command module
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2020 License: MIT Imports: 2 Imported by: 0

README


Features | How does it work? | Getting started | Examples | Similar


GitHub GitHub go.mod Go version GitHub tag (latest by date) Go PkgGoDev

Run your Go Advent of Code solutions with a single command. Write your solution and Elver will take care of the rest.

Features

  • Automatically downloads and caches the input
  • Runs your latest solution and times it
  • Automatic benchmarking of your solution
  • 0 third party dependencies

How does it work?

Elver uses plugin build mode to dynamically look up the solutions. These must reside in an Advent of Code folder under the main package.

Getting started

1. Install

$ go get github.com/aod/elver

2. Session token

Your https://adventofcode.com session token is required for downloading and caching the inputs.

2.A Environment variable

Set your Advent of Code session token in the environment variable AOC_SESSION.

2.B Config file

Alternatively you can store it in the aoc_session file in the following directory:

  • Linux: $HOME/.config/elver/
  • MacOS: /Library/Application Support/elver/
  • Windows: %AppData%\elver\

3. Project structure

A solution for a day in an Advent of Code year is represented by 2 solvers for part A and B. All solvers are functions which satisfy the same signature where interface{} is the output:

func (input string) (interface{}, error)

For the plugin build mode to work correctly all solvers must be exported. The name of a solver is also very important for elver to work properly. It's name must satisfy the following set of rules:

  • Starts with Day
  • Followed by a valid Advent of Code day
    • Within (inclusive) range of 1..25
  • Ends with A for part 1 or B for part 2.

Solvers are workspaced by the Advent of Code year which is also used as the folder name.

Example
// /2015/01.go
package main

import "errors"

func Day1A(input string) (interface{}, error) {
    return 42, nil
}

func Day1B(input string) (interface{}, error) {
    return nil, errors.New("Not implemented")
}

Running Elver in the root directory will output something like the following:

$ elver
AOC 2015
Day 1 A (312ns):
42
Day 1 B (956ns):
[ERROR] Not implemented
Benchmarking

Run Elver with the -b flag to benchmark your latest solution:

$ elver -b
AOC 2015
Day 1 A (N=231919370, 5 ns/op, 0 bytes/op, 0 allocs/op):
42
Day 1 B (N=0, 0 ns/op, 0 bytes/op, 0 allocs/op):
[ERROR] Not implemented

Examples

Running the latest solvers:

$ elver

Running the latest solvers of a specific year:

$ elver -y 2017

Running the latest solvers of a specific day:

$ elver -d 21

Running the specific solvers of a year and day:

$ elver -y 2017 -d 21

Benchmarking the solvers by adding the -b flag

$ elver -b
// Works with any combination of the previously mentioned flags e.g.:
$ elver -y 2017 -d 21 -b

Similar

These type of utility tools for Advent of Code also exist for other programming languages like cargo-aoc (Rust) and aocd (Python). Elver finds inspiration in these awesome projects so be sure to check them out as well!

Documentation

Overview

Run your Go Advent of Code solutions with a single command. Write your solution and Elver will take care of the rest.

How It Works

Elver uses plugin build mode to generate a `.so` file to dynamically look up the solutions. These must reside in an Advent of Code folder under the main package.

A solution for a day in an Advent of Code year is represented by 2 solvers for part A and B. All solvers are functions which satisfy the same signature where interface{} is the output:

func (input string) (interface{}, error)

A solver must be exported and it's name satisfy the following regex:

(Day)([1-9]|1[0-9]|2[0-5])(A|B)

E.g.:

func Day1A(input string) (interface{}, error) {
    return 42, nil
}

Solvers are workspaced by the Advent of Code year which is also used as the folder name.

Code Example

package main
import "errors"
func Day1A(input string) (interface{}, error) {
    return 42, nil
}
func Day1B(input string) (interface{}, error) {
    return nil, errors.New("Not implemented")
}

Running Elver in the root directory will output something like the following:

$ elver
AOC 2015
Day 1 A (312ns):
42
Day 1 B (956ns):
[ERROR] Not implemented

Directories

Path Synopsis
Package aoc contains functionalities related to Advent of Code.
Package aoc contains functionalities related to Advent of Code.
Package command is a simple bare-bones wrapper around the std "os/exec" package.
Package command is a simple bare-bones wrapper around the std "os/exec" package.
Package config providies ways to retrieve configurations and such from the user's profile.
Package config providies ways to retrieve configurations and such from the user's profile.
Package flags adds more types of flags which satisfy the flag.Value interface.
Package flags adds more types of flags which satisfy the flag.Value interface.
internal
cmd
util
Package util provides small utility functions.
Package util provides small utility functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL