program remembers "old" arguments
I declare const { program } = require( 'commander' );
I add the options:
program
.option( '-u, --user <USER>', 'The user to interact with, please use the Discord @Tag function' )
.option( '-t, --tickets <AMOUNT>', 'The amount of tickets to add' )
.option( '-d, --date <DATE>', 'the date for the ticket measurement', client.getCurrentDate() )
.option( '-s, --start <DATE>', '' )
.option( '-e, --end <DATE>', '' );
I then call my program with the following args:
<PROGRAM> -u @<username> -d <date>
I then again call my program with:
<PROGRAM> -d <date>
expecting only the -d flag having a value, but on closer inspection of program I see that the -u / --user object still has a value.
I looked for a clear option or something related, but couldn't find one.
tried it with versions 5.1.0 and 6.0.0-0
my expectation was that calling program.parse(args) would clear all "old" data
If you need more information, I will happily supply it
I am guessing your application stays running and you are calling parse twice on the same program object?
program.parse does not clear out the old data. The way to get a clean parse each time is create a new object each time. e.g.
function doParse(args) {
const program = new Command();
// configure program
program.parse(args);
}
You are absolutely right. I am (mis-) using commander for a Discord bot, therefore the program keeps running.
Your suggestion fixed my issue.
Thanks! you can close this issue
ps. i am kinda new to Node, so excuse me if this is like standard practice within Node programming.
Glad that solves your problem. 🙂 Thanks for update.