From 662f6f4957743629a286b4eaa4563b2d49e70f61 Mon Sep 17 00:00:00 2001 From: Chris Raborg Date: Tue, 22 Jun 2021 14:31:38 -0400 Subject: [PATCH] Add drone cron exec cmd (#180) --- drone/cron/cron.go | 1 + drone/cron/cron_exec.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 drone/cron/cron_exec.go diff --git a/drone/cron/cron.go b/drone/cron/cron.go index 4eb24db..a044d4d 100644 --- a/drone/cron/cron.go +++ b/drone/cron/cron.go @@ -13,5 +13,6 @@ var Command = cli.Command{ cronDeleteCmd, cronDisableCmd, cronEnableCmd, + cronExecCmd, }, } diff --git a/drone/cron/cron_exec.go b/drone/cron/cron_exec.go new file mode 100644 index 0000000..4f2c518 --- /dev/null +++ b/drone/cron/cron_exec.go @@ -0,0 +1,35 @@ +package cron + +import ( + "errors" + + "github.com/drone/drone-cli/drone/internal" + "github.com/urfave/cli" +) + +var cronExecCmd = cli.Command{ + Name: "exec", + Usage: "trigger cron job", + ArgsUsage: "[repo/name] [cronjob]", + Action: cronExec, +} + +func cronExec(c *cli.Context) error { + slug := c.Args().First() + owner, name, err := internal.ParseRepo(slug) + if err != nil { + return err + } + + client, err := internal.NewClient(c) + if err != nil { + return err + } + + cron := c.Args().Get(1) + if cron == "" { + return errors.New("missing cronjob name") + } + + return client.CronExec(owner, name, cron) +}