From bd4bb9a9fbe51451cbfb6f5abd11169809f5d275 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 26 May 2022 09:15:49 +0200 Subject: [PATCH] feat: added cli command for previewing cron schedules --- src/console/schedule/schedule.v | 34 +++++++++++++++++++++++++++++++++ src/main.v | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 src/console/schedule/schedule.v diff --git a/src/console/schedule/schedule.v b/src/console/schedule/schedule.v new file mode 100644 index 00000000..b086b532 --- /dev/null +++ b/src/console/schedule/schedule.v @@ -0,0 +1,34 @@ +module schedule + +import cli +import cron.expression { parse_expression } + +// cmd returns the cli submodule for previewing a cron schedule. +pub fn cmd() cli.Command { + return cli.Command{ + name: 'schedule' + description: 'Preview the behavior of a cron schedule.' + flags: [ + cli.Flag{ + name: 'count' + description: 'How many scheduled times to show.' + flag: cli.FlagType.int + default_value: ['5'] + }, + ] + execute: fn (cmd cli.Command) ? { + exp := parse_expression(cmd.args.join(' '))? + + mut t := exp.next_from_now()? + println(t) + + count := cmd.flags.get_int('count')? + + for _ in 1 .. count { + t = exp.next(t)? + + println(t) + } + } + } +} diff --git a/src/main.v b/src/main.v index 6df45dc3..885e0f32 100644 --- a/src/main.v +++ b/src/main.v @@ -5,6 +5,7 @@ import server import cli import console.git import console.logs +import console.schedule import cron fn main() { @@ -27,6 +28,7 @@ fn main() { git.cmd(), cron.cmd(), logs.cmd(), + schedule.cmd(), ] } app.setup()