@cenk1cenk2/oclif-common 3.6.0 → 3.7.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Command as Command$1, CliUx } from '@oclif/core';
1
+ import { Command as Command$1, Config, CliUx } from '@oclif/core';
2
2
  export { CliUx, Flags } from '@oclif/core';
3
3
  import { Logger as Logger$2, ListrTaskWrapper, ListrContext, Manager, PromptOptions } from 'listr2';
4
4
  import { Logger as Logger$1, LeveledLogMethod } from 'winston';
@@ -310,7 +310,10 @@ declare type DeepPartial<T> = {
310
310
  };
311
311
 
312
312
  declare class Command<Ctx extends ListrContext = ListrContext, Flags extends Record<PropertyKey, any> = InferFlags<typeof Command>, Args extends Record<PropertyKey, any> = InferArgs<typeof Command>, Store extends Record<PropertyKey, any> = Record<PropertyKey, any>> extends Command$1 {
313
- static globalFlags: object;
313
+ argv: string[];
314
+ config: Config;
315
+ static get globalFlags(): FlagInput;
316
+ static set globalFlags(flags: FlagInput);
314
317
  logger: Logger;
315
318
  tasks: Manager<Ctx, 'default' | 'verbose' | 'silent' | 'simple'>;
316
319
  validator: ValidatorService;
@@ -320,8 +323,7 @@ declare class Command<Ctx extends ListrContext = ListrContext, Flags extends Rec
320
323
  store: StoreService<Store>;
321
324
  flags: Flags;
322
325
  args: Args;
323
- /** Initial functions / constructor */
324
- init(): Promise<void>;
326
+ constructor(argv: string[], config: Config);
325
327
  /**
326
328
  * Construct the class if you dont want to extend init or constructor.
327
329
  */
@@ -330,25 +332,27 @@ declare class Command<Ctx extends ListrContext = ListrContext, Flags extends Rec
330
332
  * Deconstruct the class if you dont want to extend finally or catch.
331
333
  */
332
334
  shouldRunAfter(_ctx?: Ctx): void | Promise<void>;
333
- run(): Promise<void>;
334
- /** Tasks to run before end of the command. */
335
- finally<C extends Ctx = Ctx>(): Promise<{
336
- ctx: C;
337
- }>;
338
- /** Catch any error occurred during command. */
339
- catch(e: Error): Promise<void>;
335
+ run<T = void>(): Promise<T>;
336
+ _run<T>(): Promise<T | undefined>;
340
337
  exit(code?: number): void;
341
338
  /** Run all tasks from task manager. */
342
339
  runTasks<C extends Ctx = Ctx>(): Promise<C>;
343
340
  /** Gets prompt from user. */
344
341
  prompt<T = any>(options: PromptOptions): Promise<T>;
345
- setCtxDefaults(...defaults: SetCtxDefaultsOptions<Ctx>[]): void;
346
- setCtxAssign<K = Record<PropertyKey, any>>(...assigns: SetCtxAssignOptions<K>[]): void;
342
+ protected setCtxDefaults(...defaults: SetCtxDefaultsOptions<Ctx>[]): void;
343
+ protected setCtxAssign<K = Record<PropertyKey, any>>(...assigns: SetCtxAssignOptions<K>[]): void;
344
+ /** Initial functions / constructor */
345
+ protected init(): Promise<void>;
346
+ /** Tasks to run before end of the command. */
347
+ protected finally<C extends Ctx = Ctx>(): Promise<{
348
+ ctx: C;
349
+ }>;
350
+ /** Catch any error occurred during command. */
351
+ protected catch(e: Error): Promise<void>;
347
352
  private greet;
348
353
  }
349
354
 
