1

I am using yargs in a CLI application. In Windows platform (development environment), I am able to invoke the commands but when I pack and run it on Amazon Linux the yargs argv is not containing the command and parameters.

I am packaging the node_modules as bundled dependencies and directly running the command on remote machine.

command:

./yargcmd.sh --command command1 --param1 2022-06-20T00:00:00.000Z --param2 2022-06-20T23:59:59.999Z

export class Cli {
    private commandMap: { [key: string]: any; } = {};

    constructor() {
        this.commandMap['command1'] = new Command1();
        this.commandMap['command2'] = new Command2();
        this.commandMap['command3'] = new Command3();
        this.commandMap['command4'] = new Command4();
    }

    public async execute(): Promise<string> {
        const argv = yargs.argv;
        console.log(JSON.stringify(argv));
        let command = this.commandMap[argv.command];
        if ( command != null) {
            await command.execute();
        } else {
            if ( argv.command != null ) {
                console.log('Command not found: ' + argv.command);
            }
            console.log('***** Available Commands *****');
            for(let key in this.commandMap) {
                console.log(this.commandMap[key].help());
            }
        }

        return 'Executed command: ' + argv.command;
    }
}

let cli: Cli = new Cli();
cli.execute();

Output on the console for stringified argv

Windows - {"_":[],"command":"command1","param1":"2022-06-20T00:00:00.000Z","param2":"2022-06-20T23:59:59.999Z","$0":"Cli.js"}

Amazon Linux - {"_":[],"$0":"Cli.js"}

S7H
  • 1,421
  • 1
  • 22
  • 37

0 Answers0