diff --git a/README.md b/README.md index 171a4c6..27179b1 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,10 @@ Execute from the working directory: ``` docker run --rm \ - -e PLUGIN_TOKEN=xxxxxxx \ + -e PLUGIN_TELEGRAM_TOKEN=xxxxxxx \ -e PLUGIN_TO=xxxxxxx \ -e PLUGIN_MESSAGE=test \ + -e PLUGIN_DEBUG=true \ -e DRONE_REPO_OWNER=appleboy \ -e DRONE_REPO_NAME=go-hello \ -e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \ diff --git a/main.go b/main.go index d25336a..75468ec 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,11 @@ func main() { Usage: "send telegram message", EnvVar: "PLUGIN_MESSAGE", }, + cli.BoolFlag{ + Name: "debug", + Usage: "enable debug message", + EnvVar: "PLUGIN_DEBUG", + }, cli.StringFlag{ Name: "repo.owner", Usage: "repository owner", @@ -107,6 +112,7 @@ func run(c *cli.Context) error { }, Config: Config{ Token: c.String("telegram.token"), + Debug: c.Bool("debug"), To: c.StringSlice("to"), Message: c.StringSlice("message"), }, diff --git a/plugin.go b/plugin.go index f7cf001..fafaa0a 100644 --- a/plugin.go +++ b/plugin.go @@ -32,6 +32,7 @@ type ( // Config for the plugin. Config struct { Token string + Debug bool To []string Message []string } @@ -98,7 +99,7 @@ func (p Plugin) Exec() error { return err } - bot.Debug = false + bot.Debug = p.Config.Debug // parse ids ids := parseID(p.Config.To) diff --git a/plugin_test.go b/plugin_test.go index 1bb5acd..f686444 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -69,6 +69,7 @@ func TestSendMessage(t *testing.T) { Token: os.Getenv("TELEGRAM_TOKEN"), To: []string{os.Getenv("TELEGRAM_TO"), "中文ID", "1234567890"}, Message: []string{"Test Telegram Chat Bot From Travis or Local", " "}, + Debug: false, }, }