Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"moment-timezone": "^0.5.32",
"nyc": "^15.1.0",
"ora": "^5.2.0",
"shelljs": "^0.8.4",
"signale": "^1.4.0",
"snyk": "^1.425.4",
"test": "^0.6.0",
Expand All @@ -45,6 +46,7 @@
"@types/crypto-js": "^3.1.43",
"@types/mocha": "^7.0.0",
"@types/node": "13.9.3",
"@types/shelljs": "^0.8.8",
"@types/signale": "^1.2.1",
"chai": "^4.2.0",
"globby": "^10.0.1",
Expand Down
44 changes: 44 additions & 0 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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: 'unix command'}),
}

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)
}

}
26 changes: 26 additions & 0 deletions test/commands/run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {expect, test} from '@oclif/test'

describe('run', () => {
test
.stdout()
.command(['run'])
.exit(0)
.it('Nothing is passed', ctx => {
expect(ctx.stdout).to.contain('Command empty or undefined')
})

test
.stdout()
.command(['run', 'echo test'])
.it('Run command with arg for input', ctx => {
expect(ctx.stdout).to.contain('running: echo test')
})

test
.stdout()
.command(['run', '-s', 'echo test'])
.it('Describe cron with -s flag for input', ctx => {
expect(ctx.stdout).to.contain('running: echo test')
})

})