Add Repo & Notes fields

This commit is contained in:
Brian Buller 2022-12-08 11:40:53 -06:00
parent b307ed73c5
commit d7904bcba2

View File

@ -11,6 +11,8 @@ type Project struct {
Original string // Original raw project text Original string // Original raw project text
Name string // The name of the project Name string // The name of the project
Directory string // The directory part of the project text Directory string // The directory part of the project text
Notes string // The filename of the notes file, defaults to Directory+/+notes.md
Repo string // The directory to the git repository, defaults to Directory+/+Name
Contexts []string Contexts []string
ProjectTags []string ProjectTags []string
AdditionalTags map[string]string AdditionalTags map[string]string
@ -36,10 +38,26 @@ func ParseProject(text string) (*Project, error) {
} }
project.Name = strings.TrimSpace(project.Name) project.Name = strings.TrimSpace(project.Name)
parts = parts[pIdx:] parts = parts[pIdx:]
var notesAbs, repoAbs bool
project.Notes = "notes.md"
project.Repo = project.Name
for _, v := range parts { for _, v := range parts {
switch v[0] { switch v[0] {
case '^': // Project Directory case '^': // Project Directory
project.Directory = v[1:] project.Directory = v[1:]
if strings.HasSuffix(project.Directory, "/") {
project.Directory = strings.TrimSuffix(project.Directory, "/")
}
case '~': // Project Repo
project.Repo = v[1:]
if strings.HasPrefix(project.Repo, "/") {
repoAbs = true
}
case '#':
project.Notes = v[1:]
if strings.HasPrefix(project.Notes, "/") {
notesAbs = true
}
case '@': // Contexts case '@': // Contexts
project.Contexts = append(project.Contexts, v[1:]) project.Contexts = append(project.Contexts, v[1:])
case '+': // ProjectTags case '+': // ProjectTags
@ -54,6 +72,12 @@ func ParseProject(text string) (*Project, error) {
} }
} }
} }
if !notesAbs {
project.Notes = fmt.Sprintf("%s/%s", project.Directory, project.Notes)
}
if !repoAbs {
project.Repo = fmt.Sprintf("%s/%s", project.Directory, project.Repo)
}
return &project, err return &project, err
} }