Unopinionated, no-frills CLI argument parser for Node.js applications
Overall
score
99%
Build a command-line argument parser that handles boolean flags and basic string options for a deployment tool.
Create a parser that processes command-line arguments with the following behavior:
-- (e.g., --verbose, --force)- (e.g., -v, -f)true--name value syntax--name=value syntax-v for --verbose)_ property as an array--verbose should parse as { verbose: true, _: [] } @test-v aliased to --verbose should parse as { verbose: true, _: [] } @test--force --verbose should parse as { force: true, verbose: true, _: [] } @test--name Alice should parse as { name: 'Alice', _: [] } @test--verbose deploy production should parse as { verbose: true, _: ['deploy', 'production'] } @test@generates
/**
* Parses command-line arguments according to a specification.
*
* @param {Object} spec - Specification object mapping argument names to types or aliases
* @param {Array<string>} [argv] - Optional array of arguments to parse (defaults to process.argv.slice(2))
* @returns {Object} Parsed arguments with a `_` property for positional args
*/
function parseArgs(spec, argv) {
// IMPLEMENTATION HERE
}
module.exports = { parseArgs };Provides CLI argument parsing support.
Install with Tessl CLI
npx tessl i tessl/npm-argdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10