Merge pull request #26 from appleboy/cli

support load env from file.
This commit is contained in:
Bo-Yi Wu 2016-11-12 16:52:25 +08:00 committed by GitHub
commit 91ae3a4c55
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"),