all repos — raven @ main

basic twtxt client in go

raven.go (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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":
			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)
			} 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)
	}
}