Skip to content

Commit

Permalink
FEAT: add Go boiler
Browse files Browse the repository at this point in the history
  • Loading branch information
luxedo committed Nov 3, 2024
1 parent 74a27a3 commit 5855025
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ for each language and how to create your own boilerplate.
- Python
- Rust
- Elixir
- Go
- [_Create your own_](doc/BOILERPLATE.md)

Any program that supports the [FIREPLACEv1](doc/FIREPLACEv1.0.md) prococol can use `esb` tooling.
Expand Down
2 changes: 1 addition & 1 deletion src/esb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
(Thank you [Eric 😉!](https://twitter.com/ericwastl)).
"""

__version__ = "0.1.3"
__version__ = "0.2.0"
11 changes: 11 additions & 0 deletions src/esb/boilers/go/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "go",
"files": {
"go.mod": "go.mod",
"main.go": "main.go"
},
"run_command": ["go", "run", "main.go"],
"build_command": ["go", "mod", "tidy"],
"symbol": "[cyan1]g[/cyan1]",
"emoji": "🐹"
}
7 changes: 7 additions & 0 deletions src/esb/boilers/go/template/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module AOC_Year{year}Day{day}

go 1.23.2

require github.com/luxedo/esb_fireplace-go v0.3.0

require github.com/spf13/pflag v1.0.5 // indirect
31 changes: 31 additions & 0 deletions src/esb/boilers/go/template/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main
/*
* ElfScript Brigade
*
* Advent Of Code {year} Day {day}
* Rust Solution
*
* {problem_title}
*
* https://{problem_url}
*
*/

import (
"github.com/luxedo/esb_fireplace-go"
)

func solve_pt1(input_data string, args []string) (interface{}, error) {
return 25, nil
}


func solve_pt2(input_data string, args []string) (interface{}, error) {
return "December", nil
}

func main() {
// 🎅🎄❄️☃️🎁🦌
// Bright christmas lights HERE
esb_fireplace.V1Run(solve_pt1, solve_pt2)
}
10 changes: 7 additions & 3 deletions src/esb/commands/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ def fetch_day(self, year: int, day: int, *, force: bool = False):
if not force and tests_file.is_file():
eprint_info(f"Tests for year {year} day {pad_day(day)} already cached")
else:
tests_input = rudolph.fetch_tests(year, day)
tests_file.parent.mkdir(parents=True, exist_ok=True)
tests_file.write_text(tests_input)
try:
tests_input = rudolph.fetch_tests(year, day)
except ValueError:
eprint_error("Could not fetch tests. Perhaps they're not available yet.")
else:
tests_file.parent.mkdir(parents=True, exist_ok=True)
tests_file.write_text(tests_input)

eprint_info(f"Fetched year {year} day {pad_day(day)}!")
self.db.ECAPuzzle(
Expand Down
2 changes: 1 addition & 1 deletion src/esb/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ def start_day(self, lang: LangSpec, year: int, day: int, *, force: bool):
language=lang.name,
solved_pt1=None,
solved_pt2=None,
).insert()
).insert(replace=True)
eprint_info(f"Started code for {lang.name}, year {year} day {pad_day(day)}")
eprint_info(f"Open files at {lang_sled.day_dir(year, day)} and happy coding!")
3 changes: 2 additions & 1 deletion src/esb/lib/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_text(self, element: Tag):
if element.name in {"p", "pre"}:
text += "\n\n"
for child in element.children:
text += self.get_text(child.extract()) # type: ignore
text += self.get_text(child) # type: ignore
else:
text += element.text
return text
Expand All @@ -125,6 +125,7 @@ def fetch_statement(self, year: int, day: int) -> tuple[str, str, str | None, st
soup = BeautifulSoup(body, "html.parser")
statement = ""
for article in soup.find_all("article"):
statement += "\n"
statement += self.get_text(article)
statement = re.sub(r"\n{3,}", "\n\n", statement)
statement = "\n".join("\n".join(wrap(line, width=100)) for line in statement.strip().split("\n"))
Expand Down
2 changes: 1 addition & 1 deletion src/esb/protocol/fireplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _v1_run(solve_pt1: AocSolutionFn, solve_pt2: AocSolutionFn, part: FPPart, ar


def v1_run(solve_pt1: AocSolutionFn, solve_pt2: AocSolutionFn):
parser = argparse.ArgumentParser("Elf Script Brigade python solution runner")
parser = argparse.ArgumentParser("Elf Script Brigade Python solution runner")
parser.add_argument(
"-p",
"--part",
Expand Down

0 comments on commit 5855025

Please sign in to comment.