chore: move load .env file to top. (#94)

This commit is contained in:
Bo-Yi Wu 2020-07-01 06:40:04 +08:00 committed by GitHub
parent ce15798a06
commit 153fe2cb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

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

15
main.go
View File

@ -5,7 +5,6 @@ import (
"os" "os"
"github.com/joho/godotenv" "github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -15,6 +14,11 @@ var (
) )
func main() { func main() {
// Load env-file if it exists first
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
_ = godotenv.Load(filename)
}
app := cli.NewApp() app := cli.NewApp()
app.Name = "telegram plugin" app.Name = "telegram plugin"
app.Usage = "telegram plugin" app.Usage = "telegram plugin"
@ -205,11 +209,6 @@ func main() {
Usage: "job finished", Usage: "job finished",
EnvVar: "DRONE_BUILD_FINISHED", EnvVar: "DRONE_BUILD_FINISHED",
}, },
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
EnvVar: "ENV_FILE",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "github", Name: "github",
Usage: "Boolean value, indicates the runtime environment is GitHub Action.", Usage: "Boolean value, indicates the runtime environment is GitHub Action.",
@ -258,10 +257,6 @@ func main() {
} }
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{
GitHub: GitHub{ GitHub: GitHub{
Workflow: c.String("github.workflow"), Workflow: c.String("github.workflow"),