-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: copy oclif/core ux methods (#537)
* feat: copy oclif/core ux methods * feat: use cli-progress instead of ux.progress * test: add integration tests for table * test: remove test * refactor: use AnyJson for styledObject * feat!: use next major of oclif/core BREAKING CHANGE: remove csv, json and yaml from table options * chore: use ux.stdout from core * chore: bump @oclif/core * chore(release): 9.0.3-beta.0 [skip ci] * chore: bump @oclif/core * chore(release): 9.0.3-beta.1 [skip ci] * ci: update preBuildCommands * ci: update preBuildCommands * chore: bump core * chore: bump core * chore(release): 9.0.14-beta.1 [skip ci] * fix: core v4 * chore(release): 9.1.1-beta.1 [skip ci] * test: dont rm oclif/core for external nuts * test: remove ocilf/core in prebuild * chore: make new major * chore(release): 10.0.0-beta.1 [skip ci] * chore: code review * style: todo for mutation bug * test: try slow integration test * chore: sfdx-core bump for xnuts * test: re-skip --------- Co-authored-by: svc-cli-bot <[email protected]> Co-authored-by: mshanemc <[email protected]>
- Loading branch information
1 parent
7072331
commit 97f5584
Showing
18 changed files
with
1,212 additions
and
1,174 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
Large diffs are not rendered by default.
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
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
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,53 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { inspect } from 'node:util'; | ||
import ansis from 'ansis'; | ||
import { AnyJson } from '@salesforce/ts-types'; | ||
|
||
function prettyPrint(obj: AnyJson): string { | ||
if (!obj) return inspect(obj); | ||
if (typeof obj === 'string') return obj; | ||
if (typeof obj === 'number') return obj.toString(); | ||
if (typeof obj === 'boolean') return obj.toString(); | ||
if (typeof obj === 'object') { | ||
return Object.entries(obj) | ||
.map(([key, value]) => `${key}: ${inspect(value)}`) | ||
.join(', '); | ||
} | ||
|
||
return inspect(obj); | ||
} | ||
|
||
export default function styledObject(obj: AnyJson, keys?: string[]): string { | ||
if (!obj) return inspect(obj); | ||
if (typeof obj === 'string') return obj; | ||
if (typeof obj === 'number') return obj.toString(); | ||
if (typeof obj === 'boolean') return obj.toString(); | ||
|
||
const output: string[] = []; | ||
const keyLengths = Object.keys(obj).map((key) => key.toString().length); | ||
const maxKeyLength = Math.max(...keyLengths) + 2; | ||
|
||
const logKeyValue = (key: string, value: AnyJson): string => | ||
`${ansis.blue(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + prettyPrint(value); | ||
|
||
for (const [key, value] of Object.entries(obj)) { | ||
if (keys && !keys.includes(key)) continue; | ||
if (Array.isArray(value)) { | ||
if (value.length > 0) { | ||
output.push(logKeyValue(key, value[0])); | ||
for (const e of value.slice(1)) { | ||
output.push(' '.repeat(maxKeyLength) + prettyPrint(e)); | ||
} | ||
} | ||
} else if (value !== null && value !== undefined) { | ||
output.push(logKeyValue(key, value)); | ||
} | ||
} | ||
|
||
return output.join('\n'); | ||
} |
Oops, something went wrong.