Skip to content

Commit

Permalink
fix: use simpler command/config setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 3, 2018
1 parent 3cc40e3 commit b5b7377
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 134 deletions.
23 changes: 10 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"commands": "./lib/commands",
"plugins": [
"@anycli/plugin-help",
"@anycli/plugin-not-found",
"@anycli/plugin-version"
"@anycli/plugin-not-found"
],
"bin": "anycli"
},
Expand All @@ -17,13 +16,11 @@
},
"bugs": "https://github.com/anycli/cli/issues",
"dependencies": {
"@anycli/command": "^0.3.7",
"@anycli/config": "^0.3.0",
"@anycli/dev-cli": "^0.1.3",
"@anycli/engine": "^0.3.2",
"@anycli/plugin-help": "^0.4.6",
"@anycli/plugin-not-found": "^0.1.14",
"@anycli/plugin-version": "^0.1.30",
"@anycli/command": "^1.2.4",
"@anycli/config": "^1.1.2",
"@anycli/dev-cli": "^0.1.5",
"@anycli/plugin-help": "^0.6.0",
"@anycli/plugin-not-found": "^0.1.15",
"cli-ux": "^3.3.13",
"debug": "^3.1.0",
"fixpack": "^2.3.1",
Expand All @@ -34,17 +31,17 @@
"yosay": "^2.0.1"
},
"devDependencies": {
"@anycli/tslint": "^0.2.1",
"@anycli/tslint": "^0.2.5",
"@types/lodash": "^4.14.100",
"@types/read-pkg": "^3.0.0",
"@types/shelljs": "^0.7.8",
"@types/yeoman-generator": "^2.0.1",
"@types/yosay": "^0.0.29",
"chai": "^4.1.2",
"eslint": "^4.16.0",
"eslint-config-anycli": "^1.3.1",
"eslint": "^4.17.0",
"eslint-config-anycli": "^1.3.2",
"execa": "^0.9.0",
"fancy-test": "^0.6.6",
"fancy-test": "^0.6.10",
"fs-extra": "^5.0.0",
"mocha": "^5.0.0",
"npm-run-path": "^2.0.2",
Expand Down
12 changes: 6 additions & 6 deletions src/app_command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {flags, parse} from '@anycli/command'
import {flags} from '@anycli/command'

import Base from './command_base'

Expand All @@ -12,18 +12,18 @@ export default abstract class AppCommand extends Base {
{name: 'path', required: false}
]

options = parse(this.argv, AppCommand)
abstract type: string

async run() {
const options = this.options.flags.options ? this.options.flags.options.split(',') : []
const {flags, args} = this.parse(AppCommand)
const options = flags.options ? flags.options.split(',') : []

await super.generate('app', {
type: this.type,
path: this.options.args.path,
path: args.path,
options,
defaults: this.options.flags.defaults,
force: this.options.flags.force
defaults: flags.defaults,
force: flags.force
})
}
}
2 changes: 1 addition & 1 deletion src/generators/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class App extends Generator {
this.pjson.scripts.prepublishOnly = 'yarn run build'
}
if (['plugin', 'multi'].includes(this.type)) {
this.pjson.scripts.prepublishOnly = nps.series(this.pjson.scripts.prepublishOnly, 'anycli-dev manifest -o .anycli.manifest.json')
this.pjson.scripts.prepublishOnly = nps.series(this.pjson.scripts.prepublishOnly, 'anycli-dev manifest')
this.pjson.scripts.postpublish = 'rm .anycli.manifest.json'
this.pjson.files.push('.anycli.manifest.json')
}
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import run from '@anycli/engine'
export {run}
export default run
export {run} from '@anycli/command'
2 changes: 1 addition & 1 deletion templates/bin/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('@anycli/engine').run()
require('@anycli/command').run()
2 changes: 1 addition & 1 deletion templates/plugin/bin/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('@anycli/engine').run()
require('@anycli/command').run()
6 changes: 3 additions & 3 deletions templates/src/command.js.ejs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const {Command, flags, parse} = require('@anycli/command')
const {Command, flags} = require('@anycli/command')
const {cli} = require('cli-ux')
<%_ const klass = _.upperFirst(_.camelCase(name.split(':').slice(-1).join(':') + ':command')) _%>

class <%- klass %> extends Command {
async run() {
const options = parse(this.argv, <%- klass %>)
const name = options.flags.name || 'world'
const {flags} = this.parse(<%- klass %>)
const name = flags.name || 'world'
cli.log(`hello ${name} from <%- name %>!`)
}
}
Expand Down
24 changes: 7 additions & 17 deletions templates/src/command.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, flags, parse} from '@anycli/command'
import {Command, flags} from '@anycli/command'
import cli from 'cli-ux'
<%_ const klass = _.upperFirst(_.camelCase(name)) _%>

Expand Down Expand Up @@ -90,25 +90,15 @@ hello myname from <%- name %>!
// set it to off if you need to accept variable arguments
// static strict = false
// runs the parser and stores the results in this.options
// you should run this even if you have no flags/args so it properly errors out
// (see strict above for variable argument commands)
//
// stores the parsed flags in options.flags[name]
//
// stores the parsed args in options.args[name] as an object
// but also in options.argv as an array
// you can get the raw args passed to the command with this.argv
// or from this.options.argv which will remove any args that were actually flags
options = parse(this.argv, <%- klass %>)
// entry point of command
async run() {
const name = this.options.flags.name || 'world'
cli.log(`hello ${name} from <%- name %>!`)
const {args, flags} = this.parse(<%- klass %>)
// this.options.flags.force is a boolean
// this.options.args.file and this.options.argv[0] is a string or undefined
const name = flags.name || 'world'
cli.log(`hello ${name} from <%- name %>!`)
if (args.file && flags.force) {
cli.log(`you input ${args.file}`)
}
}
}
<%_ if (type === 'single') { _%>
Expand Down

0 comments on commit b5b7377

Please sign in to comment.