diff options
author | Matthew Lemon <y@yulqen.org> | 2024-12-19 21:30:08 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-12-19 21:30:08 +0000 |
commit | ad96831a072d192b34aa897473b5df3fb673cf07 (patch) | |
tree | b136b322e9426ec9e1bdd9ee96d83eb7aed587df | |
parent | 9f7a724a07b170e72760a9d9ea47e6ddae69f649 (diff) |
splits up add and list into subcommands - wip
-rw-r--r-- | tjp.go | 66 |
1 files changed, 55 insertions, 11 deletions
@@ -189,27 +189,71 @@ func main() { firstName := flag.String("firstName", "", "First name of the contact") lastName := flag.String("lastName", "", "Last name of the contact") - entry := flag.String("entry", "", "Content of the journal entry") - dateOfEntry := flag.String("date", "", "Date of entry") + // orientationFlag is used to set the orientation of the journal entries (vertical or horizontal) orientationFlag := flag.String("orientation", "horizontal", "Orientation of the journal entries (vertical or horizontal)") - addMODMeetingFlag := flag.Bool("add-meeting", false, "Add a MOD meeting") + addMODMeetingFlag := flag.Bool("addmeeting", false, "Add a MOD meeting") - 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") + addMODEntryFlag := flag.Bool("addmod", false, "Add a MOD entry") + addJobbylogEntryFlag := flag.Bool("addjobby", false, "Add a Jobbylog entry") + addSleepEntryFlag := flag.Bool("addsleep", false, "Add a sleep entry") - 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") + listPersonalEntriesFlag := flag.Bool("listpersonal", false, "List all personal entries") + listMODEntriesFlag := flag.Bool("listmod", false, "List all MOD entries, not including those associated with a meeting") + listJobbylogEntriesFlag := flag.Bool("listjobby", false, "List all Jobblylog entries") + listSleepEntriesFlag := flag.Bool("listsleep", false, "List all sleep entries") // Parse flags flag.Parse() + // TODO: Break these up into subcommands: + // - add + // - list + // - update + // - delete + // ref: https://www.golinuxcloud.com/golang-flags-examples/ + + // add commands + addCmd := flag.NewFlagSet("add", flag.ExitOnError) + + // add flags + addPersonalEntryFlag := addCmd.Bool("personal", false, "Add a Personal entry") + entry := addCmd.String("entry", "", "Content of the journal entry") + + // list commands + listCmd := flag.NewFlagSet("list", flag.ExitOnError) + + if len(os.Args) < 2 { + fmt.Println("expected 'add' or 'list' subcommands") + os.Exit(1) + } + + switch os.Args[1] { + case "add": + addCmd.Parse(os.Args[2:]) + // create personal entry + if *addPersonalEntryFlag { + if *entry == "" { + log.Fatal("Personal entry content must be provided - use the -entry flag") + } + addJournalEntry(*entry, JOURNAL_TYPE_PERSONAL) + } + // create MOD entry + if *addMODEntryFlag { + if *entry == "" { + log.Fatal("MOD entry content must be provided - use the -entry flag") + } + addJournalEntry(*entry, JOURNAL_TYPE_MOD) + } + case "list": + listCmd.Parse(os.Args[2:]) + default: + flag.PrintDefaults() + os.Exit(1) + } + // Call functions based on flags if *addMODFlag { if *firstName == "" || *lastName == "" { |