Skip to content

Commit

Permalink
Merge branch 'main' into mdonnalley/no-tsconfck
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 9, 2024
2 parents c741c74 + b9f5fb5 commit eafdba3
Show file tree
Hide file tree
Showing 22 changed files with 1,031 additions and 732 deletions.
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
# [3.16.0](https://github.com/oclif/core/compare/3.15.1...3.16.0) (2024-01-02)


### Features

* add 'only' option to allowStdin ([#900](https://github.com/oclif/core/issues/900)) ([4f7346e](https://github.com/oclif/core/commit/4f7346e2ebcbf72181f147e38a7d94bcd443c08b))



## [3.15.1](https://github.com/oclif/core/compare/3.15.0...3.15.1) (2023-12-23)


### Bug Fixes

* **deps:** bump password-prompt from 1.1.2 to 1.1.3 ([39f8860](https://github.com/oclif/core/commit/39f8860e6da3b9bd98ed9c5357cbdbe66f73b186))



# [3.15.0](https://github.com/oclif/core/compare/3.14.1...3.15.0) (2023-12-15)


### Features

* add flagSortOrder to help options ([#896](https://github.com/oclif/core/issues/896)) ([3903720](https://github.com/oclif/core/commit/3903720377dde5c9f92d8c24f57cf9a32e516b3d))



## [3.14.1](https://github.com/oclif/core/compare/3.14.0...3.14.1) (2023-12-08)


### Bug Fixes

* peserve original error coming from failed flag parsing ([#897](https://github.com/oclif/core/issues/897)) ([a7a3bba](https://github.com/oclif/core/commit/a7a3bbabdf2a6cce19dd86583ca91409e0de3123))



# [3.14.0](https://github.com/oclif/core/compare/3.13.2...3.14.0) (2023-12-07)


### Features

* allowStdin option for flags ([#894](https://github.com/oclif/core/issues/894)) ([#895](https://github.com/oclif/core/issues/895)) ([379e940](https://github.com/oclif/core/commit/379e9401f8c8f7400be71e2e45c65fd6564a8c21))



## [3.13.2](https://github.com/oclif/core/compare/3.13.1...3.13.2) (2023-12-04)


### Bug Fixes

* add exit codes to different flag validation errors ([#861](https://github.com/oclif/core/issues/861)) ([1c841bf](https://github.com/oclif/core/commit/1c841bf296f89529183a182433ce2baddc697072))



## [3.13.1](https://github.com/oclif/core/compare/3.13.0...3.13.1) (2023-11-30)


Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "3.13.1",
"version": "3.16.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/core/issues",
"dependencies": {
Expand All @@ -22,7 +22,7 @@
"js-yaml": "^3.14.1",
"natural-orderby": "^2.0.3",
"object-treeify": "^1.1.33",
"password-prompt": "^1.1.2",
"password-prompt": "^1.1.3",
"slice-ansi": "^4.0.0",
"string-width": "^4.2.3",
"strip-ansi": "^6.0.1",
Expand All @@ -34,29 +34,29 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^17.8.1",
"@oclif/plugin-help": "^5.2.20",
"@oclif/plugin-plugins": "^3.3.0",
"@oclif/plugin-help": "^6",
"@oclif/plugin-plugins": "^4",
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^3.0.3",
"@types/ansi-styles": "^3.2.1",
"@types/benchmark": "^2.1.2",
"@types/chai": "^4.3.10",
"@types/benchmark": "^2.1.5",
"@types/chai": "^4.3.11",
"@types/chai-as-promised": "^7.1.8",
"@types/clean-stack": "^2.1.1",
"@types/cli-progress": "^3.11.0",
"@types/cli-progress": "^3.11.5",
"@types/color": "^3.0.5",
"@types/debug": "^4.1.10",
"@types/ejs": "^3.1.3",
"@types/ejs": "^3.1.5",
"@types/indent-string": "^4.0.1",
"@types/js-yaml": "^3.12.7",
"@types/mocha": "^10.0.2",
"@types/mocha": "^10.0.6",
"@types/node": "^18",
"@types/node-notifier": "^8.0.2",
"@types/pnpapi": "^0.0.4",
"@types/pnpapi": "^0.0.5",
"@types/slice-ansi": "^4.0.0",
"@types/strip-ansi": "^5.2.1",
"@types/supports-color": "^8.1.1",
"@types/wordwrap": "^1.0.1",
"@types/wordwrap": "^1.0.3",
"@types/wrap-ansi": "^3.0.0",
"benchmark": "^2.1.4",
"chai": "^4.3.10",
Expand All @@ -74,9 +74,9 @@
"madge": "^6.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^3.0.3",
"prettier": "^3.1.1",
"shx": "^0.3.4",
"sinon": "^16.1.0",
"sinon": "^16.1.3",
"ts-node": "^10.9.1",
"tsd": "^0.29.0",
"typescript": "^5"
Expand Down
4 changes: 3 additions & 1 deletion src/config/cache.ts → src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Plugin} from '../interfaces'
import {PJSON, Plugin} from './interfaces'

type CacheContents = {
rootPlugin: Plugin
exitCodes: PJSON.Plugin['oclif']['exitCodes']
}

type ValueOf<T> = T[keyof T]
Expand All @@ -20,6 +21,7 @@ export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContent
}

public get(key: 'rootPlugin'): Plugin | undefined
public get(key: 'exitCodes'): PJSON.Plugin['oclif']['exitCodes'] | undefined
public get(key: keyof CacheContents): ValueOf<CacheContents> | undefined {
return super.get(key)
}
Expand Down
6 changes: 4 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {arch, userInfo as osUserInfo, release, tmpdir, type} from 'node:os'
import {join, resolve, sep} from 'node:path'
import {URL, fileURLToPath} from 'node:url'

import Cache from '../cache'
import {ux} from '../cli-ux'
import {parseTheme} from '../cli-ux/theme'
import {Command} from '../command'
Expand All @@ -19,7 +20,6 @@ import {settings} from '../settings'
import {requireJson, safeReadJson} from '../util/fs'
import {getHomeDir, getPlatform} from '../util/os'
import {compact, isProd} from '../util/util'
import Cache from './cache'
import PluginLoader from './plugin-loader'
import {tsPath} from './ts-node'
import {Debug, collectUsableIds, getCommandIdPermutations} from './util'
Expand Down Expand Up @@ -290,7 +290,9 @@ export class Config implements IConfig {

// Cache the root plugin so that we can reference it later when determining if
// we should skip ts-node registration for an ESM plugin.
Cache.getInstance().set('rootPlugin', this.rootPlugin)
const cache = Cache.getInstance()
cache.set('rootPlugin', this.rootPlugin)
cache.set('exitCodes', this.rootPlugin.pjson.oclif.exitCodes ?? {})

this.root = this.rootPlugin.root
this.pjson = this.rootPlugin.pjson
Expand Down
2 changes: 1 addition & 1 deletion src/config/ts-node.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {join, relative as pathRelative, sep} from 'node:path'
import * as TSNode from 'ts-node'

import Cache from '../cache'
import {memoizedWarn} from '../errors'
import {Plugin, TSConfig} from '../interfaces'
import {settings} from '../settings'
import {existsSync} from '../util/fs'
import {readTSConfig} from '../util/read-tsconfig'
import {isProd} from '../util/util'
import Cache from './cache'
import {Debug} from './util'
// eslint-disable-next-line new-cap
const debug = Debug('ts-node')
Expand Down
3 changes: 2 additions & 1 deletion src/errors/errors/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cs from 'clean-stack'
import indent from 'indent-string'
import wrap from 'wrap-ansi'

import Cache from '../../cache'
import {OclifError, PrettyPrintableError} from '../../interfaces/errors'
import {errtermwidth} from '../../screen'
import {config} from '../config'
Expand All @@ -16,7 +17,7 @@ export function addOclifExitCode(error: Record<string, any>, options?: {exit?: f
;(error as unknown as OclifError).oclif = {}
}

error.oclif.exit = options?.exit === undefined ? 2 : options.exit
error.oclif.exit = options?.exit === undefined ? Cache.getInstance().get('exitCodes')?.default ?? 2 : options.exit
return error as OclifError
}

Expand Down
31 changes: 22 additions & 9 deletions src/help/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import {HelpFormatter, HelpSection, HelpSectionRenderer} from './formatter'
// split on any platform, not just the os specific EOL at runtime.
const POSSIBLE_LINE_FEED = /\r\n|\n/

/**
* Determines the sort order of flags. Will default to alphabetical if not set or set to an invalid value.
*/
function determineSortOrder(
flagSortOrder: HelpFormatter['opts']['flagSortOrder'],
): NonNullable<HelpFormatter['opts']['flagSortOrder']> {
if (flagSortOrder === 'alphabetical') return 'alphabetical'
if (flagSortOrder === 'none') return 'none'
return 'alphabetical'
}

export class CommandHelp extends HelpFormatter {
constructor(
public command: Command.Loadable,
Expand Down Expand Up @@ -218,15 +229,17 @@ export class CommandHelp extends HelpFormatter {

generate(): string {
const cmd = this.command
const flags = sortBy(
Object.entries(cmd.flags || {})
.filter(([, v]) => !v.hidden)
.map(([k, v]) => {
v.name = k
return v
}),
(f) => [!f.char, f.char, f.name],
)
const unsortedFlags = Object.entries(cmd.flags || {})
.filter(([, v]) => !v.hidden)
.map(([k, v]) => {
v.name = k
return v
})

const flags =
determineSortOrder(this.opts.flagSortOrder) === 'alphabetical'
? sortBy(unsortedFlags, (f) => [!f.char, f.char, f.name])
: unsortedFlags

const args = Object.values(ensureArgObject(cmd.args)).filter((a) => !a.hidden)
const output = compact(
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ export interface HelpOptions {
* Use docopts as the usage. Defaults to true.
*/
docopts?: boolean
/**
* Order in which to sort flags in help output. Defaults to `alphabetical`.
*
* `alphabetical`: Sort flags alphabetically. All flags with short characters will come first.
* `none`: Do not sort flags. They will appear in the order in which they were defined on the command.
*/
flagSortOrder?: 'alphabetical' | 'none'
/**
* If true, hide command aliases from the root help output. Defaults to false.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type CLIParseErrorOptions = {
input?: ParserInput
output?: ParserOutput
}
exit?: number
}

export type OutputArgs<T extends ParserInput['args']> = {[P in keyof T]: any}
Expand Down Expand Up @@ -220,6 +221,12 @@ export type OptionFlagProps = FlagProps & {
* separate on spaces.
*/
delimiter?: ','
/**
* Allow input value to be read from stdin if the provided value is `-`.
* If set to `only`, the flag will only accept input from stdin.
* Should only be used on one flag at a time.
*/
allowStdin?: boolean | 'only'
}

export type FlagParserContext = Command & {token: FlagToken}
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/pjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ export namespace PJSON {
default?: string
description?: string
devPlugins?: string[]
exitCodes?: {
default?: number
failedFlagParsing?: number
failedFlagValidation?: number
invalidArgsSpec?: number
nonExistentFlag?: number
requiredArgs?: number
unexpectedArgs?: number
}
flexibleTaxonomy?: boolean
helpClass?: string
helpOptions?: HelpOptions
Expand Down
Loading

0 comments on commit eafdba3

Please sign in to comment.