spruce/internal/pdf/pdf.go
Dan Anglin 71d62ecaf6
refactor: add golangci-lint with code refactoring
Add golangci-lint for linting and refactor the code based on the
feedback from running it.

Changes:

- Add configuration for golangci-lint.
- Break the large function in create.go into smaller ones.
- Rename internal/templateFuncs to internal/templatefuncs to remove
  upper case letters in the package name.
- Add a mage target for lint tests.
2023-08-21 03:07:06 +01:00

40 lines
876 B
Go

package pdf
import (
"fmt"
"log/slog"
"os"
"os/exec"
"path/filepath"
"time"
)
// Generate generates the CV PDF document from the JSON file.
func Generate(tempDir, input string, historyLimit time.Time, verbose bool) (string, error) {
texFileName, err := tex(input, tempDir, historyLimit)
if err != nil {
return "", fmt.Errorf("unable to create the tex file; %w", err)
}
slog.Info("Creating the PDF document.")
pathArg := "--path=" + tempDir
command := exec.Command("mtxrun", pathArg, "--script", "context", texFileName)
if verbose {
command.Stderr = os.Stderr
command.Stdout = os.Stdout
}
if err := command.Run(); err != nil {
return "", fmt.Errorf("an error occurred when creating the PDF file; %w", err)
}
output := filepath.Join(tempDir, "cv.pdf")
slog.Info("PDF document successfully created.", "filename", output)
return output, nil
}