summaryrefslogtreecommitdiff
path: root/cmd/aocli
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-02-26 18:06:19 +0100
committerMike Vink <mike1994vink@gmail.com>2023-02-26 18:06:19 +0100
commit92e0fe693cdca3b15fb3c0e9b97738fdac0df8ba (patch)
treea3df65d32b8a6c481751e4010c4354f0e98f6f17 /cmd/aocli
parent2a0875cf1f0b726678831cf9e8951b3363f4578d (diff)
fixup
Diffstat (limited to 'cmd/aocli')
-rw-r--r--cmd/aocli/gen.go42
1 files changed, 39 insertions, 3 deletions
diff --git a/cmd/aocli/gen.go b/cmd/aocli/gen.go
index c8251a6..7320894 100644
--- a/cmd/aocli/gen.go
+++ b/cmd/aocli/gen.go
@@ -2,14 +2,50 @@ package main
import (
"fmt"
+ "strconv"
+ "strings"
"github.com/spf13/cobra"
)
+var templateStr string = `
+`
+
var genCmd = &cobra.Command{
Use: "gen",
- Short: "Generate a new key pair",
- Run: func(cmd *cobra.Command, args []string) {
- fmt.Println(args)
+ Short: "Generate a new boilerplate entrypoint for a day of Advent of Code",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ year, day := "", ""
+ if len(args) == 1 {
+ parts := strings.SplitN(args[0], "/", 2)
+ if len(parts) == 2 {
+ year = parts[0]
+ day = parts[1]
+ }
+ } else {
+ return fmt.Errorf("Expected one argument in format %q", "<year>/<day>")
+ }
+
+ if year == "" || day == "" {
+ return fmt.Errorf("Expected one argument in format %q", "<year>/<day>")
+ }
+
+ _, err := strconv.Atoi(year)
+ if err != nil {
+ return fmt.Errorf("Couldn't parse year integer: %q", year)
+ }
+
+ dayInt, err := strconv.Atoi(day)
+ if err != nil {
+ return fmt.Errorf("Couldn't parse day integer: %q", day)
+ }
+
+ if dayInt < 1 || dayInt > 25 {
+ return fmt.Errorf("Day must be between 1 and 25, got %d", dayInt)
+ }
+
+ dayStr := fmt.Sprintf("%02d", dayInt)
+ fmt.Println(dayStr)
+ return nil
},
}