-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
671 additions
and
2,497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
.circleci/setup_git | ||
|
||
PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH | ||
|
||
yarn global add @dxcli/semantic-release@1 semantic-release@12 | ||
yarn install --frozen-lockfile | ||
semantic-release -e @dxcli/semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ install: | |
- git submodule update --init --recursive | ||
- git config --global user.email "[email protected]" | ||
- git config --global user.name "dxcli" | ||
- yarn | ||
- yarn add -D nyc @dxcli/nyc-config | ||
test_script: | ||
- yarn test | ||
after_test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import {ICachedArg, ICachedCommand, ICachedFlag, IConfig} from '@dxcli/config' | ||
import chalk from 'chalk' | ||
import * as _ from 'lodash' | ||
|
||
import {Article, Section} from '.' | ||
|
||
const { | ||
underline, | ||
dim, | ||
} = chalk | ||
|
||
export default class CommandHelp { | ||
constructor(public config: IConfig) {} | ||
|
||
command(cmd: ICachedCommand): Article { | ||
const flagDefs = cmd.flags || {} | ||
const flags = Object.keys(flagDefs) | ||
.filter(k => !flagDefs[k].hidden) | ||
.map(k => { | ||
flagDefs[k].name = k | ||
return flagDefs[k] | ||
}) | ||
const args = (cmd.args || []).filter(a => !a.hidden) | ||
return { | ||
title: cmd.title, | ||
sections: _([ | ||
this.usage(cmd, flags), | ||
this.args(args), | ||
this.flags(flags), | ||
this.aliases(cmd.aliases), | ||
]).compact().value(), | ||
} | ||
} | ||
|
||
// commandLine(cmd: ICachedCommand): [string, string | undefined] { | ||
// return [buildUsage(cmd), cmd.description ? dim(cmd.description) : undefined] as [string, string | undefined] | ||
// } | ||
|
||
protected usage(cmd: ICachedCommand, flags: ICachedFlag[]): Section { | ||
return { | ||
heading: 'usage', | ||
body: cmd.usage ? _.castArray(cmd.usage) : this.defaultUsage(cmd, flags) | ||
} | ||
} | ||
protected defaultUsage(command: ICachedCommand, flags: ICachedFlag[]): string { | ||
return _([ | ||
'$', | ||
this.config.bin, | ||
command.id, | ||
command.args.map(a => this.arg(a)).join(' '), | ||
flags.length && dim('[OPTIONS]'), | ||
]) | ||
.compact() | ||
.join(' ') | ||
} | ||
|
||
protected description(cmd: ICachedCommand): Section | undefined { | ||
if (!cmd.description) return | ||
return { | ||
heading: 'description', | ||
body: cmd.description.trim(), | ||
} | ||
} | ||
|
||
protected aliases(aliases: string[] | undefined): Section | undefined { | ||
if (!aliases || !aliases.length) return | ||
return { | ||
heading: 'aliases', | ||
body: aliases.map(a => ['$', this.config.bin, a].join(' ')), | ||
} | ||
} | ||
|
||
protected args(args: ICachedCommand['args']): Section | undefined { | ||
if (!args.find(f => !!f.description)) return | ||
return { | ||
heading: 'arguments', | ||
body: args.map(a => { | ||
return [a.name!.toUpperCase(), a.description ? dim(a.description) : undefined] | ||
}) | ||
} | ||
} | ||
protected arg(arg: ICachedArg): string { | ||
let name = arg.name.toUpperCase() | ||
if (arg.required) return `${name}` | ||
return `[${name}]` | ||
} | ||
|
||
protected flags(flags: ICachedFlag[]): Section | undefined { | ||
if (!flags.length) return | ||
return { | ||
heading: 'options', | ||
body: _(flags) | ||
.sortBy(f => [!f.char, f.char, f.name]) | ||
.map(f => this.flag(f)) | ||
.value(), | ||
} | ||
} | ||
|
||
protected flag(flag: ICachedFlag): [string, string | undefined] { | ||
const label = [] | ||
if (flag.char) label.push(`-${flag.char}`) | ||
if (flag.name) label.push(` --${flag.name}`) | ||
let left = label.join(',').trim() | ||
if (flag.type === 'option') left += `=${underline(flag.name)}` | ||
|
||
let right = flag.description || '' | ||
if (flag.required) right = `(required) ${right}` | ||
|
||
return [left, dim(right.trim())] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Command from '@dxcli/command' | ||
import cli from 'cli-ux' | ||
|
||
export default class HelpCommand extends Command { | ||
async run() { | ||
const name = this.flags.name || 'world' | ||
cli.log(`hello ${name}!`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// tslint:disable | ||
|
||
declare namespace NodeJS { | ||
interface Global { | ||
'columns': number | ||
} | ||
} |
Oops, something went wrong.