This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 265
/
main.go
87 lines (76 loc) · 1.73 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2013 The Go Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd.
// Command gddo-admin is the GoDoc.org command line administration tool.
package main
import (
"flag"
"fmt"
"os"
"strings"
"time"
)
type command struct {
name string
run func(c *command)
flag flag.FlagSet
usage string
}
func (c *command) printUsage() {
fmt.Fprintf(os.Stderr, "%s %s\n", os.Args[0], c.usage)
c.flag.PrintDefaults()
}
var (
project = flag.String("project", "", "App Engine project ID used to interact with remote API.")
redisServer = flag.String("db-server", "redis://127.0.0.1:6379", "URI of Redis server.")
dbIdleTimeout = flag.Duration("db-idle-timeout", 250*time.Second, "Close database connections after remaining idle for this duration.")
)
var gaeEndpoint string
var commands = []*command{
blockCommand,
reindexCommand,
deleteCommand,
popularCommand,
dangleCommand,
crawlCommand,
statsCommand,
}
func printUsage() {
var n []string
for _, c := range commands {
n = append(n, c.name)
}
fmt.Fprintf(os.Stderr, "%s %s\n", os.Args[0], strings.Join(n, "|"))
flag.PrintDefaults()
for _, c := range commands {
c.printUsage()
}
}
func setDefaults() {
if *project != "" {
gaeEndpoint = fmt.Sprintf("serviceproxy-dot-%s.appspot.com", *project)
}
}
func main() {
flag.Usage = printUsage
flag.Parse()
args := flag.Args()
setDefaults()
if len(args) >= 1 {
for _, c := range commands {
if args[0] == c.name {
c.flag.Usage = func() {
c.printUsage()
os.Exit(2)
}
c.flag.Parse(args[1:])
c.run(c)
return
}
}
}
printUsage()
os.Exit(2)
}