Skip to content

livecycle/oclif-core-command-not-found-on-empty-arg

 
 

Repository files navigation

@oclif/core

base library for oclif CLIs

Version Downloads/week License

Migrating

See the v3 migration guide for an overview of breaking changes that occurred between v2 and v3.

See the v2 migration guide for an overview of breaking changes that occurred between v1 and v2.

Migrating from @oclif/config and @oclif/command? See the v1 migration guide.

CLI UX

The ux README contains detailed usage examples of using the ux export.

Usage

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 -S node --loader ts-node/esm --no-warnings=ExperimentalWarning

import * as fs from 'fs'
import {Command, Flags, flush, handle} 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(
  async () => {
    await flush()
  },
  async (err) => {
    await handle(err)
  },
)

Then run it like this:

$ ts-node myscript.ts
...files in current dir...

About

Node.js Open CLI Framework. Built by Salesforce.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.4%
  • Other 0.6%