@rizzlesauce/oclif-command
oclif base command
Last updated 2 months ago by rizzlesauce .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rizzlesauce/oclif-command 
SYNC missed versions from official npm registry.

@oclif/command

oclif base command

Version CircleCI Appveyor CI Codecov Known Vulnerabilities Downloads/week License

This is about half of the main codebase for oclif. The other half lives in @oclif/config. This can be used directly, but it probably makes more sense to build your CLI with the generator.

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/command'

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/errors/handle'))

JavaScript

#!/usr/bin/env node

const fs = require('fs')
const {Command, flags} = require('@oclif/command')

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

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

LS.run()
.catch(require('@oclif/errors/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/command

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

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

Current Tags

  • 1.5.20-rossa.8                                ...           latest (2 months ago)

8 Versions

  • 1.5.20-rossa.8                                ...           2 months ago
  • 1.5.20-rossa.7                                ...           2 months ago
  • 1.5.20-rossa.6                                ...           2 months ago
  • 1.5.20-rossa.5                                ...           3 months ago
  • 1.5.20-rossa.4                                ...           8 months ago
  • 1.5.20-rossa.3                                ...           8 months ago
  • 1.5.20-beta.2                                ...           8 months ago
  • 1.5.20-beta.1                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (15)

Copyright 2014 - 2016 © taobao.org |