Selaa lähdekoodia

simple subcommands

Lucas Stadler 11 vuotta sitten
vanhempi
commit
4b71d16d66
1 muutettua tiedostoa jossa 30 lisäystä ja 1 poistoa
  1. 30 1
      go/feeds/feeds.go

+ 30 - 1
go/feeds/feeds.go

@ -3,6 +3,7 @@ package main
3 3
import (
4 4
	"bufio"
5 5
	"errors"
6
	"flag"
6 7
	"fmt"
7 8
	"net/http"
8 9
	"net/url"
@ -27,8 +28,36 @@ import (
27 28
// - support json and edn output (and transit?)
28 29
// test (see feeds_test.go)
29 30
31
var commands = []string{"fetch-all", "help"}
32
30 33
func main() {
31
	FetchAll()
34
	if len(os.Args) == 1 {
35
		printUsage()
36
		os.Exit(1)
37
	}
38
39
	cmd := os.Args[1]
40
	flag.CommandLine.Parse(os.Args[2:])
41
42
	switch cmd {
43
	case "fetch-all":
44
		FetchAll()
45
	case "help":
46
		printUsage()
47
		flag.PrintDefaults()
48
		fmt.Println("\nAvaillable commands:")
49
		for _, command := range commands {
50
			fmt.Println("\t", command)
51
		}
52
		os.Exit(0)
53
	default:
54
		printUsage()
55
		os.Exit(1)
56
	}
57
}
58
59
func printUsage() {
60
	fmt.Printf("Usage: %s [<options>] <cmd> [<args>]\n", os.Args[0])
32 61
}
33 62
34 63
func FetchAll() {