Dan Anglin
71d62ecaf6
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.
142 lines
2.9 KiB
Go
142 lines
2.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"time"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/spruce/internal/cv"
|
|
)
|
|
|
|
type CreateCommand struct {
|
|
*flag.FlagSet
|
|
summary string
|
|
firstName string
|
|
lastName string
|
|
jobTitle string
|
|
filename string
|
|
}
|
|
|
|
func NewCreateCommand(name, summary string) *CreateCommand {
|
|
command := CreateCommand{
|
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
|
summary: summary,
|
|
}
|
|
|
|
command.StringVar(&command.filename, "filepath", "cv.json", "specify the output path of the CV JSON file.")
|
|
command.StringVar(&command.firstName, "first-name", "", "specify your first name.")
|
|
command.StringVar(&command.jobTitle, "job-title", "", "specify your current job title.")
|
|
command.StringVar(&command.lastName, "last-name", "", "specify your last name.")
|
|
|
|
command.Usage = usageFunc(command.Name(), command.summary, command.FlagSet)
|
|
|
|
return &command
|
|
}
|
|
|
|
func (c *CreateCommand) Run() error {
|
|
detailLen := 2
|
|
data := cv.NewCV(c.firstName, c.lastName, c.jobTitle)
|
|
|
|
data.Contact = contact()
|
|
data.Links = links()
|
|
data.Summary = make([]string, detailLen)
|
|
data.Skills = skills()
|
|
data.Employment = employment(detailLen)
|
|
data.Education = education()
|
|
data.Interests = make([]string, detailLen)
|
|
|
|
file, err := os.Create(c.filename)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to open %s; %w", c.filename, err)
|
|
}
|
|
defer file.Close()
|
|
|
|
encoder := json.NewEncoder(file)
|
|
|
|
encoder.SetIndent("", " ")
|
|
|
|
if err := encoder.Encode(data); err != nil {
|
|
return fmt.Errorf("unable to write the data to %s; %w", c.filename, err)
|
|
}
|
|
|
|
slog.Info("CV successfully created", "filename", file.Name())
|
|
|
|
return nil
|
|
}
|
|
|
|
func contact() map[string]string {
|
|
return map[string]string{
|
|
"Email": "",
|
|
"Phone": "",
|
|
}
|
|
}
|
|
|
|
func links() map[string]string {
|
|
return map[string]string{
|
|
"GitHub": "",
|
|
"Website": "",
|
|
}
|
|
}
|
|
|
|
func skills() []cv.Skills {
|
|
return []cv.Skills{
|
|
{
|
|
Category: "",
|
|
Values: make([]string, 1),
|
|
},
|
|
{
|
|
Category: "",
|
|
Values: make([]string, 1),
|
|
},
|
|
}
|
|
}
|
|
|
|
func employment(detailLen int) []cv.Employment {
|
|
return []cv.Employment{
|
|
{
|
|
Company: "",
|
|
Location: "",
|
|
LocationType: "",
|
|
JobTitle: "",
|
|
Duration: cv.Duration{
|
|
Start: cv.Date{
|
|
Day: int64(time.Now().Day()),
|
|
Month: int64(time.Now().Month()),
|
|
Year: int64(time.Now().Year()),
|
|
},
|
|
End: &cv.Date{
|
|
Day: int64(time.Now().Day()),
|
|
Month: int64(time.Now().Month()),
|
|
Year: int64(time.Now().Year()),
|
|
},
|
|
Present: false,
|
|
},
|
|
Details: make([]string, detailLen),
|
|
},
|
|
}
|
|
}
|
|
|
|
func education() []cv.Education {
|
|
return []cv.Education{
|
|
{
|
|
School: "",
|
|
Location: "",
|
|
Qualification: "",
|
|
Duration: cv.Duration{
|
|
Start: cv.Date{
|
|
Year: int64(time.Now().Year()),
|
|
Month: int64(time.Now().Month()),
|
|
Day: int64(time.Now().Day()),
|
|
},
|
|
End: &cv.Date{
|
|
Year: int64(time.Now().Year()),
|
|
Month: int64(time.Now().Month()),
|
|
Day: int64(time.Now().Day()),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|