From 571c37b0898b3806952e281d4080288b5c5d352e Mon Sep 17 00:00:00 2001 From: vilmibm Date: Sun, 31 Jul 2022 21:24:50 +0000 Subject: [PATCH] WIP --- cmd/contrib/main.go | 45 +++++++++++++++++++++++++++++++++++++++++++-- db/db.go | 5 +++++ go.mod | 11 +++++++++++ go.sum | 2 ++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 db/db.go diff --git a/cmd/contrib/main.go b/cmd/contrib/main.go index 3edbc4c..b829e33 100644 --- a/cmd/contrib/main.go +++ b/cmd/contrib/main.go @@ -3,15 +3,16 @@ package main import ( "errors" "fmt" + "github.com/AlecAivazis/survey/v2" "github.com/spf13/cobra" "os" + "path/filepath" ) const ( submitOp = "submit" delOp = "del" updateOp = "update" - dbpath = "/town/var/commands.db" ) type ContribOptions struct { @@ -36,10 +37,50 @@ func runContrib(opts *ContribOptions) error { } func submit(opts *ContribOptions) error { - // TODO run survey + var cmdName string + var category string + var shortDescription string + var longDescription string + + _, defaultName := filepath.Split(opts.ExecPath) + if err := survey.AskOne(&survey.Input{ + Message: "New command's name:", + Default: defaultName}, &cmdName); err != nil { + return err + } + + categories := []string{ + "art", + "social", + "game", + "utility", + "misc", + } + var choice int + if err := survey.AskOne(&survey.Select{ + Message: "what category should this command be filed under?", + Options: categories, + }, &choice); err != nil { + return err + } + category = categories[choice] + fmt.Printf("DBG %#v\n", category) + + if err := survey.AskOne(&survey.Input{ + Message: "What's a one line description of this command?", + }, &shortDescription); err != nil { + return err + } + + if err := survey.AskOne(&survey.Editor{ + Message: "Write a long description for this command. Try to include examples. If the short description is enough, you can just leave it blank though. Really it's whatever you want. I donno"}, &longDescription); err != nil { + return nil + } + // TODO create pending row // TODO email me // TODO print confirmation + return nil } diff --git a/db/db.go b/db/db.go new file mode 100644 index 0000000..d34f0da --- /dev/null +++ b/db/db.go @@ -0,0 +1,5 @@ +package db + +const Path = "/town/var/town.sqlite3" + +// TODO diff --git a/go.mod b/go.mod index faa9501..8d865e6 100644 --- a/go.mod +++ b/go.mod @@ -8,3 +8,14 @@ require ( github.com/spf13/cobra v1.5.0 gopkg.in/yaml.v3 v3.0.1 ) + +require ( + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/mattn/go-colorable v0.1.2 // indirect + github.com/mattn/go-isatty v0.0.13 // indirect + github.com/mattn/go-sqlite3 v1.14.14 // indirect + github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect + golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect + golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect + golang.org/x/text v0.3.6 // indirect +) diff --git a/go.sum b/go.sum index b465f7b..b792e9d 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-sqlite3 v1.14.14 h1:qZgc/Rwetq+MtyE18WhzjokPD93dNqLGNT3QJuLvBGw= +github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/microcosm-cc/bluemonday v1.0.17 h1:Z1a//hgsQ4yjC+8zEkV8IWySkXnsxmdSY642CTFQb5Y=