2023-01-10 05:23:25 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func helpMe(prog string) {
|
|
|
|
fmt.Printf("%s: twtxt client\n", prog)
|
|
|
|
fmt.Printf("usage: %s CMD <ARG>\n\n", prog)
|
|
|
|
fmt.Println("available commands are")
|
|
|
|
fmt.Println(" twt: post to your twtxt file")
|
|
|
|
fmt.Println(" feed: read the feed from all your friends, or the one named with ARG if given")
|
|
|
|
fmt.Println(" self: read your own feed\n")
|
|
|
|
fmt.Println("Config file is stored in " + GetConfigLocation() + " and is initialized automatically with a wizard")
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(args []string) error {
|
|
|
|
cfg := ReadConfig()
|
|
|
|
if cfg.IsNull() {
|
|
|
|
cfg.RunWizard()
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) == 1 || args[1] == "help" || args[1] == "-h" || args[1] == "--help" {
|
|
|
|
helpMe(args[0])
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
switch args[1] {
|
|
|
|
case "twt":
|
2023-01-10 05:48:07 +00:00
|
|
|
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")
|
|
|
|
}
|
2023-01-10 05:23:25 +00:00
|
|
|
case "feed":
|
|
|
|
if len(args) > 2 {
|
|
|
|
return GetFeed(args[2], cfg.FriendsFile, cfg.MaxPosts)
|
|
|
|
} else {
|
|
|
|
return GetFeed("", cfg.FriendsFile, cfg.MaxPosts)
|
|
|
|
}
|
|
|
|
case "self":
|
|
|
|
return GetOwnFeed(cfg.Nick, cfg.FeedFile, cfg.MaxPosts)
|
|
|
|
default:
|
|
|
|
helpMe(args[0])
|
|
|
|
return errors.New("Unrecognized command line option: " + args[1] + "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := run(os.Args)
|
|
|
|
if err == nil {
|
|
|
|
os.Exit(0)
|
|
|
|
} else {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|