Skip to content

Commit

Permalink
feat(bin): logs full command to be run w/ resolved scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 24, 2019
1 parent 4832bf7 commit 4fc97bc
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions src/bin/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default async function main(argv: string[]): Promise<void> {
if (cmd['--version']) return console.log(pkg.version);
if (!cmd._.length) {
console.log(help + '\n');
throw Error(`kpo requires a command`);
throw Error(`A command is required`);
}

state.setBase({
Expand All @@ -83,11 +83,10 @@ export default async function main(argv: string[]): Promise<void> {
});

let first = cmd._.shift();
let isScoped = false;
while (!first || first[0] === '@') {
if (!first) {
console.log(help + '\n');
throw Error(`kpo requires a command`);
throw Error(`A command is required`);
}

const command = first.split(':');
Expand All @@ -98,35 +97,42 @@ export default async function main(argv: string[]): Promise<void> {
first = command.length
? `:${command.join(':')}`
: (cmd._.shift() as string);

isScoped = true;
}
if (isScoped) {
logger.info('Scope: ' + chalk.bold('@' + state.get('scopes').join(' @')));

// Normalize command on special cases (: and no command)
if (first === ':') first = ':cmd';
else if (first[0] !== ':') {
cmd._.unshift(first);
first = ':run';
}

// Log full command to be run w/ resolved scopes
const scopes = state.get('scopes');
logger.info(
`Running: ${chalk.bold('kpo')}` +
(scopes.length ? chalk.bold.yellow(' @' + scopes.join(' @')) : '') +
chalk.bold.blue(' ' + first) +
(cmd._.length ? ` "${cmd._.join('" "')}"` : '')
);

// TODO
if (first[0] === ':') {
switch (first) {
case ':':
case ':cmd':
return console.log('TODO :cmd');
case ':series':
return console.log('TODO :series');
case ':parallel':
return console.log('TODO :parallel');
case ':list':
return console.log('TODO :list');
case ':raise':
return console.log('TODO :raise');
case ':link':
return console.log('TODO :link');
case ':run':
return run(cmd._);
default:
throw Error('Unknown command ' + first);
}
} else {
return run([first].concat(cmd._));
switch (first) {
case ':cmd':
return console.log('TODO :cmd');
case ':series':
return console.log('TODO :series');
case ':parallel':
return console.log('TODO :parallel');
case ':list':
return console.log('TODO :list');
case ':raise':
return console.log('TODO :raise');
case ':link':
return console.log('TODO :link');
case ':run':
// add arguments after --
return run(cmd._);
default:
throw Error('Unknown command ' + first);
}
}

0 comments on commit 4fc97bc

Please sign in to comment.