mirror of
https://github.com/thegeeklab/drone-matrix.git
synced 2024-11-28 13:10:35 +00:00
refactor: add plugin flags to category (#42)
This commit is contained in:
parent
d910fb4ca1
commit
6fe43d2f02
@ -41,8 +41,6 @@ steps:
|
||||
<!-- spellchecker-enable -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
### Examples
|
||||
|
||||
## Build
|
||||
|
||||
Build the binary with the following command:
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user