diff --git a/NOTES.md b/NOTES.md index 8df25d955aad5b4c9c3cba26ac45c619fea2301e..abe4eb113f93adf073c70c7790cdaf0056474a02 100644 --- a/NOTES.md +++ b/NOTES.md @@ -10,7 +10,7 @@ ssh `authorized_keys` should look like this: command="/home/bulletin/bin/bulletin -u alice",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty KEY-TYPE KEY ``` -Have readline store a history file for the user. Configure at the `accounts.Open` step. +Have readline store a history file for the user. Configure at the `users.Open` step. Look up how godoc does references to other things. diff --git a/go.mod b/go.mod index ef5e66584e5598fc3ff29d78b56d626b898ed9b8..09e451465015e300800b86f08c7f6e9d7ad6c86a 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.24.2 require ( github.com/adrg/xdg v0.5.3 + github.com/carlmjohnson/versioninfo v0.22.5 github.com/chzyer/readline v1.5.1 github.com/gdamore/tcell/v2 v2.8.1 github.com/golang-migrate/migrate/v4 v4.18.3 @@ -14,7 +15,6 @@ require ( ) require ( - github.com/carlmjohnson/versioninfo v0.22.5 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/gdamore/encoding v1.0.1 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/main.go b/main.go index 65011cada29ab9c795fc1e7b03c2b5f9d93cf67a..2a66475d8df4ae8d39432c5d4c3a466f13f70576 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ import ( "fmt" "os" - "git.lyda.ie/kevin/bulletin/accounts" + "git.lyda.ie/kevin/bulletin/users" "git.lyda.ie/kevin/bulletin/batch" "git.lyda.ie/kevin/bulletin/repl" @@ -46,7 +46,7 @@ func main() { fmt.Println("ERROR: can only run batch commands as SYSTEM.") os.Exit(1) } - err := accounts.Open(user, cmd.String("name")) + err := users.Open(user, cmd.String("name")) if err != nil { fmt.Printf("ERROR: %s.", err) os.Exit(1) @@ -66,7 +66,7 @@ func main() { os.Exit(exitcode) } - err := accounts.Open(user, cmd.String("name")) + err := users.Open(user, cmd.String("name")) if err != nil { return err } diff --git a/repl/folders.go b/repl/folders.go index 900f8b74dbd806b335238370b975aed3187305ed..d9b23a34a5341d229f575ab37105fd4d37da09b8 100644 --- a/repl/folders.go +++ b/repl/folders.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "git.lyda.ie/kevin/bulletin/accounts" + "git.lyda.ie/kevin/bulletin/users" "git.lyda.ie/kevin/bulletin/dclish" "git.lyda.ie/kevin/bulletin/folders" ) @@ -15,7 +15,7 @@ import ( // ActionIndex handles the `INDEX` command. This lists all the folders. func ActionIndex(_ *dclish.Command) error { options := folders.FolderListOptions{} - rows, err := accounts.User.Folders.ListFolder(accounts.User.Login, options) + rows, err := users.User.Folders.ListFolder(users.User.Login, options) if err != nil { return err } @@ -46,7 +46,7 @@ func ActionCreate(cmd *dclish.Command) error { if cmd.Flags["/OWNER"].Value != "" { options.Owner = cmd.Flags["/OWNER"].Value } else { - options.Owner = accounts.User.Login + options.Owner = users.User.Login } if cmd.Flags["/READNEW"].Value == "true" { options.Readnew = 1 @@ -78,7 +78,7 @@ func ActionCreate(cmd *dclish.Command) error { // Verify options... if options.Description == "" { var err error - options.Description, err = accounts.GetLine("Enter one line description of folder: ") + options.Description, err = users.GetLine("Enter one line description of folder: ") if err != nil { return nil } @@ -86,7 +86,7 @@ func ActionCreate(cmd *dclish.Command) error { if options.Description == "" || len(options.Description) > 53 { return errors.New("Description must exist and be under 53 characters") } - err := accounts.User.Folders.CreateFolder(cmd.Args[0], options) + err := users.User.Folders.CreateFolder(cmd.Args[0], options) // TODO: handle the /ID flag. return err } @@ -96,12 +96,12 @@ func ActionSelect(cmd *dclish.Command) error { if strings.Contains(cmd.Args[0], "%") { return errors.New("Folder name cannot contain a %") } - folder := accounts.User.Folders.FindFolder(cmd.Args[0]) + folder := users.User.Folders.FindFolder(cmd.Args[0]) if folder == "" { return errors.New("Unable to select the folder") } - if accounts.User.Folders.IsFolderAccess(folder, accounts.User.Login) { - accounts.User.CurrentFolder = folder + if users.User.Folders.IsFolderAccess(folder, users.User.Login) { + users.User.CurrentFolder = folder fmt.Printf("Folder has been set to '%s'.\n", folder) return nil } @@ -119,7 +119,7 @@ func ActionModify(cmd *dclish.Command) error { // ActionRemove handles the `REMOVE` command. This modifies a folder. func ActionRemove(cmd *dclish.Command) error { - err := accounts.User.Folders.DeleteFolder(cmd.Args[0]) + err := users.User.Folders.DeleteFolder(cmd.Args[0]) if err == nil { fmt.Println("Folder removed.") } diff --git a/repl/messages.go b/repl/messages.go index ae292944a4f57175362566136746454e4d3c3128..f9e05e8c09438f244f7ce1e2d1cd1c900bd0117f 100644 --- a/repl/messages.go +++ b/repl/messages.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "git.lyda.ie/kevin/bulletin/accounts" + "git.lyda.ie/kevin/bulletin/users" "git.lyda.ie/kevin/bulletin/dclish" "git.lyda.ie/kevin/bulletin/editor" ) @@ -21,20 +21,20 @@ func ActionDirectory(cmd *dclish.Command) error { if strings.Contains(cmd.Args[0], "%") { return errors.New("Folder name cannot contain a %") } - folder := accounts.User.Folders.FindFolder(cmd.Args[0]) + folder := users.User.Folders.FindFolder(cmd.Args[0]) if folder == "" { return errors.New("Unable to select the folder") } - if !accounts.User.Folders.IsFolderAccess(folder, accounts.User.Login) { + if !users.User.Folders.IsFolderAccess(folder, users.User.Login) { // TODO: Should be: // WRITE(6,'('' You are not allowed to access folder.'')') // WRITE(6,'('' See '',A,'' if you wish to access folder.'')') return errors.New("Unable to select the folder") } - accounts.User.CurrentFolder = folder + users.User.CurrentFolder = folder } - msgs, err := accounts.User.Folders.ListMessages( - accounts.User.CurrentFolder, nil) + msgs, err := users.User.Folders.ListMessages( + users.User.CurrentFolder, nil) if err != nil { return err } @@ -129,11 +129,11 @@ func ActionAdd(cmd *dclish.Command) error { fmt.Printf("TODO: optSystem is not yet implemented - you set it to %d\n", optSystem) if len(optFolder) == 0 { - optFolder = []string{accounts.User.CurrentFolder} + optFolder = []string{users.User.CurrentFolder} } // TODO: check if folders exist. if optSubject == "" { - optSubject, _ = accounts.GetLine("Enter subject of message: ") + optSubject, _ = users.GetLine("Enter subject of message: ") if optSubject == "" { return errors.New("Must enter a subject") } @@ -145,7 +145,7 @@ func ActionAdd(cmd *dclish.Command) error { return err } for i := range optFolder { - err = accounts.User.Folders.CreateMessage(accounts.User.Login, optSubject, message, + err = users.User.Folders.CreateMessage(users.User.Login, optSubject, message, optFolder[i], optPermanent, optShutdown, optExpiration) } return nil @@ -183,8 +183,8 @@ func ActionNext(cmd *dclish.Command) error { // ActionRead handles the `READ` command. func ActionRead(cmd *dclish.Command) error { - // TODO: We need to set accounts.User.CurrentMessage when we change folder. - msgid := accounts.User.CurrentMessage + // TODO: We need to set users.User.CurrentMessage when we change folder. + msgid := users.User.CurrentMessage if len(cmd.Args) == 1 { var err error msgid, err = strconv.Atoi(cmd.Args[0]) @@ -192,12 +192,12 @@ func ActionRead(cmd *dclish.Command) error { return err } } - msg, err := accounts.User.Folders.ReadMessage( - accounts.User.Login, accounts.User.CurrentFolder, msgid) + msg, err := users.User.Folders.ReadMessage( + users.User.Login, users.User.CurrentFolder, msgid) if err != nil { return err } - // TODO: update accounts.User.CurrentMessage + // TODO: update users.User.CurrentMessage fmt.Printf("%s\n", msg) return nil } diff --git a/repl/misc.go b/repl/misc.go index 0bb3a730a1739c9e7427221f2b61eda1cc483b24..8a7d5e7c67f96efcb13f3926bc530667e1f4ee4c 100644 --- a/repl/misc.go +++ b/repl/misc.go @@ -5,13 +5,13 @@ import ( "fmt" "os" - "git.lyda.ie/kevin/bulletin/accounts" + "git.lyda.ie/kevin/bulletin/users" "git.lyda.ie/kevin/bulletin/dclish" ) // ActionQuit handles the `QUIT` command. func ActionQuit(_ *dclish.Command) error { - accounts.User.Close() + users.User.Close() // TODO: IIRC, quit should not update unread data. Check old code to confirm. fmt.Println("QUIT") os.Exit(0) @@ -20,7 +20,7 @@ func ActionQuit(_ *dclish.Command) error { // ActionExit handles the `EXIT` command. func ActionExit(_ *dclish.Command) error { - accounts.User.Close() + users.User.Close() // TODO: update unread data. fmt.Println("EXIT") os.Exit(0) diff --git a/repl/repl.go b/repl/repl.go index 2a11baa3644c2f982f5d1273b0023baa4f75e45a..5dda56ef593915e7850593d7cfb7fd66b9cfa28c 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -6,7 +6,7 @@ import ( "path" "unicode" - "git.lyda.ie/kevin/bulletin/accounts" + "git.lyda.ie/kevin/bulletin/users" "github.com/adrg/xdg" "github.com/chzyer/readline" ) @@ -18,7 +18,7 @@ func Loop() error { &readline.Config{ Prompt: "BULLETIN> ", HistoryFile: path.Join(xdg.ConfigHome, "BULLETIN", - fmt.Sprintf("%s.history", accounts.User.Login)), + fmt.Sprintf("%s.history", users.User.Login)), // TODO: AutoComplete: completer, InterruptPrompt: "^C", EOFPrompt: "EXIT", diff --git a/repl/set.go b/repl/set.go index bc6d276aebccadb0d5595fd846ecabe1661c7907..d947b071bbb7f9835007e7578fa9e36665fd612b 100644 --- a/repl/set.go +++ b/repl/set.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "git.lyda.ie/kevin/bulletin/accounts" + "git.lyda.ie/kevin/bulletin/users" "git.lyda.ie/kevin/bulletin/dclish" ) @@ -61,12 +61,12 @@ func ActionSetFolder(cmd *dclish.Command) error { if strings.Contains(cmd.Args[0], "%") { return errors.New("Folder name cannot contain a %") } - folder := accounts.User.Folders.FindFolder(cmd.Args[0]) + folder := users.User.Folders.FindFolder(cmd.Args[0]) if folder == "" { return errors.New("Unable to select the folder") } - if accounts.User.Folders.IsFolderAccess(folder, accounts.User.Login) { - accounts.User.CurrentFolder = folder + if users.User.Folders.IsFolderAccess(folder, users.User.Login) { + users.User.CurrentFolder = folder fmt.Printf("Folder has been set to '%s'.\n", folder) return nil } diff --git a/users/users.go b/users/users.go index a175e1acd3bcde672f5d90a0fedc880f377c2556..4b2c99ff5b91276030db439dccb773ce49ee2cef 100644 --- a/users/users.go +++ b/users/users.go @@ -1,4 +1,4 @@ -// Package users manages accounts. +// Package users manages users. package users import (