@oclif/command
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -0,1 +1,10 @@ | ||
<a name="1.3.1"></a> | ||
## [1.3.1](https://github.com/oclif/command/compare/d67287709694b6e16a940e445378e419e0312f66...v1.3.1) (2018-02-17) | ||
### Bug Fixes | ||
* fixed single command help ([efe7409](https://github.com/oclif/command/commit/efe7409)) | ||
* updated help ([48235ab](https://github.com/oclif/command/commit/48235ab)) | ||
<a name="1.3.0"></a> | ||
@@ -2,0 +11,0 @@ # [1.3.0](https://github.com/oclif/command/compare/v1.2.24...v1.3.0) (2018-02-15) |
@@ -17,4 +17,4 @@ import * as Config from '@oclif/config'; | ||
static parse: boolean; | ||
static flags: flags.Input<any>; | ||
static args: Parser.args.IArg[]; | ||
static flags?: flags.Input<any>; | ||
static args?: Parser.args.IArg[]; | ||
static plugin: Config.IPlugin | undefined; | ||
@@ -21,0 +21,0 @@ static examples: string[] | undefined; |
@@ -8,3 +8,2 @@ "use strict"; | ||
const util_1 = require("util"); | ||
const flags = require("./flags"); | ||
class Command { | ||
@@ -90,3 +89,6 @@ constructor(argv, config) { | ||
const help = new HHelp(this.config); | ||
help.showHelp(this.argv); | ||
let title = this.ctor.description && help.render(this.ctor.description).split('\n')[0]; | ||
if (title) | ||
this.log(title + '\n'); | ||
this.log(help.command(Config.Command.toCached(this.ctor))); | ||
this.exit(0); | ||
@@ -114,7 +116,2 @@ } | ||
Command.parse = true; | ||
Command.flags = { | ||
version: flags.version(), | ||
help: flags.help(), | ||
}; | ||
Command.args = []; | ||
Command.parserOptions = {}; | ||
@@ -124,3 +121,5 @@ /** | ||
*/ | ||
Command.run = async function (argv = process.argv.slice(2), opts) { | ||
Command.run = async function (argv, opts) { | ||
if (!argv) | ||
argv = process.argv.slice(2); | ||
const config = await Config.load(opts || module.parent && module.parent.parent && module.parent.parent.filename || __dirname); | ||
@@ -127,0 +126,0 @@ let cmd = new this(argv, config); |
@@ -33,3 +33,4 @@ import * as Config from '@oclif/config'; | ||
protected _helpOverride(): boolean; | ||
protected _help(): void; | ||
} | ||
export declare function run(argv?: string[], options?: Config.LoadOptions): Promise<any>; |
@@ -29,2 +29,8 @@ "use strict"; | ||
} | ||
_help() { | ||
const HHelp = require('@oclif/plugin-help').default; | ||
const help = new HHelp(this.config); | ||
help.showHelp(this.argv); | ||
this.exit(0); | ||
} | ||
} | ||
@@ -31,0 +37,0 @@ Main.flags = { |
{ | ||
"name": "@oclif/command", | ||
"description": "oclif base command", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -18,5 +18,5 @@ "bugs": "https://github.com/oclif/command/issues", | ||
"devDependencies": { | ||
"@oclif/config": "^1.3.52", | ||
"@oclif/config": "^1.3.55", | ||
"@oclif/errors": "^1.0.2", | ||
"@oclif/plugin-help": "^1.0.2", | ||
"@oclif/plugin-help": "^1.0.4", | ||
"@oclif/plugin-plugins": "^1.0.0", | ||
@@ -34,3 +34,3 @@ "@oclif/tslint": "^1.0.2", | ||
"tslint": "^5.9.1", | ||
"typescript": "^2.7.1" | ||
"typescript": "^2.7.2" | ||
}, | ||
@@ -37,0 +37,0 @@ "engines": { |
@@ -7,3 +7,3 @@ @oclif/command | ||
[![Version](https://img.shields.io/npm/v/@oclif/command.svg)](https://npmjs.org/package/@oclif/command) | ||
[![CircleCI](https://circleci.com/gh/oclif/command/tree/master.svg?style=svg)](https://circleci.com/gh/oclif/command/tree/master) | ||
[![CircleCI](https://circleci.com/gh/oclif/command/tree/master.svg?style=shield)](https://circleci.com/gh/oclif/command/tree/master) | ||
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/command?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/command/branch/master) | ||
@@ -15,1 +15,91 @@ [![Codecov](https://codecov.io/gh/oclif/command/branch/master/graph/badge.svg)](https://codecov.io/gh/oclif/command) | ||
[![License](https://img.shields.io/npm/l/@oclif/command.svg)](https://github.com/oclif/command/blob/master/package.json) | ||
This is about half of the main codebase for oclif. The other half lives in [@oclif/config](https://github.com/oclif/config). This can be used directly, but it probably makes more sense to build your CLI with the [generator](https://github.com/oclif/oclif). | ||
Usage | ||
===== | ||
Without the generator, you can create a simple CLI like this: | ||
**TypeScript** | ||
```js | ||
#!/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** | ||
```js | ||
#!/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: | ||
```sh-session | ||
$ ./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](https://github.com/oclif/oclif) for all the options you can pass to the command. |
42289
14
374
104