python-archieve-projects/WechatBot/node_modules/cmd-ts/dist/deno_cjs/binary.ts

25 lines
645 B
TypeScript

import { Runner } from './runner.ts';
import { ParseContext } from './argparser.ts';
import { Named } from './helpdoc.ts';
/**
* A small helper to easily use `process.argv` without dropping context
*
* @param cmd a command line parser
*/
export function binary<Command extends Runner<any, any> & Named>(
cmd: Command
): Command {
return {
...cmd,
run(context: ParseContext) {
const name = cmd.name || context.nodes[1].raw;
context.hotPath?.push(name);
context.nodes.splice(0, 1);
context.nodes[0].raw = name;
context.visitedNodes.add(context.nodes[0]);
return cmd.run(context);
},
};
}