diff --git a/.github/workflows/fig.yaml b/.github/workflows/fig.yaml new file mode 100644 index 00000000..a0cdf4c8 --- /dev/null +++ b/.github/workflows/fig.yaml @@ -0,0 +1,35 @@ +name: Fig integration + +on: + push: + branches: + - cli-command-help + +jobs: + push-autocomplete-spec: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 20 + - name: Install Dependencies + run: npm ci + - run: npm run generate-autocomplete-spec + working-directory: packages/cli + + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.GH_APP_ID }} + private_key: ${{ secrets.GH_PRIVATE_KEY }} + + - name: Create Autocomplete PR + uses: withfig/push-to-fig-autocomplete-action@v1 + with: + token: ${{ steps.generate_token.outputs.token }} + autocomplete-spec-name: barnard59 + spec-path: packages/cli/fig-spec.js + integration: commander diff --git a/.gitignore b/.gitignore index 00745fc5..b4ec2058 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ node_modules *.js.map .env *.received.txt +fig-spec.js diff --git a/package-lock.json b/package-lock.json index 568e8973..31512526 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1605,6 +1605,33 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@fig/complete-commander": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@fig/complete-commander/-/complete-commander-3.0.0.tgz", + "integrity": "sha512-jxiF1O+xiqdM7jECmTTrSO5w35iKsVRcSCz9mu20R4bFgLJS+61VNHw2A3EY7gU1kKlLJye0TmkyTfAoPhIq7A==", + "dev": true, + "dependencies": { + "prettier": "^3.1.0" + }, + "peerDependencies": { + "commander": "^11.1.0" + } + }, + "node_modules/@fig/complete-commander/node_modules/prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.10", "dev": true, @@ -9947,8 +9974,9 @@ } }, "node_modules/commander": { - "version": "11.0.0", - "license": "MIT", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", "engines": { "node": ">=16" } @@ -26688,7 +26716,7 @@ }, "packages/cli": { "name": "barnard59", - "version": "4.2.0", + "version": "4.3.2", "license": "MIT", "dependencies": { "@opentelemetry/api": "^1.0.0", @@ -26700,8 +26728,8 @@ "@opentelemetry/semantic-conventions": "^0.24.0", "@opentelemetry/tracing": "^0.24.0", "@rdfjs/namespace": "^2.0.0", - "barnard59-core": "5.1.0", - "barnard59-env": "1.1.0", + "barnard59-core": "5.2.0", + "barnard59-env": "1.2.0", "commander": "^11.0.0", "find-up": "^7.0.0", "is-graph-pointer": "^2.1.0", @@ -26709,6 +26737,7 @@ "lodash": "^4.17.21", "pkg-dir": "^8.0.0", "pkgscan": "^1.0.24", + "rdf-loader-code": "^2.1.1", "readable-stream": "^3.6.0" }, "bin": { @@ -26716,6 +26745,7 @@ "barnard59": "bin/barnard59.sh" }, "devDependencies": { + "@fig/complete-commander": "^3.0.0", "approvals": "^6.2.2", "barnard59-base": "^2.1.0", "barnard59-formats": "^2.1.0", @@ -26846,7 +26876,7 @@ }, "packages/core": { "name": "barnard59-core", - "version": "5.1.0", + "version": "5.2.0", "license": "MIT", "dependencies": { "@opentelemetry/api": "^1.0.1", @@ -26865,7 +26895,7 @@ "devDependencies": { "@rdfjs/namespace": "^2.0.0", "@types/readable-stream": "^4.0.9", - "barnard59-env": "^1.1.0", + "barnard59-env": "^1.2.0", "barnard59-http": "^2.0.0", "barnard59-test-support": "^0.0.3", "chai": "^4.3.7", @@ -26945,14 +26975,14 @@ }, "packages/cube": { "name": "barnard59-cube", - "version": "1.1.1", + "version": "1.2.0", "license": "MIT", "dependencies": { "barnard59-base": "^2.2.0", "barnard59-formats": "^2.0.0", "barnard59-http": "^2.0.0", - "barnard59-rdf": "^3.2.2", - "barnard59-shacl": "^1.1.3", + "barnard59-rdf": "^3.3.0", + "barnard59-shacl": "^1.2.0", "barnard59-sparql": "^2.1.1", "external-merge-sort": "^0.1.3", "lodash": "^4.17.21", @@ -26962,7 +26992,7 @@ }, "devDependencies": { "@rdfjs/to-ntriples": "^2.0.0", - "barnard59-env": "^1.1.0", + "barnard59-env": "^1.2.0", "chai": "^4.3.7", "get-stream": "^6.0.1", "is-stream": "^3.0.0", @@ -26971,7 +27001,7 @@ }, "packages/env": { "name": "barnard59-env", - "version": "1.1.0", + "version": "1.2.0", "license": "MIT", "dependencies": { "@zazuko/env-node": "^1.0.3", @@ -27214,11 +27244,11 @@ }, "packages/rdf": { "name": "barnard59-rdf", - "version": "3.2.2", + "version": "3.3.0", "license": "MIT", "dependencies": { "@rdfjs/fetch": "^3.0.0", - "barnard59-env": "^1.1.0", + "barnard59-env": "^1.2.0", "file-fetch": "^1.7.0", "is-stream": "^3.0.0", "lodash": "^4.17.21", @@ -27376,13 +27406,13 @@ }, "packages/shacl": { "name": "barnard59-shacl", - "version": "1.1.3", + "version": "1.2.0", "license": "MIT", "dependencies": { "@rdfjs/fetch": "^3.0.0", "barnard59-base": "^2.2.0", "barnard59-formats": "^2.1.0", - "barnard59-rdf": "^3.2.2", + "barnard59-rdf": "^3.3.0", "is-stream": "^3.0.0", "rdf-validate-shacl": "^0.5.1", "readable-stream": "3 - 4" @@ -27391,8 +27421,8 @@ "@rdfjs/to-ntriples": "^2.0.0", "@tpluscode/rdf-string": "^1.1.0", "assert-throws-async": "^3.0.0", - "barnard59-core": "^5.1.0", - "barnard59-env": "^1.0.0", + "barnard59-core": "^5.2.0", + "barnard59-env": "^1.2.0", "barnard59-test-support": "*", "chai": "^4.3.4", "express": "^4.18.2", @@ -27668,13 +27698,13 @@ }, "packages/validation": { "name": "barnard59-validation", - "version": "0.4.0", + "version": "0.4.1", "license": "MIT", "dependencies": { "@rdfjs/namespace": "^2.0.0", "anylogger": "^1.0.11", "anylogger-console": "^1.0.0", - "barnard59-env": "^1.1.0", + "barnard59-env": "^1.2.0", "chalk": "^4.1.0", "commander": "^11.0.0", "rdf-loader-code": "^2.1.1" @@ -27685,7 +27715,7 @@ "devDependencies": { "@jsdevtools/chai-exec": "^2.1.1", "barnard59-base": "^2.0.1", - "barnard59-core": "^5.0.0", + "barnard59-core": "^5.2.0", "barnard59-formats": "^2.1.0", "chai": "^4.3.0", "deep-equal": "^2.0.5", @@ -27753,11 +27783,11 @@ }, "test/e2e": { "name": "barnard59-test-e2e", - "version": "0.0.4", + "version": "0.0.5", "dependencies": { "barnard59-base": "^2.0.1", - "barnard59-core": "^5.0.0", - "barnard59-env": "^1.0.0", + "barnard59-core": "^5.2.0", + "barnard59-env": "^1.2.0", "barnard59-formats": "^2.1.0", "barnard59-http": "^2.0.0", "barnard59-test-support": "^0.0.3", diff --git a/packages/cli/bin/barnard59.js b/packages/cli/bin/barnard59.js index 3f567d7a..7d774714 100755 --- a/packages/cli/bin/barnard59.js +++ b/packages/cli/bin/barnard59.js @@ -95,7 +95,8 @@ const onError = async err => { // Dynamically import the rest once the SDK started to ensure // monkey-patching was done properly - const { default: run } = await import('../lib/cli.js') + const { default: cli } = await import('../lib/cli.js') + const { run } = await cli() await run() await sdk.shutdown() })().catch(onError) diff --git a/packages/cli/bin/generate-autocomplete-spec.js b/packages/cli/bin/generate-autocomplete-spec.js new file mode 100644 index 00000000..b71e4d05 --- /dev/null +++ b/packages/cli/bin/generate-autocomplete-spec.js @@ -0,0 +1,8 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { generateCompletionSpec } from '@fig/complete-commander' +import cli from '../lib/cli.js' + +(async () => { + const { program } = await cli() + process.stdout.write(await generateCompletionSpec(program)) +})() diff --git a/packages/cli/lib/cli.js b/packages/cli/lib/cli.js index 531acad6..37a66528 100644 --- a/packages/cli/lib/cli.js +++ b/packages/cli/lib/cli.js @@ -9,6 +9,7 @@ import { parse } from './pipeline.js' import { combine } from './cli/options.js' program + .name('barnard59') .addOption(commonOptions.variable) .addOption(commonOptions.variableAll) .addOption(commonOptions.verbose) @@ -43,21 +44,26 @@ export default async function () { .addOption(commonOptions.verbose) .addOption(commonOptions.quiet) - program.exitOverride() + return { + program, + async run() { + program.exitOverride() - try { - await program.parseAsync(process.argv) - } catch (error) { - const { groups } = /unknown command '(?[^']+)'/.exec(error.message) || {} - if (groups && groups.command) { - /* eslint-disable no-console */ - if (isInstalledGlobally) { - console.error(`Try running 'npm install (-g) barnard59-${groups.command}'`) - } + try { + await program.parseAsync(process.argv) + } catch (error) { + const { groups } = /unknown command '(?[^']+)'/.exec(error.message) || {} + if (groups && groups.command) { + /* eslint-disable no-console */ + if (isInstalledGlobally) { + console.error(`Try running 'npm install (-g) barnard59-${groups.command}'`) + } - console.error(`Try running 'npm install barnard59-${groups.command}'`) - } + console.error(`Try running 'npm install barnard59-${groups.command}'`) + } - process.exit(1) + process.exit(1) + } + }, } } diff --git a/packages/cli/package.json b/packages/cli/package.json index c06cda61..5a6b76fd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -9,7 +9,8 @@ "b59": "bin/barnard59.sh" }, "scripts": { - "test": "mocha" + "test": "mocha", + "generate-autocomplete-spec": "node --loader ts-node/esm --no-warnings ./bin/generate-autocomplete-spec.js > fig-spec.js" }, "repository": { "type": "git", @@ -46,6 +47,7 @@ "readable-stream": "^3.6.0" }, "devDependencies": { + "@fig/complete-commander": "^3.0.0", "approvals": "^6.2.2", "barnard59-base": "^2.1.0", "barnard59-formats": "^2.1.0",