feat: added cli command for previewing cron schedules
							parent
							
								
									0bff91c15f
								
							
						
					
					
						commit
						5e07b0efc9
					
				|  | @ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | @ -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() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue