@oclif/core 1.4.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.5.0](https://github.com/oclif/core/compare/v1.4.0...v1.5.0) (2022-03-02)
6
+
7
+
8
+ ### Features
9
+
10
+ * dir and file flags that validate existence and type ([#384](https://github.com/oclif/core/issues/384)) ([44dff41](https://github.com/oclif/core/commit/44dff41c5a3ffcdcbf2f10dcefb7c1ab233bfc4f))
11
+
5
12
  ## [1.4.0](https://github.com/oclif/core/compare/v1.3.6...v1.4.0) (2022-03-01)
6
13
 
7
14
 
package/lib/flags.d.ts CHANGED
@@ -10,6 +10,6 @@ declare const _enum: <T = string>(opts: EnumFlagOptions<T>) => OptionFlag<T>;
10
10
  export { _enum as enum };
11
11
  declare const stringFlag: Definition<string>;
12
12
  export { stringFlag as string };
13
- export { boolean, integer, url } from './parser';
13
+ export { boolean, integer, url, directory, file } from './parser';
14
14
  export declare const version: (opts?: Partial<BooleanFlag<boolean>>) => BooleanFlag<void>;
15
15
  export declare const help: (opts?: Partial<BooleanFlag<boolean>>) => BooleanFlag<void>;
package/lib/flags.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.help = exports.version = exports.url = exports.integer = exports.boolean = exports.string = exports.enum = exports.option = exports.build = void 0;
3
+ exports.help = exports.version = exports.file = exports.directory = exports.url = exports.integer = exports.boolean = exports.string = exports.enum = exports.option = exports.build = void 0;
4
4
  const Parser = require("./parser");
5
5
  function build(defaults) {
6
6
  return Parser.flags.build(defaults);
@@ -28,6 +28,8 @@ var parser_1 = require("./parser");
28
28
  Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return parser_1.boolean; } });
29
29
  Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return parser_1.integer; } });
30
30
  Object.defineProperty(exports, "url", { enumerable: true, get: function () { return parser_1.url; } });
