@oclif/core 3.13.2 → 3.14.0

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.
@@ -213,6 +213,11 @@ export type OptionFlagProps = FlagProps & {
213
213
  * separate on spaces.
214
214
  */
215
215
  delimiter?: ',';
216
+ /**
217
+ * Allow input value to be read from stdin.
218
+ * Should only be used on one flag at a time.
219
+ */
220
+ allowStdin?: boolean;
216
221
  };
217
222
  export type FlagParserContext = Command & {
218
223
  token: FlagToken;
@@ -1,4 +1,5 @@
1
1
  import { OutputArgs, OutputFlags, ParserInput, ParserOutput } from '../interfaces/parser';
2
+ export declare const readStdin: () => Promise<null | string>;
2
3
  export declare class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']>, BFlags extends OutputFlags<T['flags']>, TArgs extends OutputArgs<T['args']>> {
3
4
  private readonly input;
4
5
  private readonly argv;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Parser = void 0;
3
+ exports.Parser = exports.readStdin = void 0;
4
4
  /* eslint-disable no-await-in-loop */
5
5
  const node_readline_1 = require("node:readline");
6
6
  const util_1 = require("../util/util");
@@ -54,6 +54,7 @@ const readStdin = async () => {
54
54
  }, { once: true });
55
55
  });
56
56
  };
57
+ exports.readStdin = readStdin;
57
58
  function isNegativeNumber(input) {
58
59
  return /^-\d/g.test(input);
59
60
  }
@@ -80,14 +81,14 @@ class Parser {
80
81
  }
81
82
  async parse() {
82
83
  this._debugInput();
83
- const parseFlag = (arg) => {
84
+ const parseFlag = async (arg) => {
84
85
  const { isLong, name } = this.findFlag(arg);
85
86
  if (!name) {
86
87
  const i = arg.indexOf('=');
87
88
  if (i !== -1) {
88
89
  const sliced = arg.slice(i + 1);
89
90
  this.argv.unshift(sliced);
90
- const equalsParsed = parseFlag(arg.slice(0, i));
91
+ const equalsParsed = await parseFlag(arg.slice(0, i));
91
92
  if (!equalsParsed) {
92
93
  this.argv.shift();
93
94
  }
@@ -101,11 +102,17 @@ class Parser {
101
102
  throw new errors_1.CLIError(`Flag --${name} can only be specified once`);
102
103
  }
103
104
  this.currentFlag = flag;
104
- const input = isLong || arg.length < 3 ? this.argv.shift() : arg.slice(arg[2] === '=' ? 3 : 2);
105
+ let input = isLong || arg.length < 3 ? this.argv.shift() : arg.slice(arg[2] === '=' ? 3 : 2);
105
106
  // if the value ends up being one of the command's flags, the user didn't provide an input
106
107
  if (typeof input !== 'string' || this.findFlag(input).name) {
107
108
  throw new errors_1.CLIError(`Flag --${name} expects a value`);
108
109
  }
110
+ if (flag.allowStdin && input === '-') {
111
+ const stdin = await (0, exports.readStdin)();
112
+ if (stdin) {
113
+ input = stdin.trim();
114
+ }
115
+ }
109
116
  this.raw.push({ flag: flag.name, input, type: 'flag' });
110
117
  }
111
118
  else {
@@ -129,7 +136,7 @@ class Parser {
129
136
  parsingFlags = false;
130
137
  continue;
131
138
  }
132
- if (parseFlag(input)) {
139
+ if (await parseFlag(input)) {
133
140
  continue;
134
141
  }
135
142
  if (input === '--') {
@@ -183,7 +190,7 @@ class Parser {
183
190
  args[token.arg] = parsed;
184
191
  }
185
192
  else if (!arg.ignoreStdin && !stdinRead) {
186
- let stdin = await readStdin();
193
+ let stdin = await (0, exports.readStdin)();
187
194
  if (stdin) {
188
195
  stdin = stdin.trim();
189
196
  const parsed = await arg.parse(stdin, ctx, arg);
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": "3.13.2",
4
+ "version": "3.14.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {