support load env from file.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-11-12 16:51:14 +08:00
parent 9f288d99d9
commit ac32848570
3 changed files with 21 additions and 0 deletions

1
.gitignore vendored
View File

@ -25,3 +25,4 @@ _testmain.go
vendor vendor
drone-telegram drone-telegram
coverage.txt coverage.txt
.env

View File

@ -83,3 +83,13 @@ docker run --rm \
-w $(pwd) \ -w $(pwd) \
appleboy/drone-telegram appleboy/drone-telegram
``` ```
Load all environments from file.
```bash
docker run --rm \
-e ENV_FILE=your_env_file_path \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-telegram
```

10
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"os" "os"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -156,11 +157,20 @@ func main() {
Usage: "job finished", Usage: "job finished",
EnvVar: "DRONE_JOB_FINISHED", EnvVar: "DRONE_JOB_FINISHED",
}, },
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
EnvVar: "ENV_FILE",
},
} }
app.Run(os.Args) app.Run(os.Args)
} }
func run(c *cli.Context) error { func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{ plugin := Plugin{
Repo: Repo{ Repo: Repo{
Owner: c.String("repo.owner"), Owner: c.String("repo.owner"),