‘program.opts()’ is returning empty instead of showing me the options I’ve added to my command

I’m trying to develop a cli utility in JavaScript & node.js that is similar to the sed command in Unix. I’ve made a command using the Commander library, that seeks for a word in a file and replaces it with another. I also need to add options to the command itself and, following Commander’s documentation, I added said options. One of the options is ‘-n’ which is supposed to prevent anything (Only the successful message for now) from being printed when you execute the command. However, I noticed that my validation wasn’t working and it would still print the successful message. Eventually I found out that my validation wasn’t working because the ‘program.opts()’ (‘cmdr.opts()’ in my code) is returning empty. According to the documentation, ‘opts()’ is where all the options that I add, should be and if I do console.log(program.opts()) I should get back an object with all the options as properties.

I’ve spent some time reading the documentation but I cannot find anything about it. I even asked ChatGPT and it said that my code was fine and it should work… So I’m not really sure of what I’m missing or not seeing.

Any help would be much appreciated.
Kind regards!

Code:

const { Command } = require('commander');
const fs = require('fs');
const { access } = require('fs/promises');
const { exit, argv } = require('process');

const folderPath = "./assets";

if (!fs.existsSync(folderPath)) {
    fs.mkdirSync(folderPath);
}

const cmdr = new Command();

cmdr
    .command('ac <content> <path>')
    .description('Creates a new file with content in the assets directory.')
    .action((content, path) => {
        let fileContent = content;

        let filePath = folderPath + path;
        fs.writeFileSync(filePath, fileContent);
    });

cmdr
    .command('rd')
    .description('Reads and returns the name of all files in the directory.')
    .action(() => {
        try {
            files = fs.readdirSync(folderPath);
            console.log(files);
        } catch (error) {
            console.log(error);
        }
    });


async function main() {

    cmdr
        .command('s <cmd> <file>')
        .description('Modifies a string, by first selecting a target file.')
        .option('-n, --negate', 'Prevents a line from being printed unless specified by "-p".')
        .option('-i', 'Forces sed to edit the file instead of printing to the standar output.')
        .option('-e', 'Accepts multiple substitution commands with one command per "-e" appearance.')
        .option('-f <file>', 'Expects a file which consists of several lines containing one command each.')
        .option('-p, --print', 'Prints the line on the terminal.')
        .option('-g', 'Substitutes all instances of the search.')
        .action(async(cmd, file) => {

            const options = cmdr.opts();
            const [find, substitute] = cmd.split('/');
            const filePath = file;
            
            try {
                await access(filePath);
            } catch (error) {
                console.error('FILE DOES NOT EXISTS.', error);
                exit(1);
            }

            let data;

            try {
                data = await fs.promises.readFile(filePath, 'utf-8');
            } catch (error) {
                console.log('ERROR WHILE READING THE FILE.', error);
                exit(1)
            }

            try {
                const newContent = data.replace(new RegExp(find), substitute);

                await fs.promises.writeFile(filePath, newContent, 'utf-8');
                    console.log(cmdr.opts());
                    console.log(cmdr.negate);
                    console.log(options.n);
                    console.log(options.negate);
                    if (!options.negate) {
                        console.log(`The words in the file ${filePath} have been successfully substituted.`);
                    }
                } catch (error) {
                console.log('STRING NOT FOUND.', error);
                exit(1)
            }
        });

    cmdr.parseAsync(process.argv);

}

main();

I’ve tried to log the options in these ways:

                console.log(cmdr.opts());
                console.log(cmdr.negate);
                console.log(options.n);
                console.log(options.negate);

I’ve also tried to parse before the action, inside the action and using parseOptions() but to no avail.