Compare commits
No commits in common. "54d5fa1831fdbaea618b530a788136f6b972fc54" and "2c57c3c278760ea2ca727ce6b0e8acf0b3a8ab58" have entirely different histories.
54d5fa1831
...
2c57c3c278
6 changed files with 4 additions and 139 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -43,5 +43,4 @@ tags
|
|||
[._]*.un~
|
||||
|
||||
cv.pdf
|
||||
cv.json
|
||||
spruce
|
||||
|
|
122
create.go
122
create.go
|
@ -1,122 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/spruce/internal/cv"
|
||||
)
|
||||
|
||||
type CreateCommand struct {
|
||||
*flag.FlagSet
|
||||
firstName string
|
||||
lastName string
|
||||
jobTitle string
|
||||
filename string
|
||||
}
|
||||
|
||||
func NewCreateCommand() *CreateCommand {
|
||||
cc := CreateCommand{
|
||||
FlagSet: flag.NewFlagSet("create", flag.ExitOnError),
|
||||
}
|
||||
|
||||
cc.StringVar(&cc.firstName, "first-name", "", "specify your first name")
|
||||
cc.StringVar(&cc.lastName, "last-name", "", "specify your last name")
|
||||
cc.StringVar(&cc.jobTitle, "job-title", "", "specify your preferred job title")
|
||||
cc.StringVar(&cc.filename, "filename", "cv.json", "specify the filename of the created JSON document")
|
||||
|
||||
return &cc
|
||||
}
|
||||
|
||||
func (c *CreateCommand) Run() error {
|
||||
data := cv.NewCV(c.firstName, c.lastName, c.jobTitle)
|
||||
|
||||
data.Contact = map[string]string{
|
||||
"Email": "",
|
||||
"Phone": "",
|
||||
}
|
||||
|
||||
data.Links = map[string]string{
|
||||
"GitHub": "",
|
||||
"Website": "",
|
||||
}
|
||||
|
||||
data.Summary = make([]string, 2)
|
||||
|
||||
data.Skills = []cv.Skills{
|
||||
{
|
||||
Category: "",
|
||||
Values: make([]string, 1),
|
||||
},
|
||||
{
|
||||
Category: "",
|
||||
Values: make([]string, 1),
|
||||
},
|
||||
}
|
||||
|
||||
data.Employment = []cv.Experience{
|
||||
{
|
||||
Company: "",
|
||||
Location: "",
|
||||
JobTitle: "",
|
||||
Duration: cv.Duration{
|
||||
Start: cv.Date{
|
||||
Year: time.Now().Year(),
|
||||
Month: int(time.Now().Month()),
|
||||
Day: time.Now().Day(),
|
||||
},
|
||||
End: cv.Date{
|
||||
Year: time.Now().Year(),
|
||||
Month: int(time.Now().Month()),
|
||||
Day: time.Now().Day(),
|
||||
},
|
||||
Present: false,
|
||||
},
|
||||
Details: make([]string, 2),
|
||||
},
|
||||
}
|
||||
|
||||
data.Education = []cv.Experience{
|
||||
{
|
||||
School: "",
|
||||
Location: "",
|
||||
Qualification: "",
|
||||
Duration: cv.Duration{
|
||||
Start: cv.Date{
|
||||
Year: time.Now().Year(),
|
||||
Month: int(time.Now().Month()),
|
||||
Day: time.Now().Day(),
|
||||
},
|
||||
End: cv.Date{
|
||||
Year: time.Now().Year(),
|
||||
Month: int(time.Now().Month()),
|
||||
Day: time.Now().Day(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
data.Interests = make([]string, 2)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
log.Printf("INFO: Successfully written the new CV to %s\n", file.Name())
|
||||
|
||||
return nil
|
||||
}
|
|
@ -63,7 +63,7 @@ func (g *GenerateCommand) Run() error {
|
|||
|
||||
// tex generates the CV document as a Tex file.
|
||||
func tex(input, tempDir string, historyLimit time.Time) (string, error) {
|
||||
c, err := cv.NewCVFromFile(input)
|
||||
c, err := cv.NewCV(input)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to create a new CV value from %s; %w", input, err)
|
||||
}
|
||||
|
|
|
@ -6,13 +6,12 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
// NewCVFromFile returns a new CV value from the given JSON file.
|
||||
func NewCVFromFile(path string) (CV, error) {
|
||||
// NewCV returns a new CV value from the given JSON file.
|
||||
func NewCV(path string) (CV, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return CV{}, fmt.Errorf("unable to open %s; %w", path, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
decoder := json.NewDecoder(file)
|
||||
|
||||
|
@ -24,13 +23,3 @@ func NewCVFromFile(path string) (CV, error) {
|
|||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func NewCV(firstName, lastName, jobTitle string) CV {
|
||||
cv := CV{
|
||||
FirstName: firstName,
|
||||
LastName: lastName,
|
||||
JobTitle: jobTitle,
|
||||
}
|
||||
|
||||
return cv
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func Install() error {
|
|||
|
||||
// Clean cleans the workspace
|
||||
func Clean() error {
|
||||
files := []string{binary, "cv.pdf", "cv.json"}
|
||||
files := []string{binary, "cv.pdf"}
|
||||
|
||||
for i := range files {
|
||||
if err := sh.Rm(files[i]); err != nil {
|
||||
|
|
1
main.go
1
main.go
|
@ -19,7 +19,6 @@ func main() {
|
|||
commandMap := map[string]Runner{
|
||||
"version": NewVersionCommand(),
|
||||
"generate": NewGenerateCommand(),
|
||||
"create": NewCreateCommand(),
|
||||
}
|
||||
|
||||
subcommand := os.Args[1]
|
||||
|
|
Loading…
Reference in a new issue