summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-12-19 09:38:08 +0000
committerMatthew Lemon <y@yulqen.org>2024-12-19 09:38:08 +0000
commit82ba7ed82e7c4568d317ce57906f7c6170e10edc (patch)
tree5eab806bc4f57b9c1b01f91d308797af3ca78c4c
parent1d2182a6fbfd3781407fdeae05735d1736737c48 (diff)
Better interface
-rw-r--r--tjp.go30
1 files changed, 17 insertions, 13 deletions
diff --git a/tjp.go b/tjp.go
index 2ff8603..c044338 100644
--- a/tjp.go
+++ b/tjp.go
@@ -51,8 +51,8 @@ func addMODContact(firstName, lastName string) {
fmt.Printf("MOD contact added with ID: %d\n", contactId)
}
-func addSleepEntry(entry string) {
- _, err := db.Exec("INSERT INTO journal_entries (entry, type) VALUES ($1, 4)", entry)
+func addSleepEntry(entry string, journalType int) {
+ _, err := db.Exec("INSERT INTO journal_entries (entry, type) VALUES ('%s', %d)", entry, journalType)
if err != nil {
log.Fatal(err)
}
@@ -85,6 +85,9 @@ func listjournalEntries(orientation string, journalType int) {
} else if journalType == JOURNAL_TYPE_JOBBY {
rows, err = db.Query(fmt.Sprintf("SELECT id, date_added, entry FROM journal_entries WHERE type = %d ORDER BY date_added ASC, id ASC", journalType))
header = "Jobblylog entries:"
+ } else if journalType == JOURNAL_TYPE_SLEEP {
+ rows, err = db.Query(fmt.Sprintf("SELECT id, date_added, entry FROM journal_entries WHERE type = %d ORDER BY date_added ASC, id ASC", journalType))
+ header = "Sleep entries:"
}
if err != nil {
@@ -176,16 +179,15 @@ func main() {
orientationFlag := flag.String("orientation", "horizontal", "Orientation of the journal entries (vertical or horizontal)")
- addSleepEntryFlag := flag.Bool("addSleepEntry", false, "Add a sleep entry")
- sleepEntry := flag.String("sleepEntry", "", "Content of the sleep entry")
-
- addMODEntryFlag := flag.Bool("m", false, "Add a MOD entry")
- addPersonalEntryFlag := flag.Bool("p", false, "Add a Personal entry")
- addJobbylogEntryFlag := flag.Bool("j", false, "Add a Jobbylog entry")
+ addMODEntryFlag := flag.Bool("add-mod", false, "Add a MOD entry")
+ addPersonalEntryFlag := flag.Bool("add-personal", false, "Add a Personal entry")
+ addJobbylogEntryFlag := flag.Bool("add-jobby", false, "Add a Jobbylog entry")
+ addSleepEntryFlag := flag.Bool("add-sleep", false, "Add a sleep entry")
- listPersonalEntriesFlag := flag.Bool("l", false, "List all personal entries")
- listMODEntriesFlag := flag.Bool("M", false, "List all MOD entries, not including those associated with a meeting")
- listJobbylogEntriesFlag := flag.Bool("J", false, "List all Jobblylog entries")
+ listPersonalEntriesFlag := flag.Bool("list-personal", false, "List all personal entries")
+ listMODEntriesFlag := flag.Bool("list-mod", false, "List all MOD entries, not including those associated with a meeting")
+ listJobbylogEntriesFlag := flag.Bool("list-jobby", false, "List all Jobblylog entries")
+ listSleepEntriesFlag := flag.Bool("list-sleep", false, "List all sleep entries")
// Parse flags
flag.Parse()
@@ -197,10 +199,10 @@ func main() {
}
addMODContact(*firstName, *lastName)
} else if *addSleepEntryFlag {
- if *sleepEntry == "" {
+ if *entry == "" {
log.Fatal("Sleep entry content must be provided")
}
- addSleepEntry(*sleepEntry)
+ addSleepEntry(*entry, JOURNAL_TYPE_SLEEP)
} else if *addPersonalEntryFlag {
if *entry == "" {
log.Fatal("Personal entry content must be provided - use the -entry flag")
@@ -221,6 +223,8 @@ func main() {
listjournalEntries(*orientationFlag, JOURNAL_TYPE_MOD)
} else if *listJobbylogEntriesFlag {
listjournalEntries(*orientationFlag, JOURNAL_TYPE_JOBBY)
+ } else if *listSleepEntriesFlag {
+ listjournalEntries(*orientationFlag, JOURNAL_TYPE_SLEEP)
} else {
flag.Usage() // Print usage if no valid flags are provided
os.Exit(1)