fix: readme for single command cli
MODIFY
package.json
package.json
},
"bugs": "https://github.com/oclif/oclif/issues",
"dependencies": {
- "@oclif/core": "^1.6.4",
+ "@oclif/core": "^1.9.9",
"@oclif/plugin-help": "^5.1.12",
"@oclif/plugin-not-found": "^2.3.1",
"@oclif/plugin-warn-if-update-available": "^2.0.4",

MODIFY
src/commands/readme.ts
src/commands/readme.ts
// tslint:disable no-implicit-dependencies
-import {Command, Config, Flags, HelpBase, Interfaces, loadHelpClass, Plugin} from '@oclif/core'
+import {Command, Config, Flags, HelpBase, Interfaces, loadHelpClass, Plugin, toConfiguredId} from '@oclif/core'
import * as fs from 'fs-extra'
import * as _ from 'lodash'
import * as path from 'path'
@@ -54,8 +54,9 @@ Customize the code URL prefix by setting oclif.repositoryPrefix in package.json.
let readme = await fs.readFile(readmePath, 'utf8')
let commands = config.commands
- commands = commands.filter(c => !c.hidden)
- commands = commands.filter(c => c.pluginType === 'core')
+ .filter(c => !c.hidden && c.pluginType === 'core')
+ .map(c => c.id === '.' ? {...c, id: ''} : c)
+
this.debug('commands:', commands.map(c => c.id).length)
commands = uniqBy(commands, c => c.id)
commands = sortBy(commands, c => c.id)
@@ -149,7 +150,7 @@ USAGE
return [
...commands.map(c => {
const usage = this.commandUsage(config, c)
- return `* [\`${config.bin} ${usage}\`](#${slugify.slug(`${config.bin}-${usage}`)})`
+ return usage ? `* [\`${config.bin} ${usage}\`](#${slugify.slug(`${config.bin}-${usage}`)})` : `* [\`${config.bin}\`](#${slugify.slug(`${config.bin}`)})`
}),
'',
...commands.map(c => this.renderCommand(config, c)).map(s => s.trim() + '\n'),
@@ -162,7 +163,10 @@ USAGE
const help = new this.HelpClass(config, {stripAnsi: true, maxWidth: columns})
const wrapper = new HelpCompatibilityWrapper(help)
- const header = () => `## \`${config.bin} ${this.commandUsage(config, c)}\``
+ const header = () => {
+ const usage = this.commandUsage(config, c)
+ return usage ? `## \`${config.bin} ${usage}\`` : `## \`${config.bin}\``
+ }
try {
return compact([
@@ -246,7 +250,7 @@ USAGE
return `[${name}]`
}
- const id = config.topicSeparator ? command.id.replace(/:/g, config.topicSeparator) : command.id
+ const id = toConfiguredId(command.id, config)
const defaultUsage = () => {
return compact([
id,

MODIFY
yarn.lock
yarn.lock
widest-line "^3.1.0"
wrap-ansi "^7.0.0"
+"@oclif/core@^1.9.9":
+ version "1.9.9"
+ resolved "https://registry.npmjs.org/@oclif/core/-/core-1.9.9.tgz#eab17e3f7cfccedce561158c834bb057168b45e2"
+ integrity sha512-B+4Utq7WQEjYQt89soEJ80eWqDGgRXL5f04sD+2MSyR0Gm+JQVM9AE0SWn4TTbHCNkkzp/yDLJ5l/W64D9QYbg==
+ dependencies:
+ "@oclif/linewrap" "^1.0.0"
+ "@oclif/screen" "^3.0.2"
+ ansi-escapes "^4.3.2"
+ ansi-styles "^4.3.0"
+ cardinal "^2.1.1"
+ chalk "^4.1.2"
+ clean-stack "^3.0.1"
+ cli-progress "^3.10.0"
+ debug "^4.3.4"
+ ejs "^3.1.6"
+ fs-extra "^9.1.0"
+ get-package-type "^0.1.0"
+ globby "^11.1.0"
+ hyperlinker "^1.0.0"
+ indent-string "^4.0.0"
+ is-wsl "^2.2.0"
+ js-yaml "^3.14.1"
+ natural-orderby "^2.0.3"
+ object-treeify "^1.1.33"
+ password-prompt "^1.1.2"
+ semver "^7.3.7"
+ string-width "^4.2.3"
+ strip-ansi "^6.0.1"
+ supports-color "^8.1.1"
+ supports-hyperlinks "^2.2.0"
+ tslib "^2.3.1"
+ widest-line "^3.1.0"
+ wrap-ansi "^7.0.0"
+
"@oclif/errors@1.3.5", "@oclif/errors@^1.2.2", "@oclif/errors@^1.3.3", "@oclif/errors@^1.3.5":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.3.5.tgz#a1e9694dbeccab10fe2fe15acb7113991bed636c"
@@ -2110,6 +2144,13 @@ debug@^3.1.0:
dependencies:
ms "^2.1.1"
+debug@^4.3.4:
+ version "4.3.4"
+ resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
+ integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
+ dependencies:
+ ms "2.1.2"
+
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
@@ -5290,6 +5331,13 @@ semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semve
dependencies:
lru-cache "^6.0.0"
+semver@^7.3.7:
+ version "7.3.7"
+ resolved "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
+ integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
+ dependencies:
+ lru-cache "^6.0.0"
+
serialize-javascript@6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8"

fix: readme for single command cli (#916)