Skip to content

Commit

Permalink
feat(bin): adds raise
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 30, 2019
1 parent 4408633 commit 583c6ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bin/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import core, { options } from '~/core';
import { TLogger, IOfType } from '~/types';
import { run } from '~/public';
import list from './list';
import raise from './raise';
import logger from '~/utils/logger';

export default async function main(argv: string[]): Promise<void> {
Expand Down Expand Up @@ -128,7 +129,7 @@ export default async function main(argv: string[]): Promise<void> {
case ':list':
return list(cmd._);
case ':raise':
return console.log('TODO :raise');
return raise(cmd._);
case ':run':
const [tasks, args] = splitBy(cmd._);
return run(tasks)(args);
Expand Down
41 changes: 41 additions & 0 deletions src/bin/main/raise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable no-console */
import { stripIndent as indent } from 'common-tags';
import arg from 'arg';
import { flags, safePairs } from 'cli-belt';
import { raise as command } from '~/public';

export default async function list(argv: string[]): Promise<void> {
const help = indent`
Usage:
$ kpo :raise [options]
Raises kpo tasks to package.json
Options:
--confirm Prompt for changes confirmation before performing a write operation
--dry Dry run
--fail Fails if there are any changes to be made on dry mode, or if the user cancels the action when confirmation is required
-h, --help Show help
`;

const types = {
'--confirm': Boolean,
'--dry': Boolean,
'--fail': 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) throw Error('Unknown command: ' + cmd._[0]);

return command.fn({
confirm: cmd['--confirm'],
dry: cmd['--dry'],
fail: cmd['--fail']
});
}

0 comments on commit 583c6ad

Please sign in to comment.