Skip to content

Commit

Permalink
fix: updated config
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 3, 2018
1 parent bef7920 commit 4f48c42
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .circleci/greenkeeper
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH

if [[ "$CIRCLE_BRANCH" != greenkeeper/* ]]; then
yarn
yarn check
# yarn check
exit 0
fi

Expand Down
2 changes: 1 addition & 1 deletion 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()
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"bugs": "https://github.com/anycli/plugin-help/issues",
"dependencies": {
"@anycli/command": "^0.3.8",
"@anycli/command": "^1.2.3",
"@anycli/screen": "^0.0.3",
"chalk": "^2.3.0",
"cli-ux": "^3.3.13",
Expand All @@ -24,14 +24,12 @@
"wrap-ansi": "^3.0.1"
},
"devDependencies": {
"@anycli/config": "^0.3.1",
"@anycli/dev-cli": "^0.1.3",
"@anycli/engine": "^0.3.2",
"@anycli/plugin-help": "^0.4.6",
"@anycli/plugin-plugins": "^0.2.8",
"@anycli/plugin-version": "^0.1.30",
"@anycli/test": "^0.10.4",
"@anycli/tslint": "^0.2.2",
"@anycli/config": "^1.0.19",
"@anycli/dev-cli": "^0.1.4",
"@anycli/plugin-plugins": "^0.2.10",
"@anycli/plugin-version": "^0.1.34",
"@anycli/test": "^0.10.9",
"@anycli/tslint": "^0.2.5",
"@types/chai": "^4.1.2",
"@types/indent-string": "^3.0.0",
"@types/lodash": "^4.14.100",
Expand All @@ -44,8 +42,8 @@
"@types/wrap-ansi": "^2.0.14",
"chai": "^4.1.2",
"concurrently": "^3.5.1",
"eslint": "^4.16.0",
"eslint-config-anycli": "^1.3.1",
"eslint": "^4.17.0",
"eslint-config-anycli": "^1.3.2",
"mocha": "^5.0.0",
"strip-ansi": "^4.0.0",
"ts-node": "^4.1.0",
Expand All @@ -70,7 +68,7 @@
"lint": "concurrently -p command \"eslint .\" \"tsc -p test --noEmit\" \"tslint -p test\"",
"postpublish": "rm .anycli.manifest.json",
"posttest": "yarn run lint",
"prepublishOnly": "yarn run build && anycli-dev manifest -o .anycli.manifest.json",
"prepublishOnly": "yarn run build && anycli-dev manifest",
"test": "mocha --forbid-only \"test/**/*.test.ts\""
},
"types": "./lib/index.d.ts"
Expand Down
20 changes: 10 additions & 10 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ICachedArg, ICachedCommand, ICachedFlag, IConfig} from '@anycli/config'
import * as Config from '@anycli/config'
import chalk from 'chalk'
import * as _ from 'lodash'

Expand All @@ -11,9 +11,9 @@ const {
} = chalk

