我正在使用OCLIF和TypeScript开发一个CLI工具,我有返回数据库中所有值的命令,在检索之前,一切正常工作,我希望检索的数据像终端中的表一样显示。

是否有任何插件或其他东西可以帮助设计CLI来像这样显示?
发布于 2019-07-01 06:41:43
您看过cli-ux表函数吗?
import {Command} from '@oclif/command'
import {cli} from 'cli-ux'
export default class Users extends Command {
static flags = {
...cli.table.flags()
}
async run() {
const {flags} = this.parse(Users)
/* ... */
cli.table(users, {
name: {
minWidth: 7,
},
company: {
get: row => row.company && row.company.name
}
}, {
printLine: this.log,
...flags, // parsed flags
})
}
}在以下方面的成果:
$ example-cli users
Name Company
Leanne Graham Romaguera-Crona
Ervin Howell Deckow-Crist
Clementine Bauch Romaguera-Jacobson
Patricia Lebsack Robel-Corkery
Chelsey Dietrich Keebler LLC
Mrs. Dennis Schulist Considine-Lockman
Kurtis Weissnat Johns Group
Nicholas Runolfsdottir V Abernathy Group
Glenna Reichert Yost and Sons
Clementina DuBuque Hoeger LLChttps://stackoverflow.com/questions/51305752
复制相似问题