@oclif/core 3.0.0-beta.14 → 3.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.
@@ -1,12 +1,10 @@
1
+ import { Options } from './types';
1
2
  export interface ITask {
2
3
  action: string;
3
4
  status: string | undefined;
4
5
  active: boolean;
5
6
  }
6
7
  export type ActionType = 'spinner' | 'simple' | 'debug';
7
- export interface Options {
8
- stdout?: boolean;
9
- }
10
8
  export declare class ActionBase {
11
9
  type: ActionType;
12
10
  std: 'stdout' | 'stderr';
@@ -24,7 +22,7 @@ export declare class ActionBase {
24
22
  set status(status: string | undefined);
25
23
  pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
26
24
  pause(fn: () => any, icon?: string): Promise<any>;
27
- protected _start(): void;
25
+ protected _start(_opts: Options): void;
28
26
  protected _stop(_: string): void;
29
27
  protected _resume(): void;
30
28
  protected _pause(_?: string): void;
@@ -16,7 +16,7 @@ class ActionBase {
16
16
  this.std = opts.stdout ? 'stdout' : 'stderr';
17
17
  const task = { action, status, active: Boolean(this.task && this.task.active) };
18
18
  this.task = task;
19
- this._start();
19
+ this._start(opts);
20
20
  task.active = true;
21
21
  this._stdout(true);
22
22
  }
@@ -93,7 +93,7 @@ class ActionBase {
93
93
  }
94
94
  return ret;
95
95
  }
96
- _start() {
96
+ _start(_opts) {
97
97
  throw new Error('not implemented');
98
98
  }
99
99
  _stop(_) {
@@ -7,10 +7,9 @@ class SimpleAction extends base_1.ActionBase {
7
7
  this.type = 'simple';
8
8
  }
9
9
  _start() {
10
- const { task } = this;
11
- if (!task)
10
+ if (!this.task)
12
11
  return;
13
- this._render(task.action, task.status);
12
+ this._render(this.task.action, this.task.status);
14
13
  }
15
14
  _pause(icon) {
16
15
  if (icon)
@@ -22,29 +21,26 @@ class SimpleAction extends base_1.ActionBase {
22
21
  // Not implemented
23
22
  }
24
23
  _updateStatus(status, prevStatus, newline = false) {
25
- const { task, std } = this;
26
- if (!task)
24
+ if (!this.task)
27
25
  return;
28
- if (task.active && !prevStatus)
29
- this._write(std, ` ${status}`);
26
+ if (this.task.active && !prevStatus)
27
+ this._write(this.std, ` ${status}`);
30
28
  else
31
- this._write(std, `${task.action}... ${status}`);
29
+ this._write(this.std, `${this.task.action}... ${status}`);
32
30
  if (newline || !prevStatus)
33
31
  this._flush();
34
32
  }
35
33
  _stop(status) {
36
- const { task } = this;
37
- if (!task)
34
+ if (!this.task)
38
35
  return;
39
- this._updateStatus(status, task.status, true);
36
+ this._updateStatus(status, this.task.status, true);
40
37
  }
41
38
  _render(action, status) {
42
- const { task, std } = this;
43
- if (!task)
39
+ if (!this.task)
44
40
  return;
45
- if (task.active)
41
+ if (this.task.active)
46
42
  this._flush();
47
- this._write(std, status ? `${action}... ${status}` : `${action}...`);
43
+ this._write(this.std, status ? `${action}... ${status}` : `${action}...`);
48
44
  }
49
45
  _flush() {
50
46
  this._write(this.std, '\n');
@@ -1,15 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  import { ActionBase, ActionType } from './base';
3
+ import { Options } from './types';
3
4
  export default class SpinnerAction extends ActionBase {
4
5
  type: ActionType;
5
6
  spinner?: NodeJS.Timeout;
6
- frames: any;
7
+ frames: string[];
7
8
  frameIndex: number;
8
9
  constructor();
9
- protected _start(): void;
10
+ protected _start(opts: Options): void;
10
11
  protected _stop(status: string): void;
11
12
  protected _pause(icon?: string): void;
12
13
  protected _frame(): string;
14
+ private getFrames;
13
15
  private _render;
14
16
  private _reset;
15
17
  private _lines;
@@ -18,10 +18,12 @@ class SpinnerAction extends base_1.ActionBase {
18
18
  constructor() {
19
19
  super();
20
20
  this.type = 'spinner';
21
- this.frames = spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
21
+ this.frames = this.getFrames();
22
22
  this.frameIndex = 0;
23
23
  }
24
- _start() {
24
+ _start(opts) {
25
+ if (opts.style)
26
+ this.frames = this.getFrames(opts);
25
27
  this._reset();
26
28
  if (this.spinner)
27
29
  clearInterval(this.spinner);
@@ -51,16 +53,20 @@ class SpinnerAction extends base_1.ActionBase {
51
53
  this.frameIndex = ++this.frameIndex % this.frames.length;
52
54
  return color(frame);
53
55
  }
56
+ getFrames(opts) {
57
+ if (opts?.style)
58
+ return spinners_1.default[process.platform === 'win32' ? 'line' : opts.style].frames;
59
+ return spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
60
+ }
54
61
  _render(icon) {
55
- const { task, std, output } = this;
56
- if (!task)
62
+ if (!this.task)
57
63
  return;
58
64
  this._reset();
59
65
  this._flushStdout();
60
66
  const frame = icon === 'spinner' ? ` ${this._frame()}` : icon || '';
61
- const status = task.status ? ` ${task.status}` : '';
62
- this.output = `${task.action}...${frame}${status}\n`;
63
- this._write(std, output);
67
+ const status = this.task.status ? ` ${this.task.status}` : '';
68
+ this.output = `${this.task.action}...${frame}${status}\n`;
69
+ this._write(this.std, this.output);
64
70
  }
65
71
  _reset() {
66
72
  if (!this.output)
@@ -0,0 +1,5 @@
1
+ import spinners from './spinners';
2
+ export type Options = {
3
+ stdout?: boolean;
4
+ style?: keyof typeof spinners;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -5,11 +5,11 @@ export declare namespace table {
5
5
  columns: Interfaces.OptionFlag<string | undefined>;
6
6
  sort: Interfaces.OptionFlag<string | undefined>;
7
7
  filter: Interfaces.OptionFlag<string | undefined>;
8
- csv: Interfaces.Flag<boolean>;
8
+ csv: Interfaces.BooleanFlag<boolean>;
9
9
  output: Interfaces.OptionFlag<string | undefined>;
10
- extended: Interfaces.Flag<boolean>;
11
- 'no-truncate': Interfaces.Flag<boolean>;
12
- 'no-header': Interfaces.Flag<boolean>;
10
+ extended: Interfaces.BooleanFlag<boolean>;
11
+ 'no-truncate': Interfaces.BooleanFlag<boolean>;
12
+ 'no-header': Interfaces.BooleanFlag<boolean>;
13
13
  };
14
14
  type IFlags = typeof Flags;
15
15
  type ExcludeFlags<T, Z> = Pick<T, Exclude<keyof T, Z>>;
@@ -210,7 +210,7 @@ export type OptionFlagProps = FlagProps & {
210
210
  export type FlagParserContext = Command & {
211
211
  token: FlagToken;
212
212
  };
213
- export type FlagParser<T, I extends string | boolean, P = CustomOptions> = (input: I, context: FlagParserContext, opts: P & OptionFlag<T, P>) => T extends Array<infer U> ? Promise<U> : Promise<T>;
213
+ export type FlagParser<T, I extends string | boolean, P = CustomOptions> = (input: I, context: FlagParserContext, opts: P & OptionFlag<T, P>) => T extends Array<infer U> ? Promise<U | undefined> : Promise<T | undefined>;
214
214
  export type ArgParserContext = Command & {
215
215
  token: ArgToken;
216
216
  };
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.0.0-beta.14",
4
+ "version": "3.0.0-beta.16",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {