Unverified Commit 183c331b authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Cleaned up SET and SHOW

parent 75e1af68
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ repl.commands?
    * Commands for a local mail system?
    * Commands to connect to Mattermost or mastodon?
    * Commands to manage users.
  * `SHOW VERSION` - versioninfo doesn't work; what else?
  * `SHOW VERSION` - [versioninfo](https://github.com/earthboundkid/versioninfo) will work for go install.
  * Check db version; notify user if it changes; refuse to write to db if it has.

## Module links
+8 −5
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ func ValidName(login string) error {
}

// Open verifies that an account exists.
func Open(login string) error {
func Open(login, name string) error {
	err := ValidName(login)
	if err != nil {
		return err
@@ -55,11 +55,14 @@ func Open(login string) error {
		user.Login = login
		user.Admin = 0

		user.Name = name
		if name == "" {
			fmt.Printf("Welcome new user %s\n", login)
			user.Name, err = GetLine("please enter your name: ")
			if err != nil {
				return err
			}
		}

		err = User.Folders.AddUser(*user)
		if err != nil {
+21 −5
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ type Command struct {
	Args        []string
	MaxArgs     int
	MinArgs     int
	Commands    []*Command
	Commands    Commands
	Action      ActionFunc
	Description string
}
@@ -108,11 +108,13 @@ func split(line string) []string {

// ParseAndRun parses a command line and runs the command.
func (c Commands) ParseAndRun(line string) error {
	// TODO: this doesn't handle a DCL command line completely.
	// Split into words.
	words := split(line)
	cmd, ok := c[strings.ToUpper(words[0])]
	if !ok {

	// Find the command.
	wordup := strings.ToUpper(words[0])
	cmd, ok := c[wordup]
	if !ok {
		possibles := []string{}
		for word := range c {
			if strings.HasPrefix(word, wordup) {
@@ -124,13 +126,26 @@ func (c Commands) ParseAndRun(line string) error {
			fmt.Printf("ERROR: Unknown command '%s'\n", words[0])
			return nil
		case 1:
			cmd = c[possibles[0]]
			wordup = possibles[0]
			cmd = c[wordup]
		default:
			fmt.Printf("ERROR: Ambiguous command '%s' (matches %s)\n",
				words[0], strings.Join(possibles, ", "))
			return nil
		}
	}

	// Deal with subcommands.
	if len(cmd.Commands) > 0 {
		if len(words) == 1 {
			fmt.Printf("ERROR: missing subcommand for %s.\n", wordup)
			return nil
		}
		// TODO: quoting is probably an issue here - break ParseAndRun into ParseAndRun + Run.
		newline := strings.Join(words[1:], " ")
		return cmd.Commands.ParseAndRun(newline)
	}

	if cmd.Action == nil {
		fmt.Printf("ERROR: Command not implemented:\n%s\n", cmd.Description)
		return nil
@@ -139,6 +154,7 @@ func (c Commands) ParseAndRun(line string) error {
		cmd.Flags[flg].Value = cmd.Flags[flg].Default
	}
	cmd.Args = []string{}

	if len(words) == 1 {
		if len(cmd.Args) < cmd.MinArgs {
			fmt.Println("ERROR: Not enough args.")
+16 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ CREATE TABLE users (
  name        VARCHAR(53)  NOT NULL,
  admin       INT          DEFAULT 0,
  disabled    INT          DEFAULT 0,
  last_login  TIMESTAMP    DEFAULT CURRENT_TIMESTAMP NOT NULL,
  create_at   TIMESTAMP    DEFAULT CURRENT_TIMESTAMP NOT NULL,
  update_at   TIMESTAMP    DEFAULT CURRENT_TIMESTAMP NOT NULL
) WITHOUT ROWID;
@@ -140,3 +141,18 @@ CREATE TABLE mark (
    ON DELETE CASCADE
    ON UPDATE CASCADE
) WITHOUT ROWID;

--- TODO: The following is incomplete:
--- User configs.
CREATE TABLE config (
  login       VARCHAR(25) REFERENCES users(login) ON DELETE CASCADE ON UPDATE CASCADE,
  folder      VARCHAR(25) REFERENCES folders(name) ON DELETE CASCADE ON UPDATE CASCADE,
  always      INT NOT NULL,
  alert       INT NOT NULL DEFAULT 0,  --- 0=no, 1=brief, 2=readnew
) WITHOUT ROWID;

--- System configs.
CREATE TABLE system (
  default_expire  INT NOT NULL DEFAULT -1,
  expire_limit    INT NOT NULL DEFAULT -1,
) WITHOUT ROWID;
+7 −10
Original line number Diff line number Diff line
@@ -5,8 +5,7 @@ go 1.24.2
require (
	github.com/adrg/xdg v0.5.3
	github.com/chzyer/readline v1.5.1
	github.com/davecgh/go-spew v1.1.1
	github.com/gdamore/tcell/v2 v2.7.1
	github.com/gdamore/tcell/v2 v2.8.1
	github.com/golang-migrate/migrate/v4 v4.18.3
	github.com/jmoiron/sqlx v1.4.0
	github.com/rivo/tview v0.0.0-20250501113434-0c592cd31026
@@ -15,26 +14,24 @@ require (
)

require (
	github.com/carlmjohnson/versioninfo v0.22.5 // indirect
	github.com/dustin/go-humanize v1.0.1 // indirect
	github.com/earthboundkid/versioninfo/v2 v2.24.1 // indirect
	github.com/gdamore/encoding v1.0.0 // indirect
	github.com/golang-migrate/migrate v3.5.4+incompatible // indirect
	github.com/gdamore/encoding v1.0.1 // indirect
	github.com/google/uuid v1.6.0 // indirect
	github.com/hashicorp/errwrap v1.1.0 // indirect
	github.com/hashicorp/go-multierror v1.1.1 // indirect
	github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
	github.com/mattn/go-isatty v0.0.20 // indirect
	github.com/mattn/go-runewidth v0.0.15 // indirect
	github.com/mitchellh/go-wordwrap v1.0.1 // indirect
	github.com/mattn/go-runewidth v0.0.16 // indirect
	github.com/ncruces/go-strftime v0.1.9 // indirect
	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
	github.com/rivo/uniseg v0.4.7 // indirect
	go.uber.org/atomic v1.11.0 // indirect
	golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
	golang.org/x/sys v0.33.0 // indirect
	golang.org/x/term v0.30.0 // indirect
	golang.org/x/text v0.23.0 // indirect
	modernc.org/libc v1.65.1 // indirect
	golang.org/x/term v0.32.0 // indirect
	golang.org/x/text v0.25.0 // indirect
	modernc.org/libc v1.65.2 // indirect
	modernc.org/mathutil v1.7.1 // indirect
	modernc.org/memory v1.10.0 // indirect
)
Loading