-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Hey all, i'm trying to separate out the action handler for a top-level command with the code below.
the options variable in my action handler is undefined, and it's unclear why.
// src/ts/program.ts
import { Command } from 'commander';
const program = new Command('cmd-name');
program
.version('0.0.1') // real code loads this from package.json
.description("program description string")
.argument('<input-file>', 'file for operations')
.requiredOption('-c --customer-name <comp>', 'description');
//add more .option()
export default program;//src/ts/cli.ts
import program from './program';
program.action((input_file: string, options: Object): Promise<any> => {
console.log(`input_file: ${input_file}`);
console.log(`options: ${JSON.stringify(options, null, 2)}`);
/* more code here */
});
(async () => {
return await program.parseAsync(process.argv);
})();so per the documentation, options should be an Object, but running this code, i get
$> node dist/cli-bundle.js -- -c upt ./foo-bar.txt
which displays:
input_file: ./foo-bar.txt
options: undefined
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels