Node.js Scripts โ Guided Argument Input
Table of Contents
- Overview
- Enabling
- Supported
argparsePatterns - Supported
parseArgsPatterns - Known Limitations
- Related Settings
Overview
When workspaceTasks.task.guidedArgInput is enabled, running a Node.js script with Run with Args can prompt for each option individually instead of requiring a raw argument string.
The extension supports static discovery for:
argparse(Node port of Pythonargparse)parseArgsfromnode:utilparseArgspolyfill from@pkgjs/parseargs
If discovery fails (unsupported patterns, dynamic option definitions, or no known argument parser import), the extension falls back to the additional-arguments free-form prompt.
Enabling
In VS Code Settings (Ctrl+, / Cmd+,) search for guidedArgInput, or add to settings.json:
"workspaceTasks.task.guidedArgInput": true
Supported argparse Patterns
The Node resolver follows the common nodeca/argparse style:
const { ArgumentParser } = require('argparse')orimport { ArgumentParser } from 'argparse'parser.add_argument('-n', '--name', { ... })parser.add_argument(['-n', '--name'], { ... })
Supported option properties:
type(int,float,str/string,number,bool/boolean)requireddefaultchoiceshelpaction(store_true,store_false,append,extend,count)nargs(?,*,+, integer)
Actions help and version are intentionally skipped.
Example:
const { ArgumentParser } = require('argparse');
const parser = new ArgumentParser({ description: 'Node.js argparse demo' });
parser.add_argument('-n', '--name', {
help: 'The user name',
required: true,
});
parser.add_argument('-v', '--verbose', {
action: 'store_true',
help: 'Show more details',
});
const args = parser.parse_args();
console.log(args.name, args.verbose);
Supported parseArgs Patterns
The Node resolver also parses static parseArgs config objects from:
const { parseArgs } = require('node:util')import { parseArgs } from 'node:util'const { parseArgs } = require('@pkgjs/parseargs')import { parseArgs } from '@pkgjs/parseargs'
It reads the options map and supports:
type: 'string' | 'boolean'defaultmultiple
Example:
const { parseArgs } = require('node:util');
const options = {
name: { type: 'string', short: 'n', default: 'User' },
verbose: { type: 'boolean', short: 'v' },
tag: { type: 'string', multiple: true },
};
const { values } = parseArgs({ options, allowPositionals: true, strict: false });
console.log(values);
For multiple: true, guided input collects repeated values and assembles repeated flag pairs (--tag a --tag b).
Known Limitations
- Static analysis only; no execution or AST evaluation.
- Dynamically generated options (loops, helpers, computed keys) may not be detected.
- Positional-only arguments are not currently surfaced in guided prompts.
parseArgsmetadata outside theoptionsobject is ignored for guided prompts (for exampleallowPositionals,strict, andtokens).
When discovery misses parameters, the extension still allows manual free-form arguments.
Related Settings
| Setting | Default | Description |
|---|---|---|
workspaceTasks.task.guidedArgInput | true | Enable guided argument input for supported script types |