Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Aug 18, 2024
1 parent b4e25c0 commit e511d78
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions examples/optional-value.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@ import { parseArgs } from 'node:util';
import process from 'node:process';

const options = {
'host': { type: 'string', preset: 'localhost', short: 'h', default: 'default.com' },
'debug': { type: 'boolean', short:'d' },
'host': {
type: 'string', short: 'h', default: 'default.com',
preset: 'localhost'
},
'debug': { type: 'boolean', short: 'd' },
};

let args = process.argv.slice(2);
const args = process.argv.slice(2);

do {
const { tokens } = parseArgs({ args, options, strict:false, tokens: true });
const { tokens } = parseArgs({ args, options, strict: false, tokens: true });
// Insert preset if:
// - missing value, like: --host
// - value came from following argument we want to process as option, like: --host --debug
// - value came from following option argument, like: --host --debug
// An empty string is a valid value for a string-type option.
const needsPreset = tokens.find((token) =>
token.kind === 'option'
&& options[token.name]
&& options[token.name].type === 'string'
&& options[token.name].preset !== undefined
&& (token.value === undefined || (token.value.startsWith('-') && !token.inlineValue)));
token.kind === 'option' &&
options[token.name] &&
options[token.name].type === 'string' &&
options[token.name].preset !== undefined &&
(
token.value === undefined ||
(token.value.startsWith('-') && !token.inlineValue)
));

if (!needsPreset) break;

Expand All @@ -33,7 +39,7 @@ do {
} while (true);


const { values } = parseArgs({args, options, allowPositionals: true });
const { values } = parseArgs({ args, options });
console.log(values);

// Try the following:
Expand Down

0 comments on commit e511d78

Please sign in to comment.