From d9c56192741a121593217f81781fa2c7ab2f234e Mon Sep 17 00:00:00 2001 From: RasPhilCo Date: Mon, 27 Sep 2021 10:56:14 -0700 Subject: [PATCH] feat: use oclif/core (#416) --- README.md | 2 +- examples/action.ts | 2 +- examples/table.ts | 4 +- package.json | 5 +- src/index.ts | 2 +- src/prompt.ts | 6 +-- src/styled/table.ts | 18 +++---- yarn.lock | 117 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 135 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 4c52be37..891089d5 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ const options: Table.Options = { Example class: ```typescript -import {Command} from '@oclif/command' +import {Command} from '@oclif/core' import {cli} from 'cli-ux' import axios from 'axios' diff --git a/examples/action.ts b/examples/action.ts index b2783cfe..c40d84c6 100644 --- a/examples/action.ts +++ b/examples/action.ts @@ -54,4 +54,4 @@ async function main() { cli.error('oh no') } main() -.catch(error => require('@oclif/errors/handle')(error)) +.catch(error => require('@oclif/core/handle')(error)) diff --git a/examples/table.ts b/examples/table.ts index dee00357..cad8089b 100644 --- a/examples/table.ts +++ b/examples/table.ts @@ -1,4 +1,4 @@ -import {Command} from '@oclif/command' +import {Command} from '@oclif/core' import axios from 'axios' import {cli} from '../src' @@ -9,7 +9,7 @@ export default class Users extends Command { } async run() { - const {flags} = this.parse(Users) + const {flags} = await this.parse(Users) const {data: users} = await axios.get('https://jsonplaceholder.typicode.com/users') cli.table(users, diff --git a/package.json b/package.json index ea6a2c80..e4409406 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "author": "Jeff Dickey @jdxcode", "bugs": "https://github.com/oclif/cli-ux/issues", "dependencies": { - "@oclif/command": "^1.6.0", - "@oclif/errors": "^1.2.1", + "@oclif/core": "^0.5.39", "@oclif/linewrap": "^1.0.0", "@oclif/screen": "^1.0.3", "ansi-escapes": "^4.3.0", @@ -33,8 +32,6 @@ "tslib": "^2.0.0" }, "devDependencies": { - "@oclif/config": "^1.12.9", - "@oclif/parser": "^3.7.0", "@types/ansi-styles": "^3.2.1", "@types/chai": "^4.1.7", "@types/chai-as-promised": "^7.1.0", diff --git a/src/index.ts b/src/index.ts index c1471272..1b122d61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import * as Errors from '@oclif/errors' +import {Errors} from '@oclif/core' import * as util from 'util' import {ActionBase} from './action/base' diff --git a/src/prompt.ts b/src/prompt.ts index e96d581f..ea356c41 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -1,4 +1,4 @@ -import {error} from '@oclif/errors' +import {Errors} from '@oclif/core' import chalk from 'chalk' import config from './config' @@ -151,7 +151,7 @@ export async function anykey(message?: string): Promise { } const char = await prompt(message, {type: 'single', required: false}) if (tty) process.stderr.write('\n') - if (char === 'q') error('quit') - if (char === '\u0003') error('ctrl-c') + if (char === 'q') Errors.error('quit') + if (char === '\u0003') Errors.error('ctrl-c') return char } diff --git a/src/styled/table.ts b/src/styled/table.ts index d39beaeb..97a213f6 100644 --- a/src/styled/table.ts +++ b/src/styled/table.ts @@ -1,4 +1,4 @@ -import {flags as F} from '@oclif/command' +import {Flags as F, Interfaces} from '@oclif/core' import {stdtermwidth} from '@oclif/screen' import chalk from 'chalk' import capitalize from 'lodash/capitalize' @@ -306,14 +306,14 @@ export function table>(data: T[], columns: tab export namespace table { export const Flags: { - columns: F.IOptionFlag; - sort: F.IOptionFlag; - filter: F.IOptionFlag; - csv: F.IFlag; - output: F.IOptionFlag; - extended: F.IFlag; - 'no-truncate': F.IFlag; - 'no-header': F.IFlag; + columns: Interfaces.OptionFlag; + sort: Interfaces.OptionFlag; + filter: Interfaces.OptionFlag; + csv: Interfaces.Flag; + output: Interfaces.OptionFlag; + extended: Interfaces.Flag; + 'no-truncate': Interfaces.Flag; + 'no-header': Interfaces.Flag; } = { columns: F.string({exclusive: ['extended'], description: 'only show provided columns (comma-separated)'}), sort: F.string({description: 'property to sort by (prepend \'-\' for descending)'}), diff --git a/yarn.lock b/yarn.lock index c46e9a6a..81e6c280 100644 --- a/yarn.lock +++ b/yarn.lock @@ -83,6 +83,29 @@ is-wsl "^2.1.1" tslib "^2.0.0" +"@oclif/core@^0.5.39": + version "0.5.39" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-0.5.39.tgz#d00705f31c5e6617145e84bb9dd50156cf3b01c5" + integrity sha512-4XusxLX8PnHDQxtRP25PImlkIj1Mlx6wt0NWb1FxQGvTJOAgXGJZl3YB02ZeXZLYbeKA2A3AqqxFTTKbADnZng== + dependencies: + "@oclif/linewrap" "^1.0.0" + chalk "^4.1.0" + clean-stack "^3.0.0" + cli-ux "^5.1.0" + debug "^4.1.1" + fs-extra "^9.0.1" + get-package-type "^0.1.0" + globby "^11.0.1" + indent-string "^4.0.0" + is-wsl "^2.1.1" + lodash.template "^4.4.0" + semver "^7.3.2" + string-width "^4.2.0" + strip-ansi "^6.0.0" + tslib "^2.0.0" + widest-line "^3.1.0" + wrap-ansi "^7.0.0" + "@oclif/errors@^1.2.1", "@oclif/errors@^1.2.2", "@oclif/errors@^1.3.3": version "1.3.4" resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.3.4.tgz#a96f94536b4e25caa72eff47e8b3ed04f6995f55" @@ -367,6 +390,11 @@ ansi-regex@^5.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + ansi-styles@^3.2.0, ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" @@ -427,6 +455,11 @@ astral-regex@^2.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== +at-least-node@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" + integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== + axios@^0.21.0: version "0.21.1" resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" @@ -565,6 +598,38 @@ cli-progress@^3.4.0: colors "^1.1.2" string-width "^4.2.0" +cli-ux@^5.1.0: + version "5.6.3" + resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-5.6.3.tgz#eecdb2e0261171f2b28f2be6b18c490291c3a287" + integrity sha512-/oDU4v8BiDjX2OKcSunGH0iGDiEtj2rZaGyqNuv9IT4CgcSMyVWAMfn0+rEHaOc4n9ka78B0wo1+N1QX89f7mw== + dependencies: + "@oclif/command" "^1.6.0" + "@oclif/errors" "^1.2.1" + "@oclif/linewrap" "^1.0.0" + "@oclif/screen" "^1.0.3" + ansi-escapes "^4.3.0" + ansi-styles "^4.2.0" + cardinal "^2.1.1" + chalk "^4.1.0" + clean-stack "^3.0.0" + cli-progress "^3.4.0" + extract-stack "^2.0.0" + fs-extra "^8.1" + hyperlinker "^1.0.0" + indent-string "^4.0.0" + is-wsl "^2.2.0" + js-yaml "^3.13.1" + lodash "^4.17.11" + natural-orderby "^2.0.1" + object-treeify "^1.1.4" + password-prompt "^1.1.2" + semver "^7.3.2" + string-width "^4.2.0" + strip-ansi "^6.0.0" + supports-color "^8.1.0" + supports-hyperlinks "^2.1.0" + tslib "^2.0.0" + cliui@^7.0.2: version "7.0.4" resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" @@ -1095,6 +1160,16 @@ fs-extra@^8.1: jsonfile "^4.0.0" universalify "^0.1.0" +fs-extra@^9.0.1: + version "9.1.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d" + integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ== + dependencies: + at-least-node "^1.0.0" + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -1125,6 +1200,11 @@ get-func-name@^2.0.0: resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE= +get-package-type@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/get-package-type/-/get-package-type-0.1.0.tgz#8de2d803cff44df3bc6c456e6668b36c3926e11a" + integrity sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q== + glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0: version "5.1.1" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229" @@ -1375,6 +1455,15 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" +jsonfile@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" + integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== + dependencies: + universalify "^2.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + levn@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade" @@ -1913,6 +2002,15 @@ string-width@^3.0.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" +string-width@^4.0.0: + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + string-width@^4.1.0, string-width@^4.2.0: version "4.2.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5" @@ -1943,6 +2041,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0: dependencies: ansi-regex "^4.1.0" +strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-json-comments@3.1.1, strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" @@ -2067,6 +2172,11 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== +universalify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" + integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== + uri-js@^4.2.2: version "4.2.2" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0" @@ -2107,6 +2217,13 @@ widest-line@^2.0.1: dependencies: string-width "^2.1.1" +widest-line@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-3.1.0.tgz#8292333bbf66cb45ff0de1603b136b7ae1496eca" + integrity sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg== + dependencies: + string-width "^4.0.0" + word-wrap@^1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"