diff --git a/create.go b/internal/cmd/create.go similarity index 99% rename from create.go rename to internal/cmd/create.go index 45a7305..6f75c32 100644 --- a/create.go +++ b/internal/cmd/create.go @@ -1,4 +1,4 @@ -package main +package cmd import ( "encoding/json" diff --git a/generate.go b/internal/cmd/generate.go similarity index 97% rename from generate.go rename to internal/cmd/generate.go index e63dc2a..2fb2b3f 100644 --- a/generate.go +++ b/internal/cmd/generate.go @@ -1,6 +1,7 @@ -package main +package cmd import ( + "embed" "flag" "fmt" "io" @@ -15,6 +16,9 @@ import ( tf "codeflow.dananglin.me.uk/apollo/spruce/internal/templateFuncs" ) +//go:embed templates/tex/* +var templates embed.FS + type GenerateCommand struct { *flag.FlagSet input string diff --git a/templates/tex/cv.tmpl.tex b/internal/cmd/templates/tex/cv.tmpl.tex similarity index 100% rename from templates/tex/cv.tmpl.tex rename to internal/cmd/templates/tex/cv.tmpl.tex diff --git a/templates/tex/cv_setup.tmpl.tex b/internal/cmd/templates/tex/cv_setup.tmpl.tex similarity index 100% rename from templates/tex/cv_setup.tmpl.tex rename to internal/cmd/templates/tex/cv_setup.tmpl.tex diff --git a/version.go b/internal/cmd/version.go similarity index 53% rename from version.go rename to internal/cmd/version.go index c3a4cfc..fb59aac 100644 --- a/version.go +++ b/internal/cmd/version.go @@ -1,4 +1,4 @@ -package main +package cmd import ( "flag" @@ -7,19 +7,20 @@ import ( type VersionCommand struct { *flag.FlagSet - fullVersion bool -} - -var ( + fullVersion bool binaryVersion string buildTime string goVersion string gitCommit string -) +} -func NewVersionCommand() *VersionCommand { +func NewVersionCommand(binaryVersion, buildTime, goVersion, gitCommit string) *VersionCommand { vc := VersionCommand{ - FlagSet: flag.NewFlagSet("version", flag.ExitOnError), + FlagSet: flag.NewFlagSet("version", flag.ExitOnError), + binaryVersion: binaryVersion, + buildTime: buildTime, + goVersion: goVersion, + gitCommit: gitCommit, } vc.BoolVar(&vc.fullVersion, "full", false, "prints the full version") @@ -37,9 +38,9 @@ func (v *VersionCommand) Run() error { Build date: %s ` - version = fmt.Sprintf(fullVersionFmt, binaryVersion, gitCommit, goVersion, buildTime) + version = fmt.Sprintf(fullVersionFmt, v.binaryVersion, v.gitCommit, v.goVersion, v.buildTime) } else { - version = binaryVersion + "\n" + version = v.binaryVersion + "\n" } fmt.Print(version) diff --git a/main.go b/main.go index e1c2e98..d0ac159 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,10 @@ package main import ( - "embed" "log" "os" + + "codeflow.dananglin.me.uk/apollo/spruce/internal/cmd" ) type Runner interface { @@ -12,14 +13,23 @@ type Runner interface { Run() error } -//go:embed templates/tex/* -var templates embed.FS +var ( + binaryVersion string + buildTime string + goVersion string + gitCommit string +) func main() { commandMap := map[string]Runner{ - "version": NewVersionCommand(), - "generate": NewGenerateCommand(), - "create": NewCreateCommand(), + "version": cmd.NewVersionCommand( + binaryVersion, + buildTime, + goVersion, + gitCommit, + ), + "generate": cmd.NewGenerateCommand(), + "create": cmd.NewCreateCommand(), } subcommand := os.Args[1]