From 6fe43d2f023536360311cdd0f1120fc8d0d81a00 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 28 May 2022 17:13:28 +0200 Subject: [PATCH] refactor: add plugin flags to category (#42) --- _docs/content/_index.md | 2 -- cmd/drone-matrix/config.go | 9 ++++++++- cmd/drone-matrix/main.go | 18 +++++------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/_docs/content/_index.md b/_docs/content/_index.md index d831d37..82c75eb 100644 --- a/_docs/content/_index.md +++ b/_docs/content/_index.md @@ -41,8 +41,6 @@ steps: -### Examples - ## Build Build the binary with the following command: diff --git a/cmd/drone-matrix/config.go b/cmd/drone-matrix/config.go index edd31e9..3f5664f 100644 --- a/cmd/drone-matrix/config.go +++ b/cmd/drone-matrix/config.go @@ -12,31 +12,35 @@ import ( ) // settingsFlags has the cli.Flags for the plugin.Settings. -func settingsFlags(settings *plugin.Settings) []cli.Flag { +func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "username", EnvVars: []string{"PLUGIN_USERNAME", "MATRIX_USERNAME"}, Usage: "sets username for authentication", Destination: &settings.Username, + Category: category, }, &cli.StringFlag{ Name: "password", EnvVars: []string{"PLUGIN_PASSWORD", "MATRIX_PASSWORD"}, Usage: "sets password for authentication", Destination: &settings.Password, + Category: category, }, &cli.StringFlag{ Name: "userid", EnvVars: []string{"PLUGIN_USERID,PLUGIN_USER_ID", "MATRIX_USERID", "MATRIX_USER_ID"}, Usage: "sets userid for authentication", Destination: &settings.UserID, + Category: category, }, &cli.StringFlag{ Name: "accesstoken", EnvVars: []string{"PLUGIN_ACCESSTOKEN,PLUGIN_ACCESS_TOKEN", "MATRIX_ACCESSTOKEN", "MATRIX_ACCESS_TOKEN"}, Usage: "sets access token for authentication", Destination: &settings.AccessToken, + Category: category, }, &cli.StringFlag{ Name: "homeserver", @@ -44,12 +48,14 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag { Usage: "sets matrix home server url to use", Value: "https://matrix.org", Destination: &settings.Homeserver, + Category: category, }, &cli.StringFlag{ Name: "roomid", EnvVars: []string{"PLUGIN_ROOMID", "MATRIX_ROOMID"}, Usage: "sets roomid to send messages to", Destination: &settings.RoomID, + Category: category, }, &cli.StringFlag{ Name: "template", @@ -57,6 +63,7 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag { Usage: "sets message template", Value: "Build {{ build.Status }} [{{ repo.Owner }}/{{ repo.Name }}#{{ truncate commit.SHA 8 }}]({{ build.Link }}) ({{ build.Branch }}) by {{ commit.Author }}", Destination: &settings.Template, + Category: category, }, } } diff --git a/cmd/drone-matrix/main.go b/cmd/drone-matrix/main.go index 9ef80ee..e9e2aa7 100644 --- a/cmd/drone-matrix/main.go +++ b/cmd/drone-matrix/main.go @@ -12,7 +12,7 @@ import ( "github.com/drone-plugins/drone-matrix/plugin" "github.com/joho/godotenv" - "github.com/thegeeklab/drone-plugin-lib/errors" + "github.com/sirupsen/logrus" "github.com/thegeeklab/drone-plugin-lib/urfave" "github.com/urfave/cli/v2" ) @@ -37,12 +37,12 @@ func main() { Name: "drone-matrix", Usage: "build notifications for matrix", Version: BuildVersion, - Flags: append(settingsFlags(settings), urfave.Flags()...), + Flags: append(settingsFlags(settings, "Plugin Flags"), urfave.Flags()...), Action: run(settings), } if err := app.Run(os.Args); err != nil { - errors.HandleExit(err) + logrus.Fatal(err) } } @@ -57,19 +57,11 @@ func run(settings *plugin.Settings) cli.ActionFunc { ) if err := plugin.Validate(); err != nil { - if e, ok := err.(errors.ExitCoder); ok { - return e - } - - return errors.ExitMessagef("validation failed: %w", err) + return fmt.Errorf("validation failed: %w", err) } if err := plugin.Execute(); err != nil { - if e, ok := err.(errors.ExitCoder); ok { - return e - } - - return errors.ExitMessagef("execution failed: %w", err) + return fmt.Errorf("execution failed: %w", err) } return nil