-
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
66 additions
and
12 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
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,50 @@ | ||
/* eslint-disable no-console */ | ||
import { stripIndent as indent } from 'common-tags'; | ||
import arg from 'arg'; | ||
import { flags, safePairs } from 'cli-belt'; | ||
import { stream as command } from '~/public'; | ||
|
||
export default async function stream(argv: string[]): Promise<void> { | ||
const help = indent` | ||
Usage: | ||
$ kpo :stream [options] [commands] | ||
Streams kpo commands for children projects | ||
Options: | ||
--include <values> Include children by name, comma separated | ||
--exclude <values> Exclude children by name, comma separated | ||
--parallel Execute streaming in parallel | ||
--force Continue execution even if some process fails | ||
-h, --help Show help | ||
Examples: | ||
$ kpo :stream :cmd foo --bar --baz | ||
`; | ||
|
||
const types = { | ||
'--include': String, | ||
'--exclude': String, | ||
'--parallel': Boolean, | ||
'--force': Boolean, | ||
'--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 command.fn(cmd._, { | ||
include: cmd['--include'] ? cmd['--include'].split(',') : undefined, | ||
exclude: cmd['--exclude'] ? cmd['--exclude'].split(',') : undefined, | ||
parallel: cmd['--parallel'], | ||
force: cmd['--force'] | ||
}); | ||
} |