raven.go: add arg length check to twt command

This commit is contained in:
Iris Lightshard 2023-01-09 22:48:07 -07:00
parent 057771467d
commit c274e63e82
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
4 changed files with 20 additions and 15 deletions

View file

@ -1,4 +1,4 @@
package main
package main
import (
"fmt"
@ -138,7 +138,7 @@ func parseConfig(configFile string) *Config {
f, err := os.ReadFile(configFile)
cfg := &Config{}
if err != nil {
fmt.Println(err.Error())
fmt.Println(err.Error())
return cfg
}

10
feed.go
View file

@ -80,13 +80,13 @@ func buildFeed(feed *Feed, nick, data string, max int64) error {
lines := strings.Split(data, "\n")
for i, l := range lines {
if int64(i) > max {
return nil
}
if int64(i) > max {
return nil
}
parts := strings.Split(l, "\t")
t, err := time.Parse(time.RFC3339, parts[0])
if err != nil {
continue
continue
}
*feed = append(*feed, FeedEntry{
Nick: nick,
@ -134,7 +134,7 @@ func GetFeed(friend, friendsFile string, max int64) error {
return err
}
if len(friend) > 0 {
break
break
}
}
}

View file

@ -28,7 +28,12 @@ func run(args []string) error {
} else {
switch args[1] {
case "twt":
return Post(args[2], cfg.FeedFile, cfg.FeedAscend)
if len(args) > 2 {
return Post(args[2], cfg.FeedFile, cfg.FeedAscend)
} else {
helpMe(args[0])
return errors.New("ARG is required with the twt command")
}
case "feed":
if len(args) > 2 {
return GetFeed(args[2], cfg.FriendsFile, cfg.MaxPosts)

View file

@ -5,11 +5,11 @@ import (
)
type Config struct {
FeedFile string
FeedAscend bool
FriendsFile string
MaxPosts int64
Nick string
FeedFile string
FeedAscend bool
FriendsFile string
MaxPosts int64
Nick string
}
type FeedEntry struct {