Skip to content

Commit 1c2f308

Browse files
author
TP Honey
authored
Merge pull request #34 from tphoney/build_cleanup
(maint) cleaning build up with move to harness
2 parents 729d073 + 6b60b2c commit 1c2f308

File tree

4 files changed

+60
-74
lines changed

4 files changed

+60
-74
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
/release/
22
/drone-download*
3-
43
coverage.out
5-
.drone.yml

cmd/drone-download/main.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

cmd/drone-download/config.go renamed to main.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,72 @@
33
// Use of this source code is governed by an Apache 2.0 license that can be
44
// found in the LICENSE file.
55

6+
// DO NOT MODIFY THIS FILE DIRECTLY
7+
68
package main
79

810
import (
11+
"os"
12+
913
"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"
1017
"github.com/urfave/cli/v2"
1118
)
1219

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+
1472
func settingsFlags(settings *plugin.Settings) []cli.Flag {
1573
return []cli.Flag{
1674
&cli.StringFlag{

plugin/impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (p *Plugin) Execute() error {
128128

129129
if exp != "" {
130130
logrus.WithField("hash", alg).Info("Computing checksum")
131-
target.Seek(0, 0)
131+
_, _ = target.Seek(0, 0)
132132

133133
if _, err := io.Copy(h, target); err != nil {
134134
defer os.Remove(target.Name())

0 commit comments

Comments
 (0)