@oclif/core 1.18.0 → 1.19.1

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/README.md CHANGED
@@ -21,20 +21,20 @@ The [cli-ux README](./src/cli-ux/README.md) also contains detailed usage example
21
21
  Usage
22
22
  =====
23
23
 
24
- Without the generator, you can create a simple CLI like this:
24
+ We strongly encourage you generate an oclif CLI using the [oclif cli](https://github.com/oclif/oclif). The generator will generate an npm package with `@oclif/core` as a dependency.
25
25
 
26
- **TypeScript**
27
- ```js
26
+ You can, however, use `@oclif/core` in a standalone script like this:
27
+ ```typescript
28
28
  #!/usr/bin/env ts-node
29
29
 
30
30
  import * as fs from 'fs'
31
31
  import {Command, Flags} from '@oclif/core'
32
32
 
33
33
  class LS extends Command {
34
+ static description = 'List the files in a directory.'
34
35
  static flags = {
35
36
  version: Flags.version(),
36
37
  help: Flags.help(),
37
- // run with --dir= or -d=
38
38
  dir: Flags.string({
39
39
  char: 'd',
40
40
  default: process.cwd(),
@@ -43,34 +43,23 @@ class LS extends Command {
43
43
 
44
44
  async run() {
45
45
  const {flags} = await this.parse(LS)
46
- let files = fs.readdirSync(flags.dir)
47
- for (let f of files) {
46
+ const files = fs.readdirSync(flags.dir)
47
+ for (const f of files) {
48
48
  this.log(f)
49
49
  }
50
50
  }
51
51
  }
52
52
 
53
- LS.run()
54
- .catch(require('@oclif/core/handle'))
53
+ LS.run().then(() => {
54
+ require('@oclif/core/flush')
55
+ }, () => {
56
+ require('@oclif/core/handle')
57
+ })
55
58
  ```
56
59
 
57
- Then run either of these with:
60
+ Then run it like this:
58
61
 
59
62
  ```sh-session
60
- $ ./myscript
63
+ $ ts-node myscript.ts
61
64
  ...files in current dir...
62
- $ ./myscript --dir foobar
63
- ...files in ./foobar...
64
- $ ./myscript --version
65
- myscript/0.0.0 darwin-x64 node-v9.5.0
66
- $ ./myscript --help
67
- USAGE
68
- $ @oclif/core
69
-
70
- OPTIONS
71
- -d, --dir=dir [default: /Users/jdickey/src/github.com/oclif/core]
72
- --help show CLI help
73
- --version show CLI version
74
65
  ```
75
-
76
- See the [generator](https://github.com/oclif/oclif) for all the options you can pass to the command.
package/lib/command.d.ts CHANGED
@@ -97,7 +97,8 @@ export default abstract class Command {
97
97
  */
98
98
  abstract run(): PromiseLike<any>;
99
99
  protected init(): Promise<any>;
100
- protected checkForDeprecations(): void;
100
+ protected warnIfFlagDeprecated(flags: Record<string, unknown>): void;
101
+ protected warnIfCommandDeprecated(): void;
101
102
  protected parse<F extends Interfaces.FlagOutput, G extends Interfaces.FlagOutput, A extends {
102
103
  [name: string]: any;
103
104
  }>(options?: Interfaces.Input<F, G>, argv?: string[]): Promise<Interfaces.ParserOutput<F, G, A>>;
package/lib/command.js CHANGED
@@ -126,18 +126,21 @@ class Command {
126
126
  const g = global;
127
127
  g['http-call'] = g['http-call'] || {};
128
128
  g['http-call'].userAgent = this.config.userAgent;
129
- this.checkForDeprecations();
129
+ this.warnIfCommandDeprecated();
130
130
  }
131
- checkForDeprecations() {
131
+ warnIfFlagDeprecated(flags) {
132
+ for (const flag of Object.keys(flags)) {
133
+ const deprecated = this.ctor.flags[flag]?.deprecated;
134
+ if (deprecated) {
135
+ this.warn((0, util_2.formatFlagDeprecationWarning)(flag, deprecated));
136
+ }
137
+ }
138
+ }
139
+ warnIfCommandDeprecated() {
132
140
  if (this.ctor.state === 'deprecated') {
133
141
  const cmdName = (0, index_1.toConfiguredId)(this.ctor.id, this.config);
134
142
  this.warn((0, util_2.formatCommandDeprecationWarning)(cmdName, this.ctor.deprecationOptions));
135
143
  }
136
- for (const [flag, opts] of Object.entries(this.ctor.flags ?? {})) {
137
- if (opts.deprecated) {
138
- this.warn((0, util_2.formatFlagDeprecationWarning)(flag, opts.deprecated));
139
- }
140
- }
141
144
  }
142
145
  async parse(options, argv = this.argv) {
143
146
  if (!options)
@@ -146,7 +149,9 @@ class Command {
146
149
  // the spread operator doesn't work with getters so we have to manually add it here
147
150
  opts.flags = options?.flags;
148
151
  opts.args = options?.args;
149
- return Parser.parse(argv, opts);
152
+ const results = await Parser.parse(argv, opts);
153
+ this.warnIfFlagDeprecated(results.flags ?? {});
154
+ return results;
150
155
  }
151
156
  async catch(err) {
152
157
  process.exitCode = process.exitCode ?? err.exitCode ?? 1;
package/lib/flags.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.help = exports.version = exports.enum = exports._enum = exports.custom = exports.option = exports.build = exports.string = exports.file = exports.directory = exports.url = exports.integer = exports.boolean = void 0;
4
4
  const parser_1 = require("./parser");
5
+ const help_1 = require("./help");
5
6
  var parser_2 = require("./parser");
6
7
  Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return parser_2.boolean; } });
7
8
  Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return parser_2.integer; } });
@@ -41,7 +42,8 @@ const help = (opts = {}) => {
41
42
  description: 'Show CLI help.',
42
43
  ...opts,
43
44
  parse: async (_, cmd) => {
44
- cmd._help();
45
+ new help_1.Help(cmd.config).showHelp(cmd.argv);
46
+ cmd.exit(0);
45
47
  },
46
48
  });
47
49
  };
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": "1.18.0",
4
+ "version": "1.19.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {