Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Repository files navigation

@oclif/command

This library been replaced by @oclif/core and is no longer maintained

oclif base command

VersionCircleCIAppveyor CIKnown VulnerabilitiesDownloads/weekLicense

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*asfsfrom'fs'import{Command,flags}from'@oclif/command'classLSextendsCommand{staticflags={version: flags.version(),help: flags.help(),// run with --dir= or -d=dir: flags.string({char: 'd',default: process.cwd(),}),}asyncrun(){const{flags}=this.parse(LS)letfiles=fs.readdirSync(flags.dir)for(letfoffiles){this.log(f)}}}LS.run().catch(require('@oclif/errors/handle'))

JavaScript

#!/usr/bin/env node
constfs=require('fs')const{Command, flags}=require('@oclif/command')classLSextendsCommand{asyncrun(){const{flags}=this.parse(LS)letfiles=fs.readdirSync(flags.dir)for(letfoffiles){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 --versionmyscript/0.0.0 darwin-x64 node-v9.5.0
$ ./myscript --helpUSAGE $ @oclif/commandOPTIONS -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.

About

oclif base command

Resources

Stars

136 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages