synapsecns/sanguine

View on GitHub
contrib/promexporter/cmd/cmd.go

Summary

Maintainability
A
3 hrs
Test Coverage
package cmd

import (
    "fmt"
    "github.com/synapsecns/sanguine/core/commandline"
    "github.com/synapsecns/sanguine/core/config"
    "github.com/synapsecns/sanguine/core/metrics"
    "github.com/urfave/cli/v2"
)

// Start starts the prometheus exporter.
func Start(args []string, buildInfo config.BuildInfo) {
    app := cli.NewApp()
    app.Name = buildInfo.Name()
    app.Description = buildInfo.VersionString() + "prometheus exporter"
    app.Usage = fmt.Sprintf("%s --help", buildInfo.Name())
    app.EnableBashCompletion = true
    // Note: for this app, a null metrics handler will result in a no-op.
    // the server will start, but nothing will happen
    app.Before = func(c *cli.Context) error {
        // nolint: wrapcheck
        return metrics.Setup(c.Context, buildInfo)
    }
    app.Commands = cli.Commands{exporterCommand}
    shellCommand := commandline.GenerateShellCommand(app.Commands)
    app.Commands = append(app.Commands, shellCommand)
    app.Action = shellCommand.Action

    err := app.Run(args)
    if err != nil {
        panic(err)
    }
}