-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
53 lines (43 loc) · 1.14 KB
/
main.go
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
package main
import (
"flag"
"log"
"os"
"strings"
"bitbucket.org/djr2/tldr/cache"
"bitbucket.org/djr2/tldr/config"
"bitbucket.org/djr2/tldr/page"
"bitbucket.org/djr2/tldr/platform"
)
var flagSet *flag.FlagSet
func init() {
flagSet = flag.NewFlagSet("", flag.ContinueOnError)
flagSet.String("p", "", "platform of the tldr page\n\t `platform` -- "+
strings.Join(platform.Platforms(), ", "))
flagSet.String("c", "", "clear cache for a tldr page\n\t `page` -- "+
"Use `clearall` to clear entire cache\n\t -p is required if clearing cache for a specific platform")
flagSet.String("debug", "disable", "enables debug logging")
log.SetOutput(new(logWriter))
}
func main() {
tldr()
}
func tldr() {
if err := flagSet.Parse(os.Args[1:]); err != nil {
return
}
setLogDebug()
config.Load()
plat := platform.ParseFlag(flagSet.Lookup("p"))
if clear := flagSet.Lookup("c"); clear.Value.String() != "" {
banner()
cache.Remove(clear.Value.String(), plat)
return
}
if len(flagSet.Args()) > 0 {
page.New(cache.Find(strings.Join(flagSet.Args(), "-"), plat)).Print()
} else if len(os.Args[1:]) == 0 {
banner()
flagSet.Usage()
}
}