Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support command line options from a file #4109

Merged
merged 2 commits into from
Aug 3, 2024

Conversation

benquarmby
Copy link
Contributor

@benquarmby benquarmby commented Jul 31, 2024

Description

This PR enables yargs' first-class support for a command line options file. It works out of the box and costs very little.

Also updated the CLI options docs while I was here.

Motivation and Context

The commitlint CLI has many arguments now; I counted 20. Composing and encoding all the required arguments for a project at the terminal or in a package script can get hard to maintain. The ability to move those options to a regular JavaScript or JSON module makes them far easier to manage. It is more human readable and writable.

Usage examples

This fabricated example is deliberately verbose and a bit unrealistic to make the point:

{
-   "commit:lint": "commitlint --from $GIT_LAST_TAG --format @some/formatter --parser-preset @some/preset --extends @some/shared-config-1 @some/shared-config-2 --strict --cwd ../project --git-log-args \"--first-parent\""
+   "commit:lint": "commitlint --options ./commitlint.options.cjs"
}
// commitlint.options.cjs
module.exports = {
    from: process.env.GIT_LAST_TAG,
    format: '@some/formatter',
    parserPreset: '@some/preset',

    // Explanatory code comment for this option could go here.
    extends: ['@some/shared-config-1', '@some/shared-config-2'],

    strict: true,
    cwd: '../project',
    gitLogArgs: '--first-parent'
};

How Has This Been Tested?

Added some temporary options files and ran them directly on this repo. Firstly a Common.js module:

// commitlint.options.cjs
module.exports = {
    from: "v19.3.1",
    verbose: true
};
yarn run commitlint --options ./commitlint.options.cjs
CJS Options Output cjs-ouput

And then a JSON file:

{
    "from": "v19.3.1",
    "verbose": true
}
yarn run commitlint --options ./commitlint.options.json
JSON Options Output json-output

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codesandbox-ci bot commented Jul 31, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@escapedcat
Copy link
Member

Hey @benquarmby , sounds great, thanks!
Would you mind updating the failing test-snapshot to get this PR green?

@escapedcat escapedcat merged commit a20e890 into conventional-changelog:master Aug 3, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants