support load env from file.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -25,3 +25,4 @@ _testmain.go | |||||||
| vendor | vendor | ||||||
| drone-telegram | drone-telegram | ||||||
| coverage.txt | coverage.txt | ||||||
|  | .env | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							| @@ -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
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.go
									
									
									
									
									
								
							| @@ -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"), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user