export default class CommandHelp {
constructor(public config: IConfig, public opts: HelpOptions) {}
constructor(public config: Config.IConfig, public opts: HelpOptions) {}

command(cmd: ICachedCommand): Article {
command(cmd: Config.Command): Article {
const flagDefs = cmd.flags || {}
const flags = Object.keys(flagDefs)
.filter(k => !flagDefs[k].hidden)
Expand All @@ -38,14 +38,14 @@ export default class CommandHelp {
// return [buildUsage(cmd), cmd.description ? dim(cmd.description) : undefined] as [string, string | undefined]
// }

protected usage(cmd: ICachedCommand, flags: ICachedFlag[]): Section {
protected usage(cmd: Config.Command, flags: Config.Command.Flag[]): Section {
return {
heading: 'usage',
type: 'code',
body: cmd.usage ? _.castArray(cmd.usage) : this.defaultUsage(cmd, flags)
}
}
protected defaultUsage(command: ICachedCommand, flags: ICachedFlag[]): string {
protected defaultUsage(command: Config.Command, flags: Config.Command.Flag[]): string {
return _([
'$',
this.config.bin,
Expand All @@ -57,7 +57,7 @@ export default class CommandHelp {
.join(' ')
}

protected description(cmd: ICachedCommand): Section | undefined {
protected description(cmd: Config.Command): Section | undefined {
if (!cmd.description) return
return {
heading: 'description',
Expand All @@ -74,7 +74,7 @@ export default class CommandHelp {
}
}

protected args(args: ICachedCommand['args']): Section | undefined {
protected args(args: Config.Command['args']): Section | undefined {
if (!args.length) return
return {
heading: 'arguments',
Expand All @@ -86,13 +86,13 @@ export default class CommandHelp {
})
}
}
protected arg(arg: ICachedArg): string {
protected arg(arg: Config.Command['args'][0]): string {
let name = arg.name.toUpperCase()
if (arg.required) return `${name}`
return `[${name}]`
}

protected flags(flags: ICachedFlag[]): Section | undefined {
protected flags(flags: Config.Command.Flag[]): Section | undefined {
if (!flags.length) return
return {
heading: 'options',
Expand All @@ -103,7 +103,7 @@ export default class CommandHelp {
}
}

protected flag(flag: ICachedFlag): [string, string | undefined] {
protected flag(flag: Config.Command.Flag): [string, string | undefined] {
const label = []
if (flag.char) label.push(`-${flag.char[0]}`)
if (flag.name) label.push(`--${flag.name.trim()}`)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Commands extends Command {
// }

async run() {
const commands = this.config.engine!.commandIDs.slice(0)
const commands = this.config.commandIDs.slice(0)
commands.sort()
for (let id of commands) {
cli.info(id)
Expand Down
11 changes: 5 additions & 6 deletions src/commands/help.ts
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'

import Help from '..'
Expand All @@ -13,17 +13,16 @@ export default class HelpCommand extends Command {
{name: 'command', required: false, description: 'command to show help for'}
]

options = parse(this.argv, HelpCommand)

async run() {
const format = this.options.flags.format as any || 'screen'
let id = this.options.args.command
const {flags, args} = this.parse(HelpCommand)
const format = flags.format as any || 'screen'
let id = args.command
let help = new Help(this.config, {format})
if (!id) {
let rootHelp = help.root()
cli.info(rootHelp)
} else {
let command = this.config.engine!.findCommand(id, true)
let command = this.config.findCommand(id, {must: true})
let commandHelp = help.command(command)
cli.info(commandHelp)
}
Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ICachedCommand, ICommand, IConfig} from '@anycli/config'
import * as Config from '@anycli/config'
import * as screen from '@anycli/screen'
import chalk from 'chalk'
import cli from 'cli-ux'
Expand Down Expand Up @@ -45,14 +45,14 @@ export interface HelpOptions {
}

export default class Help {
constructor(public config: IConfig, public opts: HelpOptions = {}) {}

showHelp(command: ICommand, _: string[]) {
if (command.type === 'engine') {
cli.info(this.root())
} else {
cli.info(this.command(command.convertToCached()))
}
constructor(public config: Config.IConfig, public opts: HelpOptions = {}) {}

showHelp(command: Config.Command.Class, _: string[]) {
// if (command.type === 'engine') {
// cli.info(this.root())
// } else {
cli.info(this.command(Config.Command.toCached(command)))
// }
}

root(): string {
Expand All @@ -61,7 +61,7 @@ export default class Help {
return this.render(article)
}

command(command: ICachedCommand): string {
command(command: Config.Command): string {
const help = new CommandHelp(this.config, this.opts)
const article = help.command(command)
return this.render(article)
Expand Down
2 changes: 1 addition & 1 deletion src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class RootHelp {
}

protected commands(): Section | undefined {
const commands = _(this.config.engine.commands)
const commands = _(this.config.commands)
.filter(c => this.opts.all || !c.hidden)
.sortBy(c => c.id)
.sortedUniqBy(c => c.id)
Expand Down
8 changes: 3 additions & 5 deletions test/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {Command as Base, flags} from '@anycli/command'
import {ICommand} from '@anycli/config'
import * as Config from '@anycli/config'
import {expect, test as base} from '@anycli/test'
import stripAnsi = require('strip-ansi')

// const chalk = require('chalk')

global.columns = 80
import Help from '../src'

Expand All @@ -15,9 +13,9 @@ class Command extends Base {
const test = base
.loadConfig()
.add('help', ctx => new Help(ctx.config))
.register('commandHelp', (command?: ICommand) => ({
.register('commandHelp', (command?: Config.Command.Class) => ({
run(ctx: {help: Help, commandHelp: string, expectation: string}) {
const cached = command!.convertToCached()
const cached = Config.Command.toCached(command!)
let help = ctx.help.command(cached)
if (process.env.TEST_OUTPUT === '1') {
// tslint:disable-next-line
Expand Down
1 change: 1 addition & 0 deletions test/commands/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ help
plugins
plugins:install
plugins:uninstall
plugins:update
version
`)
})
Expand Down
1 change: 1 addition & 0 deletions test/commands/help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ COMMANDS
plugins
plugins:install
plugins:uninstall
plugins:update
version
`)
Expand Down
7 changes: 3 additions & 4 deletions test/markdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Command as Base, flags} from '@anycli/command'
import {ICommand} from '@anycli/config'
import {Command as Base, Config, flags} from '@anycli/command'
import {expect, test as base} from '@anycli/test'
import stripAnsi = require('strip-ansi')

Expand All @@ -13,9 +12,9 @@ class Command extends Base {
const test = base
.loadConfig()
.add('help', ctx => new Help(ctx.config, {format: 'markdown'}))
.register('commandHelp', (command?: ICommand) => ({
.register('commandHelp', (command?: Config.Command.Class) => ({
run(ctx: {help: Help, commandHelp: string, expectation: string}) {
const cached = command!.convertToCached()
const cached = Config.Command.toCached(command!)
let help = ctx.help.command(cached)
if (process.env.TEST_OUTPUT === '1') {
// tslint:disable-next-line
Expand Down
5 changes: 3 additions & 2 deletions test/root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ global.columns = 80
import Help from '../src'

const test = base
.loadEngine()
.add('help', ctx => new Help(ctx.engine.config))
.loadConfig()
.add('help', ctx => new Help(ctx.config))
.register('rootHelp', () => ({
run(ctx: {help: Help, commandHelp: string, expectation: string}) {
let help = ctx.help.root()
Expand Down Expand Up @@ -34,5 +34,6 @@ COMMANDS
plugins
plugins:install
plugins:uninstall
plugins:update
version`))
})
Loading

0 comments on commit 4f48c42

Please sign in to comment.