2023-08-12 10:26:23 +01:00
|
|
|
package cmd
|
2023-08-12 09:43:45 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2023-08-12 12:02:44 +01:00
|
|
|
"log/slog"
|
2023-08-12 09:43:45 +01:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"codeflow.dananglin.me.uk/apollo/spruce/internal/cv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CreateCommand struct {
|
|
|
|
*flag.FlagSet
|
2023-08-13 17:45:33 +01:00
|
|
|
summary string
|
2023-08-12 09:43:45 +01:00
|
|
|
firstName string
|
|
|
|
lastName string
|
|
|
|
jobTitle string
|
|
|
|
filename string
|
|
|
|
}
|
|
|
|
|
2023-08-20 06:14:10 +01:00
|
|
|
func NewCreateCommand(name, summary string) *CreateCommand {
|
|
|
|
command := CreateCommand{
|
|
|
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
|
|
|
summary: summary,
|
2023-08-12 09:43:45 +01:00
|
|
|
}
|
|
|
|
|
2023-08-20 06:14:10 +01:00
|
|
|
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.")
|
2023-08-13 17:45:33 +01:00
|
|
|
|
2023-08-20 06:14:10 +01:00
|
|
|
command.Usage = usageFunc(command.Name(), command.summary, command.FlagSet)
|
2023-08-12 09:43:45 +01:00
|
|
|
|
2023-08-20 06:14:10 +01:00
|
|
|
return &command
|
2023-08-12 09:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CreateCommand) Run() error {
|
2023-08-21 03:07:06 +01:00
|
|
|
detailLen := 2
|
2023-08-12 09:43:45 +01:00
|
|
|
data := cv.NewCV(c.firstName, c.lastName, c.jobTitle)
|
|
|
|
|
2023-08-21 03:07:06 +01:00
|
|
|
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{
|
2023-08-12 09:43:45 +01:00
|
|
|
"Email": "",
|
|
|
|
"Phone": "",
|
|
|
|
}
|
2023-08-21 03:07:06 +01:00
|
|
|
}
|
2023-08-12 09:43:45 +01:00
|
|
|
|
2023-08-21 03:07:06 +01:00
|
|
|
func links() map[string]string {
|
|
|
|
return map[string]string{
|
2023-08-12 09:43:45 +01:00
|
|
|
"GitHub": "",
|
|
|
|
"Website": "",
|
|
|
|
}
|
2023-08-21 03:07:06 +01:00
|
|
|
}
|
2023-08-12 09:43:45 +01:00
|
|
|
|
2023-08-21 03:07:06 +01:00
|
|
|
func skills() []cv.Skills {
|
|
|
|
return []cv.Skills{
|
2023-08-12 09:43:45 +01:00
|
|
|
{
|
|
|
|
Category: "",
|
|
|
|
Values: make([]string, 1),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Category: "",
|
|
|
|
Values: make([]string, 1),
|
|
|
|
},
|
|
|
|
}
|
2023-08-21 03:07:06 +01:00
|
|
|
}
|
2023-08-12 09:43:45 +01:00
|
|
|
|
2023-08-21 03:07:06 +01:00
|
|
|
func employment(detailLen int) []cv.Employment {
|
|
|
|
return []cv.Employment{
|
2023-08-12 09:43:45 +01:00
|
|
|
{
|
2023-08-15 17:25:00 +01:00
|
|
|
Company: "",
|
|
|
|
Location: "",
|
|
|
|
LocationType: "",
|
|
|
|
JobTitle: "",
|
2023-08-12 09:43:45 +01:00
|
|
|
Duration: cv.Duration{
|
|
|
|
Start: cv.Date{
|
2023-08-18 23:42:01 +01:00
|
|
|
Day: int64(time.Now().Day()),
|
|
|
|
Month: int64(time.Now().Month()),
|
|
|
|
Year: int64(time.Now().Year()),
|
2023-08-12 09:43:45 +01:00
|
|
|
},
|
2023-08-18 23:42:01 +01:00
|
|
|
End: &cv.Date{
|
|
|
|
Day: int64(time.Now().Day()),
|
|
|
|
Month: int64(time.Now().Month()),
|
|
|
|
Year: int64(time.Now().Year()),
|
2023-08-12 09:43:45 +01:00
|
|
|
},
|
|
|
|
Present: false,
|
|
|
|
},
|
2023-08-21 03:07:06 +01:00
|
|
|
Details: make([]string, detailLen),
|
2023-08-12 09:43:45 +01:00
|
|
|
},
|
|
|
|
}
|
2023-08-21 03:07:06 +01:00
|
|
|
}
|
2023-08-12 09:43:45 +01:00
|
|
|
|
2023-08-21 03:07:06 +01:00
|
|
|
func education() []cv.Education {
|
|
|
|
return []cv.Education{
|
2023-08-12 09:43:45 +01:00
|
|
|
{
|
|
|
|
School: "",
|
|
|
|
Location: "",
|
|
|
|
Qualification: "",
|
|
|
|
Duration: cv.Duration{
|
|
|
|
Start: cv.Date{
|
2023-08-18 23:42:01 +01:00
|
|
|
Year: int64(time.Now().Year()),
|
|
|
|
Month: int64(time.Now().Month()),
|
|
|
|
Day: int64(time.Now().Day()),
|
2023-08-12 09:43:45 +01:00
|
|
|
},
|
2023-08-18 23:42:01 +01:00
|
|
|
End: &cv.Date{
|
|
|
|
Year: int64(time.Now().Year()),
|
|
|
|
Month: int64(time.Now().Month()),
|
|
|
|
Day: int64(time.Now().Day()),
|
2023-08-12 09:43:45 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|