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 ( import (
"fmt" "fmt"
@ -138,7 +138,7 @@ func parseConfig(configFile string) *Config {
f, err := os.ReadFile(configFile) f, err := os.ReadFile(configFile)
cfg := &Config{} cfg := &Config{}
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return cfg 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") lines := strings.Split(data, "\n")
for i, l := range lines { for i, l := range lines {
if int64(i) > max { if int64(i) > max {
return nil return nil
} }
parts := strings.Split(l, "\t") parts := strings.Split(l, "\t")
t, err := time.Parse(time.RFC3339, parts[0]) t, err := time.Parse(time.RFC3339, parts[0])
if err != nil { if err != nil {
continue continue
} }
*feed = append(*feed, FeedEntry{ *feed = append(*feed, FeedEntry{
Nick: nick, Nick: nick,
@ -134,7 +134,7 @@ func GetFeed(friend, friendsFile string, max int64) error {
return err return err
} }
if len(friend) > 0 { if len(friend) > 0 {
break break
} }
} }
} }

View file

@ -28,7 +28,12 @@ func run(args []string) error {
} else { } else {
switch args[1] { switch args[1] {
case "twt": 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": case "feed":
if len(args) > 2 { if len(args) > 2 {
return GetFeed(args[2], cfg.FriendsFile, cfg.MaxPosts) return GetFeed(args[2], cfg.FriendsFile, cfg.MaxPosts)

View file

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