2022-05-26 09:15:49 +02:00
|
|
|
module schedule
|
|
|
|
|
|
|
|
import cli
|
|
|
|
import cron.expression { parse_expression }
|
2022-05-26 13:34:57 +02:00
|
|
|
import time
|
2022-05-26 09:15:49 +02:00
|
|
|
|
|
|
|
// cmd returns the cli submodule for previewing a cron schedule.
|
|
|
|
pub fn cmd() cli.Command {
|
|
|
|
return cli.Command{
|
|
|
|
name: 'schedule'
|
2022-05-26 13:34:57 +02:00
|
|
|
usage: 'schedule'
|
2022-05-26 09:15:49 +02:00
|
|
|
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) ? {
|
2022-05-26 13:34:57 +02:00
|
|
|
ce := parse_expression(cmd.args.join(' '))?
|
2022-05-26 09:15:49 +02:00
|
|
|
count := cmd.flags.get_int('count')?
|
|
|
|
|
2022-05-26 13:34:57 +02:00
|
|
|
for t in ce.next_n(time.now(), count)? {
|
2022-05-26 09:15:49 +02:00
|
|
|
println(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|