@oclif/core 4.0.0-beta.15 → 4.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -153,12 +153,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
153
153
  label = labels.join(flag.char ? (0, theme_1.colorize)(this.config?.theme?.flagSeparator, ', ') : ' ');
154
154
  }
155
155
  if (flag.type === 'option') {
156
- let value = flag.helpValue || (this.opts.showFlagNameInTitle ? flag.name : '<value>');
157
- if (!flag.helpValue && flag.options) {
158
- value = showOptions || this.opts.showFlagOptionsInTitle ? `${flag.options.join('|')}` : '<option>';
159
- }
160
- if (flag.multiple)
161
- value += '...';
156
+ let value = docopts_1.DocOpts.formatUsageType(flag, this.opts.showFlagNameInTitle ?? false, this.opts.showFlagOptionsInTitle ?? showOptions);
162
157
  if (!value.includes('|'))
163
158
  value = ansis_1.default.underline(value);
164
159
  label += `=${value}`;
@@ -304,7 +299,11 @@ class CommandHelp extends formatter_1.HelpFormatter {
304
299
  const dollarSign = (0, theme_1.colorize)(this.config?.theme?.dollarSign, '$');
305
300
  const bin = (0, theme_1.colorize)(this.config?.theme?.bin, this.config.bin);
306
301
  const command = (0, theme_1.colorize)(this.config?.theme?.command, '<%= command.id %>');
307
- const commandDescription = (0, theme_1.colorize)(this.config?.theme?.sectionDescription, u.replace('<%= command.id %>', '').replace(standardId, '').replace(configuredId, '').trim());
302
+ const commandDescription = (0, theme_1.colorize)(this.config?.theme?.sectionDescription, u
303
+ .replace('<%= command.id %>', '')
304
+ .replace(new RegExp(`^${standardId}`), '')
305
+ .replace(new RegExp(`^${configuredId}`), '')
306
+ .trim());
308
307
  const line = `${dollarSign} ${bin} ${command} ${commandDescription}`.trim();
309
308
  if (line.length > allowedSpacing) {
310
309
  const splitIndex = line.slice(0, Math.max(0, allowedSpacing)).lastIndexOf(' ');
@@ -60,6 +60,7 @@ export declare class DocOpts {
60
60
  private flagList;
61
61
  private flagMap;
62
62
  constructor(cmd: Command.Loadable);
63
+ static formatUsageType(flag: Command.Flag.Any, showFlagName: boolean, showOptions: boolean): string;
63
64
  static generate(cmd: Command.Loadable): string;
64
65
  toString(): string;
65
66
  private combineElementsToFlag;
@@ -73,6 +73,27 @@ class DocOpts {
73
73
  return flag;
74
74
  });
75
75
  }
76
+ static formatUsageType(flag, showFlagName, showOptions) {
77
+ if (flag.type !== 'option')
78
+ return '';
79
+ let helpValues;
80
+ if (flag.helpValue) {
81
+ // if there is a given helpValue, use it
82
+ helpValues = typeof flag.helpValue === 'string' ? [flag.helpValue] : flag.helpValue;
83
+ }
84
+ else if (flag.options) {
85
+ // if there are options, show them if wanted
86
+ helpValues = [showOptions ? flag.options.join('|') : '<option>'];
87
+ }
88
+ else if (showFlagName) {
89
+ helpValues = [flag.name];
90
+ }
91
+ else {
92
+ // default to <value>
93
+ helpValues = ['<value>'];
94
+ }
95
+ return helpValues.map((v) => `${v}${flag.multiple ? '...' : ''}`).join(' ');
96
+ }
76
97
  static generate(cmd) {
77
98
  return new DocOpts(cmd).toString();
78
99
  }
@@ -93,7 +114,7 @@ class DocOpts {
93
114
  const name = flag.char ? `-${flag.char}` : `--${flag.name}`;
94
115
  if (flag.type === 'boolean')
95
116
  return name;
96
- return `${name}=<value>`;
117
+ return `${name}=${DocOpts.formatUsageType(flag, false, true)}`;
97
118
  }));
98
119
  }
99
120
  return opts.join(' ');
@@ -123,7 +144,7 @@ class DocOpts {
123
144
  // not all flags have short names
124
145
  const flagName = flag.char ? `-${flag.char}` : `--${flag.name}`;
125
146
  if (flag.type === 'option') {
126
- type = flag.options ? ` ${flag.options.join('|')}` : ' <value>';
147
+ type = ` ${DocOpts.formatUsageType(flag, false, true)}`;
127
148
  }
128
149
  const element = `${flagName}${type}`;
129
150
  elementMap[flag.name] = element;
@@ -198,7 +198,7 @@ export type BooleanFlagProps = FlagProps & {
198
198
  };
199
199
  export type OptionFlagProps = FlagProps & {
200
200
  type: 'option';
201
- helpValue?: string;
201
+ helpValue?: string | string[];
202
202
  options?: readonly string[];
203
203
  multiple?: boolean;
204
204
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "4.0.0-beta.15",
4
+ "version": "4.0.0-beta.16",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -10,7 +10,7 @@
10
10
  "clean-stack": "^3.0.1",
11
11
  "cli-spinners": "^2.9.2",
12
12
  "cosmiconfig": "^9.0.0",
13
- "debug": "^4.3.4",
13
+ "debug": "^4.3.5",
14
14
  "ejs": "^3.1.10",
15
15
  "get-package-type": "^0.1.0",
16
16
  "globby": "^11.1.0",