Skip to content

Conversation

carlosms
Copy link
Contributor

@carlosms carlosms commented Dec 3, 2018

Migrate the CLI to use https://github.com/src-d/go-cli.

This PR does not solve any issue, but I think in the long term it's good to have all our projects use the same libraries to be consistent.

@carlosms carlosms added the enhancement New feature or request label Dec 3, 2018
)

var app = gocli.New("dummy", version, build, "Dummy analyzer for testing")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gocli.New(name, version, build, "Dummy analyzer for testing")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0c2b3ea

util/cli/log.go Outdated

// Init initializes the default logger factory.
func (c *LogOptions) init(app *App) {
// InitLog is similar to go-cli LogOptions.Init, but adds the application name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it also applies the configuration to logrus.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in f800074

queueConsumerCommand
}

func (c *ServeCommand) Execute(args []string) error {
ctx, stopCtx := context.WithCancel(context.Background())
stopCh := make(chan error, 1)

cli.InitLog(&c.LogOptions, name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think if we use cli.Command instead of cli.PlainCommand? It would bring profiling by default now and any other perks in the future. Also I really like that go-cli calls init by default. Right now we don't use it.

My suggestion:

type LookoutCommand struct {
  cli.Command
}

func (c LookoutCommand) Init(a *App) error {
  c.Command.Init()
  // add additional logic for our logger
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to leave the full cli.Command out of this PR to limit it to migrate what we have to go-cli, as is. We can add profiling later easily if we think we need it.

For the initializer interface, I added it in 2812a43

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense 👍

}

type ServeCommand struct {
gocli.PlainCommand `name:"serve" short-description:"run a standalone server" long-description:"Run a standalone server"`
queueConsumerCommand
}

func (c *ServeCommand) Execute(args []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use ExecuteContext and remove our custom signal handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5efef51

Copy link
Contributor

@smacker smacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few inline comments. But also maybe we should change our private init functions to use Initializer where it's appropriate.

@carlosms
Copy link
Contributor Author

carlosms commented Dec 5, 2018

Ready for another round of review.
The merge conflicts are minimal, I'll do it before merging to not mess with the current reviews and comments.

Provider string `long:"provider" choice:"github" choice:"json" default:"github" env:"LOOKOUT_PROVIDER" description:"provider name: github, json"`
ProbesAddr string `long:"probes-addr" default:"0.0.0.0:8090" env:"LOOKOUT_PROBES_ADDRESS" description:"TCP address to bind the health probe endpoints"`
gocli.LogOptions `group:"Log Options"`
ConfigFile string `long:"config" short:"c" default:"config.yml" env:"LOOKOUT_CONFIG_FILE" description:"path to configuration file"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line is 138 characters (lll)

If you have feedback about this comment, please, tell us.

ConfigFile string `long:"config" short:"c" default:"config.yml" env:"LOOKOUT_CONFIG_FILE" description:"path to configuration file"`
GithubUser string `long:"github-user" env:"GITHUB_USER" description:"user for the GitHub API"`
GithubToken string `long:"github-token" env:"GITHUB_TOKEN" description:"access token for the GitHub API"`
Provider string `long:"provider" choice:"github" choice:"json" default:"github" env:"LOOKOUT_PROVIDER" description:"provider name: github, json"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line is 154 characters (lll)

If you have feedback about this comment, please, tell us.

GithubUser string `long:"github-user" env:"GITHUB_USER" description:"user for the GitHub API"`
GithubToken string `long:"github-token" env:"GITHUB_TOKEN" description:"access token for the GitHub API"`
Provider string `long:"provider" choice:"github" choice:"json" default:"github" env:"LOOKOUT_PROVIDER" description:"provider name: github, json"`
ProbesAddr string `long:"probes-addr" default:"0.0.0.0:8090" env:"LOOKOUT_PROBES_ADDRESS" description:"TCP address to bind the health probe endpoints"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line is 158 characters (lll)

If you have feedback about this comment, please, tell us.

@smacker
Copy link
Contributor

smacker commented Dec 5, 2018

Sorry most probably I did something wrong and github doesn't show context for my comments anymore...

@carlosms
Copy link
Contributor Author

carlosms commented Dec 5, 2018

Besides the changes requested I've pushed another commit c9dbaa9 to make our LogOptions behave like go-cli's LogOption.

I didn't do the same for QueueOptions and DBOptions because they connect to other components, and it feels like this does not belong to an "initialization" phase. It's more about the code structure, it would work the same in the command's Init and Execute.

}

type PushCommand struct {
gocli.PlainCommand `name:"push" short-description:"trigger a push event" long-description:"Provides a simple data server and triggers an analyzer push event"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line is 159 characters (lll)

If you have feedback about this comment, please, tell us.

}

type ReviewCommand struct {
gocli.PlainCommand `name:"review" short-description:"trigger a review event" long-description:"Provides a simple data server and triggers an analyzer review event"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line is 165 characters (lll)

If you have feedback about this comment, please, tell us.


var err error
c.conf, err = c.initConfig()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick:

var err error
c.conf, err = c.initConfig()
return err

sorry 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 63ae46e

Copy link
Contributor

@smacker smacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work! 👍 👍 👍

there is a tiny nitpick left

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
@carlosms
Copy link
Contributor Author

carlosms commented Dec 7, 2018

Tests are failing because of #391

@carlosms carlosms merged commit a20cace into src-d:master Dec 7, 2018
bzz added a commit to src-d/lookout-gometalint-analyzer that referenced this pull request Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants