base library for oclif CLIs
If you're migrating from the old oclif libraries (@oclif/config
, @oclif/command
, @oclif/error
, @oclif/parser
), see the migration guide.
The @oclif/core
module now also includes the cli-ux
module. Merging cli-ux
into @oclif/core
resolves a circular dependency between the two modules.
See the cli-ux README for instructions on how to replace the cli-ux
module with @oclif/core
.
The cli-ux README also contains detailed usage examples.
We strongly encourage you generate an oclif CLI using the oclif cli. The generator will generate an npm package with @oclif/core
as a dependency.
You can, however, use @oclif/core
in a standalone script like this:
#!/usr/bin/env ts-node
import * as fs from 'fs'
import {Command, Flags} from '@oclif/core'
class LS extends Command {
static description = 'List the files in a directory.'
static flags = {
version: Flags.version(),
help: Flags.help(),
dir: Flags.string({
char: 'd',
default: process.cwd(),
}),
}
async run() {
const {flags} = await this.parse(LS)
const files = fs.readdirSync(flags.dir)
for (const f of files) {
this.log(f)
}
}
}
LS.run().then(() => {
require('@oclif/core/flush')
}, () => {
require('@oclif/core/handle')
})
Then run it like this:
$ ts-node myscript.ts
...files in current dir...