-
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.
feat: treat 'default' keys in Task.Record as the task to be run for i…
…ts top level
- Loading branch information
Showing
8 changed files
with
131 additions
and
33 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,60 @@ | ||
import { Task } from '../definitions'; | ||
import { list, series, raises, print, log } from '../tasks'; | ||
import { stripIndent as indent } from 'common-tags'; | ||
import { flags, safePairs } from 'cli-belt'; | ||
import chalk from 'chalk'; | ||
import arg from 'arg'; | ||
|
||
interface Params { | ||
argv: string[]; | ||
record: Task.Record; | ||
} | ||
|
||
interface Options { | ||
bin: string; | ||
} | ||
|
||
export default async function bin( | ||
params: Params, | ||
opts: Options | ||
): Promise<Task> { | ||
const help = indent` | ||
${chalk.bold(`Lists ${opts.bin} tasks`)} | ||
Usage: | ||
$ ${opts.bin} :list [options] | ||
Options: | ||
--defaults List default tasks and subtasks by their own | ||
-h, --help Show help | ||
`; | ||
|
||
const types = { | ||
'--defaults': Boolean, | ||
'--help': Boolean | ||
}; | ||
|
||
const { options, aliases } = flags(help); | ||
safePairs(types, options, { fail: true, bidirectional: true }); | ||
Object.assign(types, aliases); | ||
const cmd = arg(types, { | ||
argv: params.argv, | ||
permissive: false, | ||
stopAtPositional: true | ||
}); | ||
|
||
if (cmd['--help']) return print(help + '\n'); | ||
if (cmd._.length) { | ||
return series( | ||
print(help + '\n'), | ||
raises(Error(`Unknown subcommand: ${cmd._[0]}`)) | ||
); | ||
} | ||
|
||
return series( | ||
log('debug', 'Working directory:', process.cwd()), | ||
log('info', chalk.bold(opts.bin), chalk.bold.blue(':list')), | ||
print(), | ||
list(params.record, { defaults: cmd['--defaults'], bin: opts.bin }) | ||
); | ||
} |
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
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
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