fix: add version and print with --version
Add a version variable that is printed to screen with the --version flag. Add a basic Makefile for building and installing spruce.
This commit is contained in:
parent
fa8dbe68e9
commit
52868d7aa8
2 changed files with 42 additions and 5 deletions
21
Makefile
Normal file
21
Makefile
Normal file
|
@ -0,0 +1,21 @@
|
|||
BINARY = spruce
|
||||
INSTALL_PREFIX ?= /usr/local
|
||||
CGO_ENABLED ?= 0
|
||||
GOOS ?= linux
|
||||
GOARCH ?= amd64
|
||||
VERSION = 0.1.0
|
||||
|
||||
LDFLAGS = "-s -w -X main.version=$(VERSION) -X main.installPrefix=$(INSTALL_PREFIX)"
|
||||
|
||||
$(BINARY):
|
||||
go build -ldflags=$(LDFLAGS) -v -a -o $(BINARY)
|
||||
|
||||
install: spruce
|
||||
cp -f $(BINARY) $(INSTALL_PREFIX)/bin
|
||||
chmod 0755 $(INSTALL_PREFIX)/bin/$(BINARY)
|
||||
|
||||
uninstall:
|
||||
rm -f $(INSTALL_PREFIX)/bin/$(BINARY)
|
||||
|
||||
clean:
|
||||
go clean
|
24
main.go
24
main.go
|
@ -19,15 +19,27 @@ import (
|
|||
//go:embed templates/tex/*
|
||||
var templates embed.FS
|
||||
|
||||
var version string
|
||||
|
||||
func main() {
|
||||
var input, output string
|
||||
var employmentHistory int
|
||||
var (
|
||||
input string
|
||||
output string
|
||||
employmentHistory int
|
||||
printVersion bool
|
||||
)
|
||||
|
||||
flag.StringVar(&input, "input", "", "specify the CV JSON file that you want to input to the builder.")
|
||||
flag.StringVar(&output, "output", "", "specify the name of the output CV file.")
|
||||
flag.IntVar(&employmentHistory, "employment-history", 10, "show employment history within these number of years.")
|
||||
flag.BoolVar(&printVersion, "version", false, "print the application version and exit.")
|
||||
flag.Parse()
|
||||
|
||||
if printVersion {
|
||||
Version()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if err := run(input, output, employmentHistory); err != nil {
|
||||
log.Fatalf("ERROR: %v", err)
|
||||
}
|
||||
|
@ -114,14 +126,14 @@ func pdf(tempDir, texFile, output string) error {
|
|||
output = "./cv.pdf"
|
||||
}
|
||||
|
||||
if err := copy(filepath.Join(tempDir, "cv.pdf"), output); err != nil {
|
||||
if err := copyfile(filepath.Join(tempDir, "cv.pdf"), output); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func copy(input, output string) error {
|
||||
func copyfile(input, output string) error {
|
||||
inputFile, err := os.Open(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to open %s; %w", input, err)
|
||||
|
@ -141,3 +153,7 @@ func copy(input, output string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Version() {
|
||||
fmt.Printf("Spruce version %s\n", version)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue