diff options
author | Matthew Lemon <y@yulqen.org> | 2024-12-19 09:29:39 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-12-19 09:29:39 +0000 |
commit | 1d2182a6fbfd3781407fdeae05735d1736737c48 (patch) | |
tree | 2bb5018e1648f529fe9e3cae7995b77a1a05909c | |
parent | e2a2551d7cc40cf669086a0c9453df18ab341fb1 (diff) |
Updates and removed comment from list output for now.
-rw-r--r-- | tjp.go | 38 |
1 files changed, 23 insertions, 15 deletions
@@ -72,17 +72,19 @@ func listjournalEntries(orientation string, journalType int) { var id sql.NullInt64 var dateAdded sql.NullTime var entry sql.NullString - var comment sql.NullString var header string var err error // if MOD journalType if journalType == JOURNAL_TYPE_MOD { - rows, err = db.Query(fmt.Sprintf("SELECT id, date_added, entry, comment FROM journal_entries WHERE type = %d AND meeting_id IS NULL ORDER BY date_added ASC, id ASC", journalType)) + rows, err = db.Query(fmt.Sprintf("SELECT id, date_added, entry FROM journal_entries WHERE type = %d AND meeting_id IS NULL ORDER BY date_added ASC, id ASC", journalType)) header = "MOD entries:" } else if journalType == JOURNAL_TYPE_PERSONAL { - rows, err = db.Query(fmt.Sprintf("SELECT id, date_added, entry, comment FROM journal_entries WHERE type = %d ORDER BY date_added ASC, id ASC", journalType)) + 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 = "Personal entries:" + } 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:" } if err != nil { @@ -96,7 +98,7 @@ func listjournalEntries(orientation string, journalType int) { // Scan for each row for rows.Next() { - if err := rows.Scan(&id, &dateAdded, &entry, &comment); err != nil { + if err := rows.Scan(&id, &dateAdded, &entry); err != nil { log.Fatal(err) } @@ -106,9 +108,9 @@ func listjournalEntries(orientation string, journalType int) { } if orientation == "vertical" { - formatVertically(id, dateAdded, entry, comment) + formatVertically(id, dateAdded, entry) } else if orientation == "horizontal" { - formatHorizontally(dateAdded, entry, comment) + formatHorizontally(dateAdded, entry) } previousDateAdded = dateAdded // Update previousDateAdded to current date @@ -120,15 +122,14 @@ func sameDay(t1, t2 time.Time) bool { return t1.Year() == t2.Year() && t1.YearDay() == t2.YearDay() } -func formatVertically(id sql.NullInt64, dateAdded sql.NullTime, entry sql.NullString, comment sql.NullString) { +func formatVertically(id sql.NullInt64, dateAdded sql.NullTime, entry sql.NullString) { fmt.Printf("ID: %s\n", formatInt64(id)) fmt.Printf("Date Added: %s\n", formatTime(dateAdded)) fmt.Printf("Entry: %s\n", formatString(entry)) - fmt.Printf("Comment: %s\n", formatString(comment)) } -func formatHorizontally(dateAdded sql.NullTime, entry sql.NullString, comment sql.NullString) { - fmt.Printf("%s %s | %s | %s\n", formatShortTime(dateAdded), getWeekdayFromDate(dateAdded), formatString(entry), formatString(comment)) +func formatHorizontally(dateAdded sql.NullTime, entry sql.NullString) { + fmt.Printf("%s %s | %s\n", formatShortTime(dateAdded), getWeekdayFromDate(dateAdded), formatString(entry)) } func getWeekdayFromDate(date sql.NullTime) string { @@ -178,12 +179,13 @@ func main() { addSleepEntryFlag := flag.Bool("addSleepEntry", false, "Add a sleep entry") sleepEntry := flag.String("sleepEntry", "", "Content of the sleep entry") - addPersonalEntryFlag := flag.Bool("p", false, "Add a personal 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") 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") // Parse flags flag.Parse() @@ -208,11 +210,17 @@ func main() { if *entry == "" { log.Fatal("MOD entry content must be provided - use the -entry flag") } - addJournalEntry(*entry, JOURNAL_TYPE_MOD) + } else if *addJobbylogEntryFlag { + if *entry == "" { + log.Fatal("Jobblylog entry content must be provided - use the -entry flag") + } + addJournalEntry(*entry, JOURNAL_TYPE_JOBBY) } else if *listPersonalEntriesFlag { - listjournalEntries(*orientationFlag, 2) + listjournalEntries(*orientationFlag, JOURNAL_TYPE_PERSONAL) } else if *listMODEntriesFlag { - listjournalEntries(*orientationFlag, 1) + listjournalEntries(*orientationFlag, JOURNAL_TYPE_MOD) + } else if *listJobbylogEntriesFlag { + listjournalEntries(*orientationFlag, JOURNAL_TYPE_JOBBY) } else { flag.Usage() // Print usage if no valid flags are provided os.Exit(1) |