feat: added --help and --version
MODIFY
package.json
package.json
"bin": "bin/run",
"bugs": "https://github.com/anycli/anycli/issues",
"dependencies": {
- "@anycli/command": "^0.2.24",
- "@anycli/config": "^0.2.8",
- "@anycli/engine": "^0.1.38",
+ "@anycli/command": "^0.3.2",
+ "@anycli/config": "^0.2.10",
+ "@anycli/engine": "^0.1.39",
"@anycli/version": "^0.1.19",
- "cli-ux": "^3.3.11",
+ "cli-ux": "^3.3.12",
"debug": "^3.1.0",
"fixpack": "^2.3.1",
"lodash": "^4.17.4",

MODIFY
src/generators/app.ts
src/generators/app.ts
@@ -244,9 +244,16 @@ class App extends Generator {
break
default:
}
+ if (this.type === 'plugin' && !this.pjson.anycli.devPlugins) {
+ this.pjson.anycli.plugins = [
+ '@anycli/help',
+ ]
+ }
if (this.type === 'multi' && !this.pjson.anycli.plugins) {
this.pjson.anycli.plugins = [
'@anycli/version',
+ '@anycli/help',
+ '@anycli/not-found',
]
}
@@ -319,6 +326,7 @@ class App extends Generator {
dependencies.push(
'@anycli/config',
'@anycli/command',
+ '@anycli/help',
'cli-ux',
)
devDependencies.push(
@@ -333,6 +341,7 @@ class App extends Generator {
devDependencies.push(
'@anycli/engine',
'@anycli/config',
+ '@anycli/help',
)
break
case 'multi':
@@ -443,16 +452,16 @@ class App extends Generator {
if (!this.fromScratch) return
let bin = this.pjson.anycli.bin || this.pjson.anycli.dirname || this.pjson.name
if (bin.includes('/')) bin = bin.split('/').pop()
- const opts = {...this as any, _, bin, cmd: bin}
+ const opts = {...this as any, _, bin, cmd: bin, name: this.pjson.name}
if (this.ts) {
this.fs.copyTpl(this.templatePath('single/bin/run.ts'), this.destinationPath('bin/run'), opts)
} else {
this.fs.copyTpl(this.templatePath('bin/run'), this.destinationPath('bin/run'), opts)
}
this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts)
- this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), {...opts, name: 'hello'})
+ this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), opts)
if (this.mocha) {
- this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/index.test.${this._ext}`), {...opts, name: 'hello'})
+ this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/index.test.${this._ext}`), opts)
}
}

MODIFY
templates/src/command.js.ejs
templates/src/command.js.ejs
@@ -11,6 +11,12 @@ class <%- klass %> extends Command {
}
<%- klass %>.flags = {
+<%_ if (type === 'single') { _%>
+ // add --version flag to show CLI version
+ version: flags.version(),
+ // add --help flag to show CLI version
+ help: flags.help(),
+<%_ } _%>
name: flags.string({char: 'n', description: 'name to print'}),
}

