cmd pkg for Subcommand type, use everywhere

This commit is contained in:
bth 2026-01-20 13:30:53 -08:00
commit c434005d39
7 changed files with 52 additions and 45 deletions

41
um.go
View file

@ -5,22 +5,13 @@ import (
"log"
"os"
nextpkg "github.com/brtholomy/um/go/next"
sortpkg "github.com/brtholomy/um/go/sort"
tagpkg "github.com/brtholomy/um/go/tag"
"github.com/brtholomy/um/go/cmd"
"github.com/brtholomy/um/go/next"
"github.com/brtholomy/um/go/sort"
"github.com/brtholomy/um/go/tag"
)
type Subcommand string
const (
tag Subcommand = "tag"
next Subcommand = "next"
last Subcommand = "last"
sort Subcommand = "sort"
help Subcommand = "help"
)
var helpShort string = fmt.Sprintf("um [%s | %s | %s | %s | %s]", tag, next, last, sort, help)
var helpShort string = fmt.Sprintf("um [%s | %s | %s | %s | %s]", cmd.Tag, cmd.Next, cmd.Last, cmd.Sort, cmd.Help)
var helpLong string = fmt.Sprintf(`%s
An (U)ltralight database for (M)arkdown composition.
@ -40,19 +31,19 @@ func main() {
log.Fatalln(helpShort)
}
cmd := Subcommand(os.Args[1])
arg := cmd.Subcommand(os.Args[1])
args := os.Args[2:]
switch cmd {
case next:
nextpkg.Next(args)
case last:
nextpkg.Last()
case tag:
tagpkg.Tag(args)
case sort:
sortpkg.Sort(args)
case help:
switch arg {
case cmd.Next:
next.Next(args)
case cmd.Last:
next.Last()
case cmd.Tag:
tag.Tag(args)
case cmd.Sort:
sort.Sort(args)
case cmd.Help:
log.Fatalln(helpLong)
default:
log.Println("um: command not found")