Skip to content

Commit

Permalink
refactor(guide): make logic concise
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jul 23, 2024
1 parent 6fc0dc8 commit 9c2c38e
Showing 1 changed file with 35 additions and 93 deletions.
128 changes: 35 additions & 93 deletions cmd/guide.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,108 +13,48 @@ import (
)

const (
codeBlockMarker = "```"
guideAssetsPathPrefix = "assets/guide"
)

var (
//go:embed assets/guide/*.md
guideFolder embed.FS

guideSummaryRegex = regexp.MustCompile(`[^a-z-]`)

guideEntries = []entry{
{
"guide: welcome to omm",
true,
},
{
"domain: tasks",
true,
},
{
"domain: task state",
true,
},
{
"domain: an archived task",
false,
},
{
"domain: task details",
true,
},
{
"visuals: list density",
true,
},
{
"visuals: toggling context pane",
true,
},
{
"actions: adding tasks",
true,
},
{
"cli: adding a task via the CLI",
true,
},
{
"cli: importing several tasks via the CLI",
true,
},
{
"actions: adding context",
true,
},
{
"actions: filtering tasks",
true,
},
{
"actions: quick filtering via a list",
true,
},
{
"domain: task bookmarks",
true,
},
{
"domain: task priorities",
true,
},
{
"actions: updating task details",
true,
},
{
"config: changing the defaults",
true,
},
{
"config: flags, env vars, and config file",
true,
},
{
"config: a sample TOML config",
true,
},
{
"guide: and that's it!",
true,
},
{summary: "guide: welcome to omm"},
{summary: "domain: tasks"},
{summary: "domain: task state"},
{summary: "domain: an archived task", archived: true},
{summary: "domain: task details"},
{summary: "visuals: list density"},
{summary: "visuals: toggling context pane"},
{summary: "actions: adding tasks"},
{summary: "cli: adding a task via the CLI"},
{summary: "cli: importing several tasks via the CLI"},
{summary: "actions: adding context"},
{summary: "actions: filtering tasks"},
{summary: "actions: quick filtering via a list"},
{summary: "domain: task bookmarks"},
{summary: "domain: task priorities"},
{summary: "actions: updating task details"},
{summary: "config: changing the defaults"},
{summary: "config: flags, env vars, and config file"},
{summary: "config: a sample TOML config"},
{summary: "guide: and that's it!"},
}
)

type entry struct {
summary string
active bool
summary string
archived bool
}

func getContext(summary string) (string, error) {
summary = strings.ToLower(summary)
summary = strings.ReplaceAll(summary, " ", "-")
re := regexp.MustCompile(`[^a-z-]`)
fPath := re.ReplaceAllString(summary, "")
fPath := guideSummaryRegex.ReplaceAllString(summary, "")

ctxBytes, err := guideFolder.ReadFile(fmt.Sprintf("%s/%s.md", guideAssetsPathPrefix, fPath))
if err != nil {
Expand All @@ -136,14 +76,16 @@ func insertGuideTasks(db *sql.DB) error {
for i, e := range guideEntries {
ctxs[i], err = getContext(guideEntries[i].summary)

if err == nil {
tasks[i] = types.Task{
Summary: e.summary,
Context: &ctxs[i],
Active: e.active,
CreatedAt: now,
UpdatedAt: now,
}
if err != nil {
continue
}

tasks[i] = types.Task{
Summary: e.summary,
Context: &ctxs[i],
Active: !e.archived,
CreatedAt: now,
UpdatedAt: now,
}
}

Expand Down

0 comments on commit 9c2c38e

Please sign in to comment.