Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4397716
test_util_parse_args.cjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_util_parse_args.cjs
View Options
const { parseArgs } = require('node:util');
function assert(cond, msg) {
if (!cond) throw new Error(msg);
}
let result = parseArgs({
args: ['--prompt', 'hello', '-c', 'positional'],
options: {
prompt: { type: 'string', short: 'p' },
continue: { type: 'boolean', short: 'c', default: false },
format: { type: 'string', default: 'default' }
},
strict: false,
allowPositionals: true
});
assert(result.values.prompt === 'hello', 'expected string long option');
assert(result.values.continue === true, 'expected boolean short option');
assert(result.values.format === 'default', 'expected default string option');
assert(Array.isArray(result.positionals), 'expected positionals array');
assert(result.positionals.length === 1 && result.positionals[0] === 'positional', 'expected positional passthrough');
result = parseArgs({
args: ['-phello', '--format=json'],
options: {
prompt: { type: 'string', short: 'p' },
format: { type: 'string' }
},
strict: false,
allowPositionals: true
});
assert(result.values.prompt === 'hello', 'expected attached short string value');
assert(result.values.format === 'json', 'expected inline long string value');
console.log('PASS');
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, May 1, 2:19 PM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
542929
Default Alt Text
test_util_parse_args.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment