Skip to content

Commit

Permalink
feat: allow context prefix to be a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 3, 2021
1 parent 7c1310b commit 405b0ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default async function main(
file: cmd['--file'],
dir: cmd['--dir'],
level: cmd['--level'] as LogLevel,
prefix: (cmd['--prefix'] ? 'all' : 'none') as PrefixPolicy,
prefix: cmd['--prefix'],
env: (cmd['--env'] || []).reduce((acc, str) => {
const arr = str.split('=');
if (arr.length !== 2) {
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface Context {
* lines of its *stdout* and *stderr* writes
* with the stringification of its route.
*/
readonly prefix: PrefixPolicy;
readonly prefix: PrefixPolicy | boolean;
/**
* A *Promise* representing a task's
* cancellation token.
Expand Down
14 changes: 11 additions & 3 deletions src/helpers/prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import { Context } from '../definitions';
import { styleString } from './style-string';
import { stringifyRoute } from './stringify-route';
import { into } from 'pipettes';
import { TypeGuard } from 'type-core';

export function getPrefix(
extra: null | string,
target: 'print' | 'exec',
context: Context
): string {
return into(
context.route.length ? stringifyRoute(context.route) : '',
(prefix) => {
if (!prefix || (context.prefix !== target && context.prefix !== 'all')) {
{
prefix: context.route.length ? stringifyRoute(context.route) : '',
policy: TypeGuard.isString(context.prefix)
? context.prefix
: context.prefix
? 'all'
: 'none'
},
({ prefix, policy }) => {
if (!prefix || (policy !== target && policy !== 'all')) {
return extra ? extra + ' ' : null;
}
return (
Expand Down

0 comments on commit 405b0ce

Please sign in to comment.