-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable no-console */ | ||
import { stripIndent as indent } from 'common-tags'; | ||
import arg from 'arg'; | ||
import { flags, safePairs } from 'cli-belt'; | ||
import core from '~/core'; | ||
|
||
export default async function series(argv: string[]): Promise<void> { | ||
const help = indent` | ||
Usage: | ||
$ kpo :cmd [options] [command] [arguments] | ||
Runs a command | ||
Options: | ||
-h, --help Show help | ||
Examples: | ||
$ kpo : foo --bar --baz | ||
$ kpo :cmd foo --bar --baz | ||
`; | ||
|
||
const types = { | ||
'--help': Boolean | ||
}; | ||
|
||
const { options, aliases } = flags(help); | ||
safePairs(types, options, { fail: true, bidirectional: true }); | ||
Object.assign(types, aliases); | ||
const cmd = arg(types, { argv, permissive: false, stopAtPositional: true }); | ||
|
||
if (cmd['--help']) return console.log(help); | ||
|
||
if (!cmd._.length) { | ||
console.log(help + '\n'); | ||
throw Error(`A command is required`); | ||
} | ||
return core.exec(cmd._[0], cmd._.slice(1), false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters