Skip to content

Commit

Permalink
feat(bin): adds cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 30, 2019
1 parent bc5bb63 commit bb50bf9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/bin/main/cmd.ts
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);
}
4 changes: 2 additions & 2 deletions src/bin/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import chalk from 'chalk';
import core, { options } from '~/core';
import { TLogger, IOfType } from '~/types';
import { run } from '~/public';
import _cmd from './cmd';
import series from './series';
import parallel from './parallel';
import list from './list';
Expand Down Expand Up @@ -115,10 +116,9 @@ export default async function main(argv: string[]): Promise<void> {
(cmd._.length ? ` "${cmd._.join('" "')}"` : '')
);

// TODO
switch (first) {
case ':cmd':
return console.log('TODO :cmd');
return _cmd(cmd._);
case ':series':
return series(cmd._);
case ':parallel':
Expand Down

0 comments on commit bb50bf9

Please sign in to comment.