From fa29138fd1bb4ac0b574086caf5dd721c17e676b Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Mon, 11 Dec 2023 17:31:32 +0200 Subject: [PATCH] fix: bugfixes, build updates --- .github/workflows/docs.yml | 47 +++++++++++++++++++++ .github/workflows/{main.yml => release.yml} | 0 .prettierignore | 4 +- CHANGELOG.md | 39 ++++++----------- package.json | 2 +- release.config.cjs | 5 ++- src/command.ts | 2 +- src/option.ts | 45 ++++++++++++-------- test/option.test.ts | 6 +++ typedoc.json | 2 +- 10 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/docs.yml rename .github/workflows/{main.yml => release.yml} (100%) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..32b9d30 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,47 @@ +name: Release +on: + push: + branches: + - master + +permissions: + contents: read # for checkout + +jobs: + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + id-token: write # to enable use of OIDC for npm provenance + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.x' + - name: Install PNPM + run: npm i -g pnpm + - name: Install dependencies + run: pnpm install --frozen-lockfile + - name: Run Tests + run: pnpm test + # - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + # run: npm audit signatures + - name: Semantic Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npx semantic-release + - name: Docs + run: pnpm doc + - name: Deploy on GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs diff --git a/.github/workflows/main.yml b/.github/workflows/release.yml similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/release.yml diff --git a/.prettierignore b/.prettierignore index a52a73c..c72ceb4 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,2 @@ -templates/ -scaffolds/ +gen/ +CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index c085018..3d168b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,32 +1,6 @@ # Change Log -# [2.0.0-pre.3](https://github.com/chenasraf/massarg/compare/v2.0.0-pre.2...v2.0.0-pre.3) (2023-12-02) - - -### Bug Fixes - -* help output formatting/text ([fed6f60](https://github.com/chenasraf/massarg/commit/fed6f602c5e682a2b585fed68ed05d95ed2a0a7e)) -* support help option with early quit ([742b597](https://github.com/chenasraf/massarg/commit/742b597f1ec9392f09b6af181d9c9cee7f680ba6)) - -# [2.0.0-pre.2](https://github.com/chenasraf/massarg/compare/v2.0.0-pre.1...v2.0.0-pre.2) (2023-12-01) - - -### Bug Fixes - -* exported types fixes ([a0aa8ec](https://github.com/chenasraf/massarg/commit/a0aa8ecbb7c112033842f080caaea666a75b88b1)) - - -### Features - -* different opt output name (default camelCase) ([48b9602](https://github.com/chenasraf/massarg/commit/48b96022e42c6de1776485be1d829247f50cb6ad)) - -# [2.0.0-pre.1](https://github.com/chenasraf/massarg/compare/v1.0.6...v2.0.0-pre.1) (2023-11-24) - - -### Continuous Integration - -* update release config ([4b111ab](https://github.com/chenasraf/massarg/commit/4b111ab6f69666a1f5540b08fc932bcf2ac03ee4)) - +# [2.0.0-pre.3](https://github.com/chenasraf/massarg/compare/v1.0.6...v2.0.0-pre.3) (2023-12-02) ### Features @@ -38,6 +12,17 @@ * pass main instance to run fn ([29d6973](https://github.com/chenasraf/massarg/commit/29d6973eecbaa2d86e496387fe946a53c9662466)) * transform output name for options ([c414365](https://github.com/chenasraf/massarg/commit/c414365fbe602419a19f5522055e5b3c2fed761a)) * v2 poc ([7d5d302](https://github.com/chenasraf/massarg/commit/7d5d3025c6c65ee2d858aaf1beed50d847f423b4)) +* different opt output name (default camelCase) ([48b9602](https://github.com/chenasraf/massarg/commit/48b96022e42c6de1776485be1d829247f50cb6ad)) + +### Bug Fixes + +* exported types fixes ([a0aa8ec](https://github.com/chenasraf/massarg/commit/a0aa8ecbb7c112033842f080caaea666a75b88b1)) +* help output formatting/text ([fed6f60](https://github.com/chenasraf/massarg/commit/fed6f602c5e682a2b585fed68ed05d95ed2a0a7e)) +* support help option with early quit ([742b597](https://github.com/chenasraf/massarg/commit/742b597f1ec9392f09b6af181d9c9cee7f680ba6)) + +### Continuous Integration + +* update release config ([4b111ab](https://github.com/chenasraf/massarg/commit/4b111ab6f69666a1f5540b08fc932bcf2ac03ee4)) ### BREAKING CHANGES diff --git a/package.json b/package.json index d984089..92d4d65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "massarg", - "version": "2.0.0-pre.3", + "version": "0.0.0", "description": "Flexible, powerful, and simple command/argument parser for CLI applications", "keywords": [ "shell", diff --git a/release.config.cjs b/release.config.cjs index 30ba482..57513d9 100644 --- a/release.config.cjs +++ b/release.config.cjs @@ -9,8 +9,9 @@ module.exports = { [ '@semantic-release/npm', { - // only update the pkg version on root, don't publish + // only update the pkg version on doc, don't publish npmPublish: false, + pkgRoot: 'doc', }, ], [ @@ -36,7 +37,7 @@ module.exports = { [ '@semantic-release/git', { - assets: ['package.json', 'CHANGELOG.md'], + assets: ['CHANGELOG.md'], }, ], // diff --git a/src/command.ts b/src/command.ts index ef85182..119ae54 100644 --- a/src/command.ts +++ b/src/command.ts @@ -328,7 +328,7 @@ export class MassargCommand { message: 'Unknown option', }) } - const res = option._parseDetails([arg, ...argv], { ...this.args }) + const res = option._parseDetails([arg, ...argv], { ...this.args }, this.optionPrefixes) this.args[res.key as keyof Args] = setOrPush( res.value, this.args[res.key as keyof Args], diff --git a/src/option.ts b/src/option.ts index b72d96c..3854c25 100644 --- a/src/option.ts +++ b/src/option.ts @@ -163,7 +163,7 @@ export class MassargOption { switch (config.type) { case 'number': - return new MassargNumber(config as OptionConfig) as MassargOption + return new MassargNumber(config as OptionConfig) as MassargOption } return new MassargOption(config as OptionConfig) } @@ -172,11 +172,11 @@ export class MassargOption { + _parseDetails(argv: string[], options: ArgsObject, prefixes: Prefixes): ArgvValue { // TODO: support --option=value let input = '' try { - if (!this._match(argv[0])) { + if (!this._match(argv[0], prefixes)) { throw new ParseError({ path: [this.name], code: 'invalid_option', @@ -212,24 +212,26 @@ export class MassargOption { }) } - _parseDetails(argv: string[], options: ArgsObject): ArgvValue { + _parseDetails(argv: string[], options: ArgsObject, prefixes: Prefixes): ArgvValue { try { - const { argv: _argv, value } = super._parseDetails(argv, options) + const { argv: _argv, value } = super._parseDetails(argv, options, prefixes) if (isNaN(value)) { throw new ParseError({ path: [this.name], @@ -324,11 +326,20 @@ export class MassargFlag extends MassargOption { this.negatable = options.negatable ?? false } - _parseDetails(argv: string[]): ArgvValue { + _parseDetails(argv: string[], prefixes: Prefixes): ArgvValue { try { const isNegation = - argv[0]?.startsWith(NEGATE_SHORT_PREFIX) || argv[0]?.startsWith(NEGATE_FULL_PREFIX) - if (!this._match(argv[0])) { + argv[0]?.startsWith(prefixes.negateAliasPrefix) || + argv[0]?.startsWith(prefixes.negateFlagPrefix) + if (!this.negatable && isNegation) { + throw new ParseError({ + path: [this.name], + code: 'invalid_option', + message: `Option ${this.name} cannot be negated`, + received: JSON.stringify(argv[0]), + }) + } + if (!this._match(argv[0], prefixes)) { throw new ParseError({ path: [this.name], code: 'invalid_option', diff --git a/test/option.test.ts b/test/option.test.ts index 75ebf23..fa57c15 100644 --- a/test/option.test.ts +++ b/test/option.test.ts @@ -103,4 +103,10 @@ describe('flag', () => { }), ).toThrow('Expected string, received number') }) + describe('negation', () => { + test('default', () => { + const command = massarg(opts).flag({ name: 'test2', description: 'test2', aliases: [] }) + expect(command.getArgs(['--no-test2'])).toThrow('is not negatable') + }) + }) }) diff --git a/typedoc.json b/typedoc.json index a6860ab..42012ed 100644 --- a/typedoc.json +++ b/typedoc.json @@ -2,7 +2,7 @@ "$schema": "https://typedoc.org/schema.json", "out": "docs", "entryPoints": [ - "src" + "src/**/*.ts" ], "theme": "default", "plugin": [