Skip to content

Commit a20cace

Browse files
authored
Merge pull request #378 from carlosms/go-cli
Use go-cli lib
2 parents 3ab56f8 + 5fffe2b commit a20cace

File tree

26 files changed

+1118
-221
lines changed

26 files changed

+1118
-221
lines changed

Gopkg.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dummy/main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ import (
88
"github.com/src-d/lookout/dummy"
99
"github.com/src-d/lookout/util/cli"
1010
"github.com/src-d/lookout/util/grpchelper"
11+
1112
"google.golang.org/grpc"
13+
gocli "gopkg.in/src-d/go-cli.v0"
1214
log "gopkg.in/src-d/go-log.v1"
1315
"gopkg.in/src-d/lookout-sdk.v0/pb"
1416
)
1517

1618
var (
17-
version = "local_build_1"
18-
app = cli.New("dummy")
19+
name = "dummy"
20+
version = "undefined"
21+
build = "undefined"
1922
)
2023

24+
var app = gocli.New(name, version, build, "Dummy analyzer for testing")
25+
2126
type ServeCommand struct {
22-
cli.CommonOptions
27+
gocli.PlainCommand `name:"serve" short-description:"serve the analyzer" long-description:"serve the analyzer"`
28+
cli.LogOptions
2329
Analyzer string `long:"analyzer" default:"ipv4://0.0.0.0:9930" env:"LOOKOUT_ANALYZER" description:"gRPC URL to bind the analyzer to"`
2430
DataServer string `long:"data-server" default:"ipv4://localhost:10301" env:"LOOKOUT_DATA_SERVER" description:"gRPC URL of the data server"`
2531
RequestUAST bool `long:"uast" env:"LOOKOUT_REQUEST_UAST" description:"analyzer will request UAST from the data server"`
@@ -93,10 +99,7 @@ func (c *ServeCommand) initHealthProbes() {
9399
}
94100

95101
func main() {
96-
if _, err := app.AddCommand("serve", "", "",
97-
&ServeCommand{}); err != nil {
98-
panic(err)
99-
}
102+
app.AddCommand(&ServeCommand{})
100103

101104
app.RunMain()
102105
}

cmd/lookout-sdk/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
type EventCommand struct {
28-
cli.CommonOptions
28+
cli.LogOptions
2929
DataServer string `long:"data-server" default:"ipv4://localhost:10301" env:"LOOKOUT_DATA_SERVER" description:"gRPC URL to bind the data server to"`
3030
Bblfshd string `long:"bblfshd" default:"ipv4://localhost:9432" env:"LOOKOUT_BBLFSHD" description:"gRPC URL of the Bblfshd server"`
3131
GitDir string `long:"git-dir" default:"." env:"GIT_DIR" description:"path to the .git directory to analyze"`

cmd/lookout-sdk/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package main
22

3-
import "github.com/src-d/lookout/util/cli"
3+
import "gopkg.in/src-d/go-cli.v0"
44

55
var (
66
name = "lookout-sdk"
77
version = "undefined"
88
build = "undefined"
99
)
1010

11-
var app = cli.New(name)
11+
var app = cli.New(name, version, build, "Simplified version of the lookout server that works with a local git repository and does not need access to GitHub")
1212

1313
func main() {
1414
app.RunMain()

cmd/lookout-sdk/push.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import (
66
"io"
77
"time"
88

9-
uuid "github.com/satori/go.uuid"
109
"github.com/src-d/lookout"
1110
"github.com/src-d/lookout/server"
1211
"github.com/src-d/lookout/store"
12+
13+
uuid "github.com/satori/go.uuid"
14+
gocli "gopkg.in/src-d/go-cli.v0"
1315
gogit "gopkg.in/src-d/go-git.v4"
1416
"gopkg.in/src-d/go-git.v4/plumbing"
1517
log "gopkg.in/src-d/go-log.v1"
1618
)
1719

1820
func init() {
19-
if _, err := app.AddCommand("push", "provides simple data server and triggers analyzer", "",
20-
&PushCommand{}); err != nil {
21-
panic(err)
22-
}
21+
app.AddCommand(&PushCommand{})
2322
}
2423

2524
type PushCommand struct {
25+
gocli.PlainCommand `name:"push" short-description:"trigger a push event" long-description:"Provides a simple data server and triggers an analyzer push event"`
2626
EventCommand
2727
}
2828

cmd/lookout-sdk/review.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ import (
44
"context"
55
"time"
66

7-
uuid "github.com/satori/go.uuid"
8-
97
"github.com/src-d/lookout"
108
"github.com/src-d/lookout/server"
119
"github.com/src-d/lookout/store"
10+
11+
uuid "github.com/satori/go.uuid"
12+
gocli "gopkg.in/src-d/go-cli.v0"
1213
log "gopkg.in/src-d/go-log.v1"
1314
)
1415

1516
func init() {
16-
if _, err := app.AddCommand("review", "provides simple data server and triggers analyzer", "",
17-
&ReviewCommand{}); err != nil {
18-
panic(err)
19-
}
17+
app.AddCommand(&ReviewCommand{})
2018
}
2119

2220
type ReviewCommand struct {
21+
gocli.PlainCommand `name:"review" short-description:"trigger a review event" long-description:"Provides a simple data server and triggers an analyzer review event"`
2322
EventCommand
2423
}
2524

cmd/lookout-sdk/version.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

cmd/lookoutd/common.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io/ioutil"
88
"net/http"
99
"os"
10-
"os/signal"
1110
"runtime"
1211
"time"
1312

@@ -24,14 +23,14 @@ import (
2423
"github.com/src-d/lookout/store/models"
2524
"github.com/src-d/lookout/util/cache"
2625
"github.com/src-d/lookout/util/cli"
27-
"github.com/src-d/lookout/util/ctxlog"
2826
"github.com/src-d/lookout/util/grpchelper"
2927

3028
"github.com/gregjones/httpcache/diskcache"
3129
"github.com/jinzhu/copier"
3230
"github.com/sanity-io/litter"
3331
"google.golang.org/grpc"
3432
"gopkg.in/src-d/go-billy.v4/osfs"
33+
gocli "gopkg.in/src-d/go-cli.v0"
3534
"gopkg.in/src-d/go-log.v1"
3635
"gopkg.in/src-d/lookout-sdk.v0/pb"
3736
yaml "gopkg.in/yaml.v2"
@@ -42,7 +41,7 @@ type stopFunc func()
4241

4342
// lookoutdCommand represents the common options for serve, watch, work
4443
type lookoutdCommand struct {
45-
cli.CommonOptions
44+
cli.LogOptions
4645
ConfigFile string `long:"config" short:"c" default:"config.yml" env:"LOOKOUT_CONFIG_FILE" description:"path to configuration file"`
4746
GithubUser string `long:"github-user" env:"GITHUB_USER" description:"user for the GitHub API"`
4847
GithubToken string `long:"github-token" env:"GITHUB_TOKEN" description:"access token for the GitHub API"`
@@ -51,6 +50,17 @@ type lookoutdCommand struct {
5150

5251
pool *github.ClientPool
5352
probeReadiness bool
53+
conf Config
54+
}
55+
56+
// Init implements the go-cli initializer interface. Initializes logs
57+
// and Config file based on the cli options
58+
func (c *lookoutdCommand) Init(a *gocli.App) error {
59+
c.LogOptions.Init(a)
60+
61+
var err error
62+
c.conf, err = c.initConfig()
63+
return err
5464
}
5565

5666
// queueConsumerCommand represents the common options for serve, work
@@ -460,13 +470,3 @@ func (c *queueConsumerCommand) runEventDequeuer(ctx context.Context, qOpt cli.Qu
460470

461471
return queue_util.RunEventDequeuer(ctx, qOpt.Q, server.HandleEvent, c.Workers)
462472
}
463-
464-
func stopOnSignal(ctx context.Context) error {
465-
var stopSignalChan = make(chan os.Signal)
466-
signal.Notify(stopSignalChan, os.Interrupt)
467-
sig := <-stopSignalChan
468-
469-
ctxlog.Get(ctx).Infof("Signal %s received. Stopping server...", sig)
470-
471-
return nil
472-
}

cmd/lookoutd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package main
22

3-
import "github.com/src-d/lookout/util/cli"
3+
import "gopkg.in/src-d/go-cli.v0"
44

55
var (
66
name = "lookoutd"
77
version = "undefined"
88
build = "undefined"
99
)
1010

11-
var app = cli.New(name)
11+
var app = cli.New(name, version, build, "A service for assisted code review")
1212

1313
func main() {
1414
app.RunMain()

cmd/lookoutd/migrate.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import (
55
"github.com/src-d/lookout/util/cli"
66

77
"github.com/golang-migrate/migrate"
8+
gocli "gopkg.in/src-d/go-cli.v0"
89
log "gopkg.in/src-d/go-log.v1"
910
)
1011

1112
func init() {
12-
if _, err := app.AddCommand("migrate", "performs a DB migration up to the latest version", "",
13-
&MigrateCommand{}); err != nil {
14-
panic(err)
15-
}
13+
app.AddCommand(&MigrateCommand{})
1614
}
1715

1816
type MigrateCommand struct {
17+
gocli.PlainCommand `name:"migrate" short-description:"performs a DB migration up to the latest version" long-description:"Performs a DB migration up to the latest version"`
1918
cli.LogOptions
2019
cli.DBOptions
2120
}

0 commit comments

Comments
 (0)