Skip to content

Commit

Permalink
Merge pull request #1451 from salesforcecli/mdonnalley/theme
Browse files Browse the repository at this point in the history
feat: add theme
  • Loading branch information
shetzel authored Feb 5, 2024
2 parents 81ad3ce + 10444f3 commit 39f64de
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 377 deletions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"/oclif.manifest.json",
"/npm-shrinkwrap.json",
"/scripts/preinstall.js",
"/scripts/post-install-release-notes.js"
"/scripts/post-install-release-notes.js",
"/theme.json"
],
"keywords": [
"oclif",
Expand All @@ -41,6 +42,7 @@
"flexibleTaxonomy": true,
"commands": "./dist/commands",
"helpClass": "./dist/help/sfHelp.js",
"theme": "theme.json",
"plugins": [
"@oclif/plugin-autocomplete",
"@oclif/plugin-commands",
Expand Down Expand Up @@ -134,7 +136,7 @@
},
"dependencies": {
"@inquirer/select": "^1.3.1",
"@oclif/core": "3.18.2",
"@oclif/core": "3.19.0",
"@oclif/plugin-autocomplete": "3.0.7",
"@oclif/plugin-commands": "3.1.2",
"@oclif/plugin-help": "6.0.12",
Expand Down Expand Up @@ -164,7 +166,9 @@
"@salesforce/plugin-trust": "3.3.6",
"@salesforce/plugin-user": "3.2.7",
"@salesforce/sf-plugins-core": "7.1.7",
"debug": "^4.3.4"
"chalk": "^5.3.0",
"debug": "^4.3.4",
"strip-ansi": "^7.1.0"
},
"pinnedDependencies": [
"@oclif/core",
Expand Down Expand Up @@ -247,7 +251,7 @@
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.2",
"@salesforce/dev-scripts": "^8.1.0",
"@salesforce/plugin-release-management": "^4.5.27",
"@salesforce/plugin-release-management": "^4.7.7",
"@salesforce/ts-sinon": "^1.4.19",
"@types/debug": "^4.1.12",
"aws-sdk": "^2.1545.0",
Expand Down
35 changes: 19 additions & 16 deletions src/help/sfHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* 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 { Command, CommandHelp, Help } from '@oclif/core';
import { Command, CommandHelp, Help, toConfiguredId } from '@oclif/core';
import stripAnsi from 'strip-ansi';
import chalk from 'chalk';
import { SfCommandHelp } from './sfCommandHelp.js';

Expand All @@ -13,18 +14,10 @@ export default class SfHelp extends Help {
protected commandHelpClass: SfCommandHelp | undefined;
private showShortHelp = false;
private commands: string[] = [];
private subCommands: Record<string, string[]> = {};

public async showHelp(argv: string[]): Promise<void> {
this.showShortHelp = argv.includes('-h');
this.commands = this.config.commandIDs.map(
(c) => `${this.config.bin} ${c.replace(/:/g, this.config.topicSeparator)}`
);
for (const cmd of this.commands) {
this.subCommands[cmd] = this.commands
.filter((c) => c.startsWith(cmd) && c !== cmd)
.map((c) => `${c.replace(cmd, '')}`);
}
this.commands = this.config.commandIDs.map((c) => `${this.config.bin} ${toConfiguredId(c, this.config)}`);

return super.showHelp(argv);
}
Expand All @@ -38,12 +31,22 @@ export default class SfHelp extends Help {
protected log(...args: string[]): void {
const formatted = args.map((arg) => {
for (const cmd of this.commands) {
const regex =
this.subCommands[cmd].length > 0
? new RegExp(`(?<!\\$ )${cmd}(?!${this.subCommands[cmd].join('|')})`, 'g')
: new RegExp(`(?<!\\$ )${cmd}`, 'g');

arg = arg.replace(regex, chalk.dim(cmd));
/**
* This regex matches any command in the help output.
* It will continue to match until the next space, quote, or period.
*
* Examples that will match:
* - sf deploy project start
* - "sf deploy project start"
* - sf org create scratch|sandbox
* - "sf org create scratch|sandbox"
*/
const regex = new RegExp(`${cmd}([^\\s".]+)?`, 'g');
const [match] = stripAnsi(arg.slice()).match(regex) ?? [];

if (match) {
arg = arg.replace(regex, chalk.dim(match));
}
}

return arg;
Expand Down
15 changes: 15 additions & 0 deletions theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"bin": "blueBright",
"command": "blueBright",
"commandSummary": "none",
"dollarSign": "green",
"flag": "green",
"flagDefaultValue": "blueBright",
"flagOptions": "blueBright",
"flagRequired": "red",
"flagSeparator": "none",
"sectionDescription": "none",
"sectionHeader": "blue",
"topic": "blueBright",
"version": "none"
}
Loading

0 comments on commit 39f64de

Please sign in to comment.