Skip to content

Commit

Permalink
ci: generate autocomplete spec for fig
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Dec 27, 2023
1 parent b86a9ab commit d839ef8
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 39 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/fig.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
*.js.map
.env
*.received.txt
fig-spec.js
78 changes: 54 additions & 24 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion packages/cli/bin/barnard59.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/bin/generate-autocomplete-spec.js
Original file line number Diff line number Diff line change
@@ -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))
})()
32 changes: 19 additions & 13 deletions packages/cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 '(?<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 '(?<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)
}
},
}
}
4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d839ef8

Please sign in to comment.