Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smart-pugs-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/cli": minor
---

Updated CLI to use Incur.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"dependencies": {
"abitype": "^1.1.1",
"bundle-require": "^5.1.0",
"cac": "^6.7.14",
"change-case": "^5.4.4",
"chokidar": "4.0.1",
"dedent": "^0.7.0",
Expand All @@ -78,6 +77,7 @@
"esbuild": "~0.28.1",
"escalade": "3.2.0",
"fdir": "^6.1.1",
"incur": "^0.5.1",
"nanospinner": "1.2.2",
"pathe": "^1.1.2",
"picocolors": "^1.0.0",
Expand Down
78 changes: 33 additions & 45 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
#!/usr/bin/env node
import { cac } from 'cac'
import { Cli, z } from 'incur'

import { type Generate, generate } from './commands/generate.js'
import { type Init, init } from './commands/init.js'
import * as logger from './logger.js'
import { generate } from './commands/generate.js'
import { init } from './commands/init.js'
import { version } from './version.js'

const cli = cac('wagmi')
try {
process.title = 'node (wagmi)'
} catch {}

cli
.command('generate', 'generate code based on configuration')
.option('-c, --config <path>', '[string] path to config file')
.option('-r, --root <path>', '[string] root path to resolve config from')
.option('-w, --watch', '[boolean] watch for changes')
.example((name) => `${name} generate`)
.action(async (options: Generate) => {
await generate(options)
if (!options.watch) process.exit(0)
})
const commonOptions = {
config: z.string().optional().describe('Path to config file'),
root: z.string().optional().describe('Root path to resolve config from'),
}

cli
.command('init', 'create configuration file')
.option('-c, --config <path>', '[string] path to config file')
.option('-r, --root <path>', '[string] root path to resolve config from')
.example((name) => `${name} init`)
.action(async (options: Init) => {
await init(options)
process.exit(0)
const cli = Cli.create('wagmi', {
description: 'Manage and generate code from Ethereum ABIs',
version,
})
.command('generate', {
alias: { config: 'c', root: 'r', watch: 'w' },
description: 'Generate code based on configuration',
options: z.object({
...commonOptions,
watch: z.boolean().optional().describe('Watch for changes'),
}),
async run({ options }) {
await generate(options)
},
})
.command('init', {
alias: { config: 'c', root: 'r' },
description: 'Create configuration file',
options: z.object(commonOptions),
async run({ options }) {
await init(options)
},
})

cli.help()
cli.version(version)

void (async () => {
try {
process.title = 'node (wagmi)'
} catch {}

try {
// Parse CLI args without running command
cli.parse(process.argv, { run: false })
if (!cli.matchedCommand) {
if (cli.args.length === 0) {
if (!cli.options.help && !cli.options.version) cli.outputHelp()
} else throw new Error(`Unknown command: ${cli.args.join(' ')}`)
}
await cli.runMatchedCommand()
} catch (error) {
logger.error(`\n${(error as Error).message}`)
process.exit(1)
}
})()
await cli.serve()
35 changes: 32 additions & 3 deletions pnpm-lock.yaml

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

Loading