summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go12
-rw-r--r--doGetNextAutoTopic.go24
-rw-r--r--main.go16
3 files changed, 37 insertions, 15 deletions
diff --git a/argv.go b/argv.go
index 775b0b5..b339ad3 100644
--- a/argv.go
+++ b/argv.go
@@ -17,12 +17,12 @@ type args struct {
Input string `arg:"--input" help:"should get a string from regex-cli"`
ImportFile string `arg:"--import" help:"import a file from regex-cli"`
Stats []string `arg:"--stats" help:"add stats to a chat"`
- NewChat []string `arg:"--new-chat" help:"create a new chat"`
- CountAuto bool `arg:"--count-auto" help:"count the number of auto chats"`
- Force bool `arg:"--force" help:"try to strong arm things"`
- Verbose bool `arg:"--verbose" help:"show more output"`
- Bash bool `arg:"--bash" help:"generate bash completion"`
- BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"`
+ NewChat []string `arg:"--new-chat" help:"create a new chat"`
+ GetNextAutoTopic bool `arg:"--get-next-auto-topic" help:"get the next auto topic name"`
+ Force bool `arg:"--force" help:"try to strong arm things"`
+ Verbose bool `arg:"--verbose" help:"show more output"`
+ Bash bool `arg:"--bash" help:"generate bash completion"`
+ BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"`
}
type EmptyCmd struct {
diff --git a/doGetNextAutoTopic.go b/doGetNextAutoTopic.go
new file mode 100644
index 0000000..47fb524
--- /dev/null
+++ b/doGetNextAutoTopic.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+)
+
+func doGetNextAutoTopic() {
+ if err := me.chats.ConfigLoad(); err != nil {
+ badExit(err)
+ }
+ max := 0
+ for _, chat := range me.chats.GetChats() {
+ if strings.HasPrefix(chat.GetChatName(), "Auto ") {
+ numStr := strings.TrimPrefix(chat.GetChatName(), "Auto ")
+ num, err := strconv.Atoi(numStr)
+ if err == nil && num > max {
+ max = num
+ }
+ }
+ }
+ fmt.Printf("Auto %d", max+1)
+}
diff --git a/main.go b/main.go
index f547a94..8b23de3 100644
--- a/main.go
+++ b/main.go
@@ -46,17 +46,15 @@ func main() {
}
me.chats = chatpb.NewChats()
- if !argv.CountAuto {
- if err := me.chats.ConfigLoad(); err != nil {
- badExit(err)
- }
- if verifyUuids(me.chats) {
- me.chats.ConfigSave()
- }
+ if err := me.chats.ConfigLoad(); err != nil {
+ badExit(err)
+ }
+ if verifyUuids(me.chats) {
+ me.chats.ConfigSave()
}
- if argv.CountAuto {
- doCountAuto()
+ if argv.GetNextAutoTopic {
+ doGetNextAutoTopic()
okExit("")
}