Files
bruno/packages/bruno-cli/src/commands/run.js
2023-02-06 03:40:13 +05:30

45 lines
843 B
JavaScript

const chalk = require('chalk');
const {
exists,
isFile,
isDirectory
} = require('../utils/filesystem');
const {
runSingleRequest
} = require('../runner/run-single-request');
const {
CLI_EPILOGUE,
} = require('../constants');
const command = 'run <filename>';
const desc = 'Run a request';
const builder = async (yargs) => {
yargs.example('$0 run request.bru', 'Run a request');
};
const handler = async function (argv) {
try {
const { filename } = argv;
const pathExists = await exists(filename);
if(!pathExists) {
console.error(chalk.red(`File or directory ${filename} does not exist`));
}
const _isFile = await isFile(filename);
if(_isFile) {
runSingleRequest(filename);
}
} catch (err) {
console.error(err);
}
};
module.exports = {
command,
desc,
builder,
handler
};