Use path.relative when printing argparse cmd
This commit is contained in:
parent
f1865a0cc4
commit
c0b245067b
@ -1,3 +1,5 @@
|
|||||||
|
import {relative} from 'path'
|
||||||
|
|
||||||
export type TArgTypeName = 'string' | 'string[]' | 'number' | 'boolean'
|
export type TArgTypeName = 'string' | 'string[]' | 'number' | 'boolean'
|
||||||
export type TArgType<T extends TArgTypeName> =
|
export type TArgType<T extends TArgTypeName> =
|
||||||
T extends 'string'
|
T extends 'string'
|
||||||
@ -183,7 +185,7 @@ export function help(command: string, config: IArgsConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const positionalHelp = [
|
const positionalHelp = [
|
||||||
command,
|
relative(process.cwd(), command),
|
||||||
'[OPTIONS]',
|
'[OPTIONS]',
|
||||||
keys
|
keys
|
||||||
.filter(k => config[k].positional)
|
.filter(k => config[k].positional)
|
||||||
|
|||||||
@ -7,20 +7,20 @@ import {argparse, arg} from '@rondo/argparse'
|
|||||||
const {parse} = argparse({
|
const {parse} = argparse({
|
||||||
help: arg('boolean'),
|
help: arg('boolean'),
|
||||||
debug: arg('boolean'),
|
debug: arg('boolean'),
|
||||||
command: arg('string', {required: true, positional: true}),
|
command: arg('string[]', {n: '+', required: true, positional: true}),
|
||||||
other: arg('string[]', {n: '*', positional: true}),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
type TArgs = ReturnType<typeof parse>
|
type TArgs = ReturnType<typeof parse>
|
||||||
|
|
||||||
async function run(args: TArgs) {
|
async function run(args: TArgs) {
|
||||||
if (!(args.command in commands)) {
|
const commandName = args.command[0]
|
||||||
|
if (!(commandName in commands)) {
|
||||||
const c = Object.keys(commands).filter(cmd => !cmd.startsWith('_'))
|
const c = Object.keys(commands).filter(cmd => !cmd.startsWith('_'))
|
||||||
log.info(`Available commands:\n\n${c.join('\n')}`)
|
log.info(`Available commands:\n\n${c.join('\n')}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const command = (commands as any)[args.command] as TCommand
|
const command = (commands as any)[commandName] as TCommand
|
||||||
await command(args.command, ...args.other)
|
await command(...args.command)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof require !== 'undefined' && require.main === module) {
|
if (typeof require !== 'undefined' && require.main === module) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user