-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.ts
44 lines (35 loc) · 1.29 KB
/
run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {Command, flags} from '@oclif/command'
import chalk from 'chalk'
import shelljs from 'shelljs'
import Logger from '../utilities/logger'
import Utilities from '../utilities/utilities'
/*
* this Commands add support for cron jobs
* */
export default class Run extends Command {
static description = 'Cron Expressions helper and scheduler'
static flags = {
help: flags.help({char: 'h'}),
string: flags.string({char: 's' , description: 'command to execute, should be compatible with your shell'}),
}
static args = [{name: 'string'}]
// only 2 parameters required HASH_TYPE and INPUT_STRING
async run() {
const {args, flags} = this.parse(Run)
args.string = Utilities.getInputStringFromCmd(this, flags, args) // from either -s or args
//check params after evaluating all
this.checkParameters(flags, args)
this.evalRun(flags, args)
}
// to check required parameters passed or not
// tslint:disable-next-line:no-unused
private checkParameters(flags: any, args: any) {
if (args.string === undefined || args.string === '')
Logger.error(this, 'Command empty or undefined')
}
// tslint:disable-next-line:no-unused
private evalRun(flags: any, args: any) {
Logger.success(this, `running: ${chalk.green(args.string)}`)
shelljs.exec(args.string)
}
}