350
355
  declare class ConfigCommand<CommandChoices extends string = string, LockFile = any, Ctx extends ListrContext = ListrContext, Flags extends Record<PropertyKey, any> = InferFlags<typeof ConfigCommand>, Args extends Record<PropertyKey, any> = InferArgs<typeof ConfigCommand>, Store extends Record<PropertyKey, any> = Record<PropertyKey, any>> extends Command<Ctx, Flags, Args, Store> {
351
- static globalFlags: object;
352
356
  choices: ConfigCommandChoices<CommandChoices>;
353
357
  locker: LockerService<LockFile>;
354
358
  protected ux: {
@@ -378,7 +382,7 @@ declare class ConfigCommand<CommandChoices extends string = string, LockFile = a
378
382
  annotation(text: string, annotation: string): void;
379
383
  flush(ms?: number): Promise<void>;
380
384
  };
381
- run(): Promise<void>;
385
+ run<T = void>(): Promise<T>;
382
386
  setup(): ConfigCommandSetup<CommandChoices, LockFile> | Promise<ConfigCommandSetup<CommandChoices, LockFile>>;
383
387
  protected table(...options: Parameters<typeof CliUx.ux.table>): void;
384
388
  protected select(): Promise<string>;
package/dist/index.js CHANGED
@@ -1032,12 +1032,68 @@ __name(setup, "setup");
1032
1032
 
1033
1033
  // src/commands/base.command.ts
1034
1034
  var Command = class extends import_core3.Command {
1035
- constructor() {
1036
- super(...arguments);
1035
+ constructor(argv, config) {
1036
+ super(argv, config);
1037
+ this.argv = argv;
1038
+ this.config = config;
1037
1039
  this.flags = {};
1038
1040
  this.args = {};
1039
1041
  }
1042
+ static get globalFlags() {
1043
+ return { CLI_FLAGS, ...this._globalFlags };
1044
+ }
1045
+ static set globalFlags(flags) {
1046
+ this._globalFlags = Object.assign({}, this.globalFlags, flags);
1047
+ this.flags = {};
1048
+ }
1049
+ shouldRunBefore() {
1050
+ }
1051
+ shouldRunAfter(_ctx) {
1052
+ }
1053
+ run() {
1054
+ throw new Error("The command should have a run function to do something!");
1055
+ }
1056
+ async _run() {
1057
+ let result;
1058
+ try {
1059
+ delete process.env[this.config.scopedEnvVarKey("REDIRECTED")];
1060
+ await this.init();
1061
+ result = await this.run();
1062
+ } catch (error) {
1063
+ await this.catch(error);
1064
+ } finally {
1065
+ await this.finally();
1066
+ }
1067
+ if (result && this.jsonEnabled()) {
1068
+ import_core2.CliUx.ux.styledJSON(this.toSuccessJson(result));
1069
+ }
1070
+ return result;
1071
+ }
1072
+ exit(code) {
1073
+ this.logger.trace("Code -> %d", code, { status: "exit" /* EXIT */ });
1074
+ process.exit(code ?? 0);
1075
+ }
1076
+ runTasks() {
1077
+ return this.tasks.runAll();
1078
+ }
1079
+ prompt(options) {
1080
+ return (0, import_listr23.createPrompt)(options, {
1081
+ stdout: process.stdout,
1082
+ cancelCallback: () => {
1083
+ throw new Error("Cancelled prompt.");
1084
+ }
1085
+ });
1086
+ }
1087
+ setCtxDefaults(...defaults) {
1088
+ setCtxDefaults(this.tasks.options.ctx, ...defaults);
1089
+ this.logger.trace("updated with defaults: %o", this.tasks.options.ctx, { status: "ctx" });
1090
+ }
1091
+ setCtxAssign(...assigns) {
1092
+ setCtxAssign(this.tasks.options.ctx, ...assigns);
1093
+ this.logger.trace("updated with assign: %o", this.tasks.options.ctx, { status: "ctx" });
1094
+ }
1040
1095
  async init() {
1096
+ await super.init();
1041
1097
  let err;
1042
1098
  try {
1043
1099
  const { flags, args } = await this.parse();
@@ -1089,13 +1145,6 @@ var Command = class extends import_core3.Command {
1089
1145
  await this.shouldRunBefore();
1090
1146
  this.logger.stage("Finished shouldRunBefore.");
1091
1147
  }
1092
- shouldRunBefore() {
1093
- }
1094
- shouldRunAfter(_ctx) {
1095
- }
1096
- run() {
1097
- throw new Error("The command should have a run function to do something!");
1098
- }
1099
1148
  async finally() {
1100
1149
  this.logger.stage("Running tasks.");
1101
1150
  const ctx = await this.runTasks();
@@ -1111,29 +1160,6 @@ var Command = class extends import_core3.Command {
1111
1160
  this.exit(127);
1112
1161
  return;
1113
1162
  }
1114
- exit(code) {
1115
- this.logger.trace("Code -> %d", code, { status: "exit" /* EXIT */ });
1116
- process.exit(code ?? 0);
1117
- }
1118
- runTasks() {
1119
- return this.tasks.runAll();
1120
- }
1121
- prompt(options) {
1122
- return (0, import_listr23.createPrompt)(options, {
1123
- stdout: process.stdout,
1124
- cancelCallback: () => {
1125
- throw new Error("Cancelled prompt.");
1126
- }
1127
- });
1128
- }
1129
- setCtxDefaults(...defaults) {
1130
- setCtxDefaults(this.tasks.options.ctx, ...defaults);
1131
- this.logger.trace("updated with defaults: %o", this.tasks.options.ctx, { status: "ctx" });
1132
- }
1133
- setCtxAssign(...assigns) {
1134
- setCtxAssign(this.tasks.options.ctx, ...assigns);
1135
- this.logger.trace("updated with assign: %o", this.tasks.options.ctx, { status: "ctx" });
1136
- }
1137
1163
  greet() {
1138
1164
  if (this.cs.isSilent || this.cs.json) {
1139
1165
  return;
@@ -1146,7 +1172,6 @@ var Command = class extends import_core3.Command {
1146
1172
  }
1147
1173
  };
1148
1174
  __name(Command, "Command");
1149
- Command.globalFlags = CLI_FLAGS;
1150
1175
 
1151
1176
  // src/commands/config.command.ts
1152
1177
  var ConfigCommand = class extends Command {
@@ -1180,7 +1205,6 @@ var ConfigCommand = class extends Command {
1180
1205
  }
1181
1206
  };
1182
1207
  __name(ConfigCommand, "ConfigCommand");
1183
- ConfigCommand.globalFlags = CLI_FLAGS;
1184
1208
 
1185
1209
  // src/hooks/not-found.hook.ts
1186
1210
  var import_core4 = require("@oclif/core");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Oclif common package for oclif2 projects.",
5
5
  "repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
6
6
  "author": {