import commander from "commander"; import inquirer from "inquirer"; import { PackageManager } from "./PackageManager"; export namespace ArgumentParser { export type Inquiry = ( pack: PackageManager, command: commander.Command, prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule, action: (closure: (options: Partial) => Promise) => Promise, ) => Promise; export const parse = async ( pack: PackageManager, inquiry: ( pack: PackageManager, command: commander.Command, prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule, action: (closure: (options: Partial) => Promise) => Promise, ) => Promise, ): Promise => { // TAKE OPTIONS const action = (closure: (options: Partial) => Promise) => new Promise((resolve, reject) => { commander.program.action(async (options) => { try { resolve(await closure(options)); } catch (exp) { reject(exp); } }); commander.program.parseAsync().catch(reject); }); return inquiry( pack, commander.program, inquirer.createPromptModule, action, ); }; }