31
+ Object.defineProperty(exports, "directory", { enumerable: true, get: function () { return parser_1.directory; } });
32
+ Object.defineProperty(exports, "file", { enumerable: true, get: function () { return parser_1.file; } });
31
33
  const version = (opts = {}) => {
32
34
  return Parser.flags.boolean({
33
35
  description: 'Show CLI version.',
@@ -6,7 +6,7 @@ export { HelpOptions } from './help';
6
6
  export { Hook, Hooks } from './hooks';
7
7
  export { Manifest } from './manifest';
8
8
  export { S3Manifest } from './s3-manifest';
9
- export { ParserArg, Arg, ParseFn, ParserOutput, ParserInput, ArgToken, OptionalArg, FlagOutput, OutputArgs, OutputFlags, FlagUsageOptions, CLIParseErrorOptions, ArgInput, RequiredArg, Metadata, ParsingToken, FlagToken, List, ListItem, BooleanFlag, Flag, FlagBase, OptionFlag, Input, EnumFlagOptions, DefaultContext, Default, Definition, CompletableOptionFlag, Completion, CompletionContext, FlagInput, CompletableFlag, } from './parser';
9
+ export { ParserArg, Arg, ParseFn, ParserOutput, ParserInput, ArgToken, OptionalArg, FlagOutput, OutputArgs, OutputFlags, FlagUsageOptions, CLIParseErrorOptions, ArgInput, RequiredArg, Metadata, ParsingToken, FlagToken, List, ListItem, BooleanFlag, Flag, FlagBase, OptionFlag, Input, EnumFlagOptions, DefaultContext, Default, Definition, CompletableOptionFlag, Completion, CompletionContext, FlagInput, CompletableFlag, OptionFlagProps, } from './parser';
10
10
  export { PJSON } from './pjson';
11
11
  export { Plugin, PluginOptions, Options } from './plugin';
12
12
  export { Topic } from './topic';
@@ -7,6 +7,12 @@ export declare function build<T>(defaults: {
7
7
  export declare function build(defaults: Partial<OptionFlag<string>>): Definition<string>;
8
8
  export declare function boolean<T = boolean>(options?: Partial<BooleanFlag<T>>): BooleanFlag<T>;
9
9
  export declare const integer: Definition<number>;
10
+ export declare const directory: (opts?: {
11
+ exists?: boolean;
12
+ } & Partial<OptionFlag<string>>) => OptionFlag<string | undefined>;
13
+ export declare const file: (opts?: {
14
+ exists?: boolean;
15
+ } & Partial<OptionFlag<string>>) => OptionFlag<string | undefined>;
10
16
  /**
11
17
  * Initializes a string as a URL. Throws an error
12
18
  * if the string is not a valid URL.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  // tslint:disable interface-over-type-literal
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.defaultFlags = exports.string = exports.option = exports.url = exports.integer = exports.boolean = exports.build = void 0;
4
+ exports.defaultFlags = exports.string = exports.option = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.build = void 0;
5
5
  const url_1 = require("url");
6
+ const fs = require("fs");
6
7
  function build(defaults) {
7
8
  return (options = {}) => {
8
9
  return {
@@ -32,6 +33,20 @@ exports.integer = build({
32
33
  return Number.parseInt(input, 10);
33
34
  },
34
35
  });
36
+ const directory = (opts = {}) => {
37
+ return build({
38
+ ...opts,
39
+ parse: async (input) => opts.exists ? dirExists(input) : input,
40
+ })();
41
+ };
42
+ exports.directory = directory;
43
+ const file = (opts = {}) => {
44
+ return build({
45
+ ...opts,
46
+ parse: async (input) => opts.exists ? fileExists(input) : input,
47
+ })();
48
+ };
49
+ exports.file = file;
35
50
  /**
36
51
  * Initializes a string as a URL. Throws an error
37
52
  * if the string is not a valid URL.
@@ -55,3 +70,21 @@ exports.string = stringFlag;
55
70
  exports.defaultFlags = {
56
71
  color: boolean({ allowNo: true }),
57
72
  };
73
+ const dirExists = async (input) => {
74
+ if (!fs.existsSync(input)) {
75
+ throw new Error(`No directory found at ${input}`);
76
+ }
77
+ if (!(await fs.promises.stat(input)).isDirectory()) {
78
+ throw new Error(`${input} exists but is not a directory`);
79
+ }
80
+ return input;
81
+ };
82
+ const fileExists = async (input) => {
83
+ if (!fs.existsSync(input)) {
84
+ throw new Error(`No file found at ${input}`);
85
+ }
86
+ if (!(await fs.promises.stat(input)).isFile()) {
87
+ throw new Error(`${input} exists but is not a file`);
88
+ }
89
+ return input;
90
+ };
@@ -8,5 +8,9 @@ export { flagUsages } from './help';
8
8
  export declare function parse<TFlags, TArgs extends {
9
9
  [name: string]: string;
10
10
  }>(argv: string[], options: Input<TFlags>): Promise<ParserOutput<TFlags, TArgs>>;
11
- declare const boolean: typeof flags.boolean, integer: import("../interfaces").Definition<number>, url: import("../interfaces").Definition<import("url").URL>;
12
- export { boolean, integer, url };
11
+ declare const boolean: typeof flags.boolean, integer: import("../interfaces").Definition<number>, url: import("../interfaces").Definition<import("url").URL>, directory: (opts?: {
12
+ exists?: boolean | undefined;
13
+ } & Partial<import("../interfaces").OptionFlag<string>>) => import("../interfaces").OptionFlag<string | undefined>, file: (opts?: {
14
+ exists?: boolean | undefined;
15
+ } & Partial<import("../interfaces").OptionFlag<string>>) => import("../interfaces").OptionFlag<string | undefined>;
16
+ export { boolean, integer, url, directory, file };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // tslint:disable interface-over-type-literal
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.url = exports.integer = exports.boolean = exports.parse = exports.flagUsages = exports.flags = exports.args = void 0;
4
+ exports.file = exports.directory = exports.url = exports.integer = exports.boolean = exports.parse = exports.flagUsages = exports.flags = exports.args = void 0;
5
5
  const args = require("./args");
6
6
  exports.args = args;
7
7
  const deps_1 = require("./deps");
@@ -32,7 +32,9 @@ async function parse(argv, options) {
32
32
  return output;
33
33
  }
34
34
  exports.parse = parse;
35
- const { boolean, integer, url } = flags;
35
+ const { boolean, integer, url, directory, file } = flags;
36
36
  exports.boolean = boolean;
37
37
  exports.integer = integer;
38
38
  exports.url = url;
39
+ exports.directory = directory;
40
+ exports.file = file;
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.4.0",
4
+ "version": "1.5.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {