Skip to content

Commit

Permalink
Updates yargs-parser config. Closes pnp#6211
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-it authored and milanholemans committed Aug 24, 2024
1 parent a0e1bec commit 7312e55
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
1 change: 0 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@
"easy-table": "^1.2.0",
"jmespath": "^0.16.0",
"json-to-ast": "^2.1.0",
"minimist": "^1.2.8",
"node-forge": "^1.3.1",
"omelette": "^0.4.17",
"open": "^10.1.0",
Expand Down
13 changes: 13 additions & 0 deletions src/cli/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1859,4 +1859,17 @@ describe('cli', () => {
await cli.execute(['cli', 'completion', 'sh', 'update']);
assert(loadAllCommandsInfoStub.calledWith(true));
});

it('validates if yargs parser has correct configuration', async () => {
const yargsConfiguration = cli.yargsConfiguration;

assert.deepStrictEqual(yargsConfiguration, {
'parse-numbers': true,
'strip-aliased': true,
'strip-dashed': true,
'dot-notation': false,
'boolean-negation': true,
'camel-case-expansion': false
});
});
});
19 changes: 12 additions & 7 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ const defaultHelpMode = 'options';
const defaultHelpTarget = 'console';
const helpModes: string[] = ['options', 'examples', 'remarks', 'response', 'full'];
const helpTargets: string[] = ['console', 'web'];
const yargsConfiguration: Partial<yargs.Configuration> = {
'parse-numbers': true,
'strip-aliased': true,
'strip-dashed': true,
'dot-notation': false,
'boolean-negation': true,
'camel-case-expansion': false
};

function getConfig(): Configstore {
if (!_config) {
Expand Down Expand Up @@ -166,7 +174,7 @@ async function execute(rawArgs: string[]): Promise<void> {
if (!result.success) {
return cli.closeWithError(result.error, cli.optionsFromArgs, true);
}

finalArgs = result.data;
}
else {
Expand Down Expand Up @@ -477,11 +485,7 @@ function getCommandOptions(command: Command): CommandOptionInfo[] {
function getCommandOptionsFromArgs(args: string[], commandInfo: CommandInfo | undefined): yargs.Arguments {
const yargsOptions: yargs.Options = {
alias: {},
configuration: {
"parse-numbers": false,
"strip-aliased": true,
"strip-dashed": true
}
configuration: yargsConfiguration
};

let argsToParse = args;
Expand Down Expand Up @@ -1015,5 +1019,6 @@ export const cli = {
printAvailableCommands,
promptForConfirmation,
promptForSelection,
shouldTrimOutput
shouldTrimOutput,
yargsConfiguration
};

0 comments on commit 7312e55

Please sign in to comment.