Skip to content

Commit

Permalink
fix: Upgrade Commander to v13
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jan 8, 2025
1 parent 756ef43 commit c5ee80b
Show file tree
Hide file tree
Showing 5 changed files with 443 additions and 162 deletions.
2 changes: 1 addition & 1 deletion packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@cspell/url": "workspace:*",
"chalk": "^5.4.1",
"chalk-template": "^1.1.0",
"commander": "^12.1.0",
"commander": "^13.0.0",
"cspell-dictionary": "workspace:*",
"cspell-gitignore": "workspace:*",
"cspell-glob": "workspace:*",
Expand Down
35 changes: 15 additions & 20 deletions packages/cspell/src/app/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ exports[`Validate cli > app 'check help' Expect Error: 'outputHelp' 1`] = `
[
"Usage: cspell check [options] <files...>",
"",
"Spell check file(s) and display the result. The full file is displayed in",
"color.",
"Spell check file(s) and display the result. The full file is displayed in color.",
"",
"Options:",
" -c, --config <cspell.json> Configuration file to use. By default cspell",
Expand Down Expand Up @@ -628,8 +627,8 @@ exports[`Validate cli > app 'lint --help --issue-template' Expect Error: 'output
" -u, --unique Only output the first instance of a word not",
" found in the dictionaries.",
" -e, --exclude <glob> Exclude files matching the glob pattern. This",
" option can be used multiple times to add",
" multiple globs.",
" option can be used multiple times to add multiple",
" globs.",
" --file-list <path or stdin> Specify a list of files to be spell checked. The",
" list is filtered against the glob file patterns.",
" Note: the format is 1 file path per line.",
Expand Down Expand Up @@ -662,8 +661,7 @@ exports[`Validate cli > app 'lint --help --issue-template' Expect Error: 'output
" --gitignore Ignore files matching glob patterns found in",
" .gitignore files.",
" --no-gitignore Do NOT use .gitignore files.",
" --gitignore-root <path> Prevent searching for .gitignore files past",
" root.",
" --gitignore-root <path> Prevent searching for .gitignore files past root.",
" --validate-directives Validate in-document CSpell directives.",
" --color Force color.",
" --no-color Turn off color.",
Expand Down Expand Up @@ -772,8 +770,8 @@ exports[`Validate cli > app 'lint --help --verbose' Expect Error: 'outputHelp' 1
" -u, --unique Only output the first instance of a word not",
" found in the dictionaries.",
" -e, --exclude <glob> Exclude files matching the glob pattern. This",
" option can be used multiple times to add",
" multiple globs.",
" option can be used multiple times to add multiple",
" globs.",
" --file-list <path or stdin> Specify a list of files to be spell checked. The",
" list is filtered against the glob file patterns.",
" Note: the format is 1 file path per line.",
Expand Down Expand Up @@ -806,8 +804,7 @@ exports[`Validate cli > app 'lint --help --verbose' Expect Error: 'outputHelp' 1
" --gitignore Ignore files matching glob patterns found in",
" .gitignore files.",
" --no-gitignore Do NOT use .gitignore files.",
" --gitignore-root <path> Prevent searching for .gitignore files past",
" root.",
" --gitignore-root <path> Prevent searching for .gitignore files past root.",
" --validate-directives Validate in-document CSpell directives.",
" --color Force color.",
" --no-color Turn off color.",
Expand Down Expand Up @@ -909,8 +906,8 @@ exports[`Validate cli > app 'lint --help' Expect Error: 'outputHelp' 1`] = `
" -u, --unique Only output the first instance of a word not",
" found in the dictionaries.",
" -e, --exclude <glob> Exclude files matching the glob pattern. This",
" option can be used multiple times to add",
" multiple globs.",
" option can be used multiple times to add multiple",
" globs.",
" --file-list <path or stdin> Specify a list of files to be spell checked. The",
" list is filtered against the glob file patterns.",
" Note: the format is 1 file path per line.",
Expand Down Expand Up @@ -943,8 +940,7 @@ exports[`Validate cli > app 'lint --help' Expect Error: 'outputHelp' 1`] = `
" --gitignore Ignore files matching glob patterns found in",
" .gitignore files.",
" --no-gitignore Do NOT use .gitignore files.",
" --gitignore-root <path> Prevent searching for .gitignore files past",
" root.",
" --gitignore-root <path> Prevent searching for .gitignore files past root.",
" --validate-directives Validate in-document CSpell directives.",
" --color Force color.",
" --no-color Turn off color.",
Expand Down Expand Up @@ -1044,8 +1040,8 @@ exports[`Validate cli > app 'no-args' Expect Error: 'outputHelp' 1`] = `
" -u, --unique Only output the first instance of a word not",
" found in the dictionaries.",
" -e, --exclude <glob> Exclude files matching the glob pattern. This",
" option can be used multiple times to add",
" multiple globs.",
" option can be used multiple times to add multiple",
" globs.",
" --file-list <path or stdin> Specify a list of files to be spell checked. The",
" list is filtered against the glob file patterns.",
" Note: the format is 1 file path per line.",
Expand Down Expand Up @@ -1078,8 +1074,7 @@ exports[`Validate cli > app 'no-args' Expect Error: 'outputHelp' 1`] = `
" --gitignore Ignore files matching glob patterns found in",
" .gitignore files.",
" --no-gitignore Do NOT use .gitignore files.",
" --gitignore-root <path> Prevent searching for .gitignore files past",
" root.",
" --gitignore-root <path> Prevent searching for .gitignore files past root.",
" --validate-directives Validate in-document CSpell directives.",
" --color Force color.",
" --no-color Turn off color.",
Expand Down Expand Up @@ -1660,8 +1655,8 @@ exports[`Validate cli > app 'trace help' Expect Error: 'outputHelp' 1`] = `
"Options:",
" -c, --config <cspell.json> Configuration file to use. By default cspell",
" looks for cspell.json in the current directory.",
" --locale <locale> Set language locales. i.e. "en,fr" for English",
" and French, or "en-GB" for British English.",
" --locale <locale> Set language locales. i.e. "en,fr" for English and",
" French, or "en-GB" for British English.",
" --language-id <language> Use programming language. i.e. "php" or "scala".",
" --allow-compound-words Turn on allowCompoundWords",
" --no-allow-compound-words Turn off allowCompoundWords",
Expand Down
11 changes: 3 additions & 8 deletions packages/cspell/src/app/commandLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,15 @@ function augmentCommandHelp(context: AddHelpTextContext) {
const showHidden = !!opts.verbose;
const hiddenHelp: string[] = [];
const help = command.createHelp();
help.helpWidth = process.stdout.columns || 80;
const hiddenOptions = command.options.filter((opt) => opt.hidden && showHidden);
const flagColWidth = Math.max(...command.options.map((opt) => opt.flags.length), 0);
const indent = flagColWidth + 4;
// const indent = flagColWidth + 4;
for (const options of hiddenOptions) {
if (!hiddenHelp.length) {
hiddenHelp.push('\nHidden Options:');
}
hiddenHelp.push(
help.wrap(
` ${options.flags.padEnd(flagColWidth)} ${options.description}`,
process.stdout.columns || 80,
indent,
),
);
hiddenHelp.push(help.formatItem(options.flags, flagColWidth, options.description, help));
}
output.push(...hiddenHelp, advanced);
return helpIssueTemplate(opts) + output.join('\n');
Expand Down
12 changes: 9 additions & 3 deletions pnpm-lock.yaml

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

Loading

0 comments on commit c5ee80b

Please sign in to comment.