Skip to content

Commit

Permalink
feat(cli): Add Validate cli command to "test" the configuration (#964)
Browse files Browse the repository at this point in the history
* feat(cli): Add Validate cli command to "test" the configuration

* update readme
  • Loading branch information
dmolik authored Jan 14, 2025
1 parent e0c4b7c commit fe650ae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,16 @@ USAGE:
gitlab-ci-pipelines-exporter [global options] command [command options] [arguments...]

COMMANDS:
run start the exporter
monitor display information about the currently running exporter
help, h Shows a list of commands or help for one command
run start the exporter
validate validate the configuration file
monitor display information about the currently running exporter
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--internal-monitoring-listener-address value, -m value internal monitoring listener address [$GCPE_INTERNAL_MONITORING_LISTENER_ADDRESS]
--help, -h show help (default: false)
--version, -v print the version (default: false)
--help, -h show help
--version, -v print the version

```

### run
Expand All @@ -296,6 +298,21 @@ OPTIONS:
--help, -h show help (default: false)
```

### validate

```bash
~$ gitlab-ci-pipelines-exporter validate --help
NAME:
gitlab-ci-pipelines-exporter validate - validate the configuration file

USAGE:
gitlab-ci-pipelines-exporter validate [command options] [arguments...]

OPTIONS:
--config file, -c file config file (default: "./gitlab-ci-pipelines-exporter.yml") [$GCPE_CONFIG]
--help, -h show help
```

### monitor

```bash
Expand Down
14 changes: 14 additions & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ func NewApp(version string, start time.Time) (app *cli.App) {
},
},
},
{
Name: "validate",
Usage: "validate the configuration file",
Action: cmd.ExecWrapper(cmd.Validate),
Flags: cli.FlagsByName{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
EnvVars: []string{"GCPE_CONFIG"},
Usage: "config `file`",
Value: "./gitlab-ci-pipelines-exporter.yml",
},
},
},
{
Name: "monitor",
Usage: "display information about the currently running exporter",
Expand Down
18 changes: 18 additions & 0 deletions internal/cmd/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)

func Validate(cliCtx *cli.Context) (int, error) {
log.Debug("Validating configuration..")

if _, err := configure(cliCtx); err != nil {
log.WithError(err).Error("Failed to configure")
return 1, err

Check failure on line 13 in internal/cmd/validate.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-24.04)

return with no blank line before (nlreturn)
}

log.Debug("Configuration is valid")
return 0, nil

Check failure on line 17 in internal/cmd/validate.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-24.04)

return with no blank line before (nlreturn)
}

0 comments on commit fe650ae

Please sign in to comment.