MODIFY
templates/src/command.ts.ejs
templates/src/command.ts.ejs
@@ -31,6 +31,7 @@ hello myname from <%- name %>!
`,
'$ <%- cmd %> file outputs "hello world!" to file',
'$ <%- cmd %> --force',
+ '$ <%- cmd %> --help',
]
<%_ if (type !== 'single') { _%>
@@ -39,6 +40,13 @@ hello myname from <%- name %>!
<%_ } _%>
static flags = {
+<%_ if (type === 'single') { _%>
+ // add --version flag to show CLI version
+ version: flags.version(),
+ // add --help flag to show CLI version
+ help: flags.help(),
+
+<%_ } _%>
// flag with a value (-n, --name=VALUE)
name: flags.string({
char: 'n', // shorter flag version

MODIFY
test/run.js
test/run.js
@@ -49,17 +49,24 @@ module.exports = file => {
case 'plugin':
build(cmd, name)
sh.exec('yarn test')
+ sh.exec('node ./bin/run')
+ sh.exec('node ./bin/run --help')
break
case 'single':
build(cmd, name)
sh.exec('yarn test')
+ sh.exec('node ./bin/run -v')
sh.exec('node ./bin/run')
+ sh.exec('node ./bin/run --help')
break
case 'multi':
build(cmd, name)
sh.exec('yarn test')
+ sh.exec('node ./bin/run -v')
sh.exec('node ./bin/run version')
sh.exec('node ./bin/run hello')
+ sh.exec('node ./bin/run help hello')
+ sh.exec('node ./bin/run hello --help')
break
case 'command':
build('plugin', name)
@@ -67,6 +74,8 @@ module.exports = file => {
sh.exec('yarn test')
sh.exec('node ./bin/run hello')
sh.exec('node ./bin/run foo:bar:baz')
+ sh.exec('node ./bin/run help foo:bar:baz')
+ sh.exec('node ./bin/run foo:bar:baz --help')
break
}
})

MODIFY
yarn.lock
yarn.lock
lodash "^4.17.4"
tslib "^1.9.0"
-"@anycli/command@^0.2.24":
- version "0.2.24"
- resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.2.24.tgz#3347d7d25ecad258bee80297b14acf4ae9cdd523"
+"@anycli/command@^0.3.2":
+ version "0.3.2"
+ resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.3.2.tgz#2dde4dafd3bc1bb2c2cb90a765821dc85053c401"
dependencies:
- "@anycli/parser" "^3.0.3"
- cli-ux "^3.3.10"
+ "@anycli/parser" "^3.0.4"
+ cli-ux "^3.3.12"
debug "^3.1.0"
lodash "^4.17.4"
tslib "^1.9.0"
-"@anycli/config@^0.2.3":
- version "0.2.6"
- resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.6.tgz#d40709a61704907d4d6e7dcab6bbf124ab74e9ad"
+"@anycli/config@^0.2.10":
+ version "0.2.10"
+ resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.10.tgz#17ec0e6f0ffff1f0d49e63dad6d3d09e625fe734"
dependencies:
cli-ux "^3.3.10"
debug "^3.1.0"
lodash "^4.17.4"
read-pkg "^3.0.0"
-"@anycli/config@^0.2.8":
- version "0.2.8"
- resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.8.tgz#db2884692252f2f64afaf1e89cc507c2d35a3226"
+"@anycli/config@^0.2.3":
+ version "0.2.6"
+ resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.6.tgz#d40709a61704907d4d6e7dcab6bbf124ab74e9ad"
dependencies:
cli-ux "^3.3.10"
debug "^3.1.0"
lodash "^4.17.4"
read-pkg "^3.0.0"
-"@anycli/engine@^0.1.38":
- version "0.1.38"
- resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.1.38.tgz#47b74330709eeadb95798f047c22436f0613cbab"
+"@anycli/engine@^0.1.39":
+ version "0.1.39"
+ resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.1.39.tgz#0d2bc14de3f339b3cc5c6f042ca09ee2f0e4f253"
dependencies:
- "@anycli/manifest-file" "^0.2.0"
- cli-ux "^3.3.10"
+ "@anycli/manifest-file" "^0.3.0"
+ cli-ux "^3.3.12"
debug "^3.1.0"
fs-extra "^5.0.0"
globby "^7.1.1"
lodash "^4.17.4"
-"@anycli/manifest-file@^0.2.0":
- version "0.2.0"
- resolved "https://registry.yarnpkg.com/@anycli/manifest-file/-/manifest-file-0.2.0.tgz#f9f70fd2afb44178fe907f2a35ad8746eeb1ee97"
+"@anycli/manifest-file@^0.3.0":
+ version "0.3.0"
+ resolved "https://registry.yarnpkg.com/@anycli/manifest-file/-/manifest-file-0.3.0.tgz#544fa71b797106e1471c290fc6a6c99d25254a40"
dependencies:
debug "^3.1.0"
fs-extra "^5.0.0"
chalk "^2.3.0"
lodash "^4.17.4"
-"@anycli/parser@^3.0.3":
- version "3.0.3"
- resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-3.0.3.tgz#abc33c9098485d0ae2705eab859ff305aec6006f"
+"@anycli/parser@^3.0.4":
+ version "3.0.4"
+ resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-3.0.4.tgz#8714c4f73134625fe3781b9e2b5aa0ebb5685a82"
dependencies:
"@anycli/screen" "^0.0.3"
chalk "^2.3.0"
@@ -677,9 +677,9 @@ cli-ux@^3.3.10:
strip-ansi "^4.0.0"
supports-color "^5.1.0"
-cli-ux@^3.3.11:
- version "3.3.11"
- resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.11.tgz#64014c575bf8a4b228976c183e201ac3f18db967"
+cli-ux@^3.3.12:
+ version "3.3.12"
+ resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.12.tgz#9bd5a2ed5c682fc22027bd32c5eb20bbe6aa2571"
dependencies:
"@anycli/screen" "^0.0.3"
"@heroku/linewrap" "^1.0.0"

feat: added --help and --version