Skip to content

Run script of my vorpal commands does not work on async functions #346

Open
@ghost

Description

I tried to write a script runner, but it does not wait for async functions:

vorpal
    .command('run <file_name>', 'Run a script file')
    .validate(function (args) {
        if (fs.existsSync(args.file_name)) {
            return true;
        } else {
            return `File does not exists '${args.file_name}'`;
        }
    })
    .action(function (args, callback) {
        const scriptLines = fs.readFileSync(args.file_name).toString().split('\n');
        for (const line of scriptLines) {
            if (line.trim() !== '') {
                vorpal.execSync(line);
            }
        }
        callback();
    });

Tried that too, but it exits instantly:

vorpal
    .command('run <file_name>', 'Run a script file')
    .validate(function (args) {
        if (fs.existsSync(args.file_name)) {
            return true;
        } else {
            return `File does not exists '${args.file_name}'`;
        }
    })
    .action(async function (args, callback) {
        const scriptLines = fs.readFileSync(args.file_name).toString().split('\n');
        for (const line of scriptLines) {
            if (line.trim() !== '') {
                await vorpal.exec(line);
            }
        }
        callback();
    });

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions