gingermusketeer / core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@oclif/core

base library for oclif CLIs

Version CircleCI Downloads/week License

Migrating

If you're migrating from the old oclif libraries (@oclif/config, @oclif/command, @oclif/error, @oclif/parser), see the migration guide.

Usage

Without the generator, you can create a simple CLI like this:

TypeScript

#!/usr/bin/env ts-node

import * as fs from 'fs'
import {Command, flags} from '@oclif/core'

class LS extends Command {
  static flags = {
    version: flags.version(),
    help: flags.help(),
    // run with --dir= or -d=
    dir: flags.string({
      char: 'd',
      default: process.cwd(),
    }),
  }

  async run() {
    const {flags} = this.parse(LS)
    let files = fs.readdirSync(flags.dir)
    for (let f of files) {
      this.log(f)
    }
  }
}

LS.run()
.catch(require('@oclif/core/handle'))

Then run either of these with:

$ ./myscript
...files in current dir...
$ ./myscript --dir foobar
...files in ./foobar...
$ ./myscript --version
myscript/0.0.0 darwin-x64 node-v9.5.0
$ ./myscript --help
USAGE
  $ @oclif/core

OPTIONS
  -d, --dir=dir  [default: /Users/jdickey/src/github.com/oclif/core]
  --help         show CLI help
  --version      show CLI version

See the generator for all the options you can pass to the command.

About

License:MIT License


Languages

Language:TypeScript 98.7%Language:JavaScript 1.3%Language:Shell 0.0%