|
3 | 3 | // Use of this source code is governed by an Apache 2.0 license that can be
|
4 | 4 | // found in the LICENSE file.
|
5 | 5 |
|
| 6 | +// DO NOT MODIFY THIS FILE DIRECTLY |
| 7 | + |
6 | 8 | package main
|
7 | 9 |
|
8 | 10 | import (
|
| 11 | + "os" |
| 12 | + |
9 | 13 | "github.com/drone-plugins/drone-download/plugin"
|
| 14 | + "github.com/drone-plugins/drone-plugin-lib/errors" |
| 15 | + "github.com/drone-plugins/drone-plugin-lib/urfave" |
| 16 | + "github.com/joho/godotenv" |
10 | 17 | "github.com/urfave/cli/v2"
|
11 | 18 | )
|
12 | 19 |
|
13 |
| -// settingsFlags has the cli.Flags for the plugin.Settings. |
| 20 | +var version = "unknown" |
| 21 | + |
| 22 | +func main() { |
| 23 | + settings := &plugin.Settings{} |
| 24 | + |
| 25 | + if _, err := os.Stat("/run/drone/env"); err == nil { |
| 26 | + _ = godotenv.Overload("/run/drone/env") |
| 27 | + } |
| 28 | + |
| 29 | + app := &cli.App{ |
| 30 | + Name: "drone-download", |
| 31 | + Usage: "download a file", |
| 32 | + Version: version, |
| 33 | + Flags: append(settingsFlags(settings), urfave.Flags()...), |
| 34 | + Action: run(settings), |
| 35 | + } |
| 36 | + |
| 37 | + if err := app.Run(os.Args); err != nil { |
| 38 | + errors.HandleExit(err) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +func run(settings *plugin.Settings) cli.ActionFunc { |
| 43 | + return func(ctx *cli.Context) error { |
| 44 | + urfave.LoggingFromContext(ctx) |
| 45 | + |
| 46 | + plugin := plugin.New( |
| 47 | + *settings, |
| 48 | + urfave.PipelineFromContext(ctx), |
| 49 | + urfave.NetworkFromContext(ctx), |
| 50 | + ) |
| 51 | + |
| 52 | + if err := plugin.Validate(); err != nil { |
| 53 | + if e, ok := err.(errors.ExitCoder); ok { |
| 54 | + return e |
| 55 | + } |
| 56 | + |
| 57 | + return errors.ExitMessagef("validation failed: %w", err) |
| 58 | + } |
| 59 | + |
| 60 | + if err := plugin.Execute(); err != nil { |
| 61 | + if e, ok := err.(errors.ExitCoder); ok { |
| 62 | + return e |
| 63 | + } |
| 64 | + |
| 65 | + return errors.ExitMessagef("execution failed: %w", err) |
| 66 | + } |
| 67 | + |
| 68 | + return nil |
| 69 | + } |
| 70 | +} |
| 71 | + |
14 | 72 | func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
15 | 73 | return []cli.Flag{
|
16 | 74 | &cli.StringFlag{
|
|
0 commit comments