breadc 0.6.1 → 0.6.4

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.cjs CHANGED
@@ -174,6 +174,8 @@ const _Command = class {
174
174
  const options = argv;
175
175
  delete options["_"];
176
176
  for (const [name, rawOption] of fullOptions) {
177
+ if (rawOption.type === "boolean")
178
+ continue;
177
179
  if (rawOption.required) {
178
180
  if (options[name] === void 0) {
179
181
  options[name] = false;
@@ -187,13 +189,12 @@ const _Command = class {
187
189
  options[name] = void 0;
188
190
  }
189
191
  }
190
- if (rawOption.default !== void 0) {
191
- if (options[name] === void 0 || options[name] === false) {
192
- options[name] = rawOption.default;
193
- }
194
- }
195
192
  if (rawOption.construct !== void 0) {
196
193
  options[name] = rawOption.construct(options[name]);
194
+ } else if (rawOption.default !== void 0) {
195
+ if (options[name] === void 0 || options[name] === false || options[name] === "") {
196
+ options[name] = rawOption.default;
197
+ }
197
198
  }
198
199
  }
199
200
  for (const key of Object.keys(options)) {
@@ -418,9 +419,14 @@ class Breadc {
418
419
  }
419
420
  return map;
420
421
  }, { h: "help", v: "version" });
422
+ const defaultValue = allowOptions.filter((o) => o.type === "boolean" && o.default !== void 0 && o.default !== null && typeof o.default === "boolean").reduce((map, o) => {
423
+ map[o.name] = o.default;
424
+ return map;
425
+ }, {});
421
426
  const argv = minimist__default(args, {
422
427
  string: allowOptions.filter((o) => o.type === "string").map((o) => o.name),
423
428
  boolean: allowOptions.filter((o) => o.type === "boolean").map((o) => o.name).concat(["help", "version"]),
429
+ default: defaultValue,
424
430
  alias,
425
431
  "--": true,
426
432
  unknown: (t) => {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import kolorist from 'kolorist';
2
2
  import { ParsedArgs } from 'minimist';
3
3
 
4
- interface OptionConfig<F extends string, T = never> {
4
+ interface OptionConfig<F extends string, T = never, O = ExtractOptionType<F>> {
5
5
  /**
6
6
  * Option description
7
7
  */
@@ -9,7 +9,7 @@ interface OptionConfig<F extends string, T = never> {
9
9
  /**
10
10
  * Option string default value
11
11
  */
12
- default?: string;
12
+ default?: O extends boolean ? boolean : string;
13
13
  /**
14
14
  * Transform option text
15
15
  */
@@ -24,17 +24,17 @@ interface OptionConfig<F extends string, T = never> {
24
24
  * + --option <arg>
25
25
  * + --option [arg]
26
26
  */
27
- declare class Option<T extends string = string, F = string> {
27
+ declare class Option<F extends string = string, T = string, O = ExtractOptionType<F>> {
28
28
  private static OptionRE;
29
29
  readonly name: string;
30
30
  readonly shortcut?: string;
31
- readonly default?: string;
31
+ readonly default?: O extends boolean ? boolean : string;
32
32
  readonly format: string;
33
33
  readonly description: string;
34
34
  readonly type: 'string' | 'boolean';
35
35
  readonly required: boolean;
36
- readonly construct?: (rawText: ExtractOptionType<T>) => F;
37
- constructor(format: T, config?: OptionConfig<T, F>);
36
+ readonly construct?: (rawText: ExtractOptionType<F>) => T;
37
+ constructor(format: F, config?: OptionConfig<F, T, O>);
38
38
  }
39
39
 
40
40
  interface CommandConfig {
@@ -137,4 +137,4 @@ declare class Breadc<GlobalOption extends object = {}> {
137
137
 
138
138
  declare function breadc<T extends object = {}>(name: string, option?: AppOption): Breadc<T>;
139
139
 
140
- export { breadc as default };
140
+ export { Breadc, Command, CommandConfig, Option, OptionConfig, breadc as default };
package/dist/index.mjs CHANGED
@@ -167,6 +167,8 @@ const _Command = class {
167
167
  const options = argv;
168
168
  delete options["_"];
169
169
  for (const [name, rawOption] of fullOptions) {
170
+ if (rawOption.type === "boolean")
171
+ continue;
170
172
  if (rawOption.required) {
171
173
  if (options[name] === void 0) {
172
174
  options[name] = false;
@@ -180,13 +182,12 @@ const _Command = class {
180
182
  options[name] = void 0;
181
183
  }
182
184
  }
183
- if (rawOption.default !== void 0) {
184
- if (options[name] === void 0 || options[name] === false) {
185
- options[name] = rawOption.default;
186
- }
187
- }
188
185
  if (rawOption.construct !== void 0) {
189
186
  options[name] = rawOption.construct(options[name]);
187
+ } else if (rawOption.default !== void 0) {
188
+ if (options[name] === void 0 || options[name] === false || options[name] === "") {
189
+ options[name] = rawOption.default;
190
+ }
190
191
  }
191
192
  }
192
193
  for (const key of Object.keys(options)) {
@@ -411,9 +412,14 @@ class Breadc {
411
412
  }
412
413
  return map;
413
414
  }, { h: "help", v: "version" });
415
+ const defaultValue = allowOptions.filter((o) => o.type === "boolean" && o.default !== void 0 && o.default !== null && typeof o.default === "boolean").reduce((map, o) => {
416
+ map[o.name] = o.default;
417
+ return map;
418
+ }, {});
414
419
  const argv = minimist(args, {
415
420
  string: allowOptions.filter((o) => o.type === "string").map((o) => o.name),
416
421
  boolean: allowOptions.filter((o) => o.type === "boolean").map((o) => o.name).concat(["help", "version"]),
422
+ default: defaultValue,
417
423
  alias,
418
424
  "--": true,
419
425
  unknown: (t) => {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "breadc",
3
- "version": "0.6.1",
3
+ "version": "0.6.4",
4
4
  "description": "Yet another Command Line Application Framework with fully strong TypeScript support",
5
5
  "keywords": [
6
+ "breadc",
6
7
  "cli",
7
8
  "framework",
8
9
  "command-line",
@@ -40,20 +41,21 @@
40
41
  "devDependencies": {
41
42
  "@types/minimist": "^1.2.2",
42
43
  "@types/node": "^18.0.0",
43
- "bumpp": "^8.2.1",
44
44
  "prettier": "^2.7.1",
45
- "typescript": "^4.7.4",
46
- "unbuild": "^0.7.6",
47
- "vite": "^3.0.4",
48
- "vitest": "^0.19.1"
45
+ "typescript": "^4.8.2",
46
+ "unbuild": "^0.8.9",
47
+ "vite": "^3.0.9",
48
+ "vitest": "^0.22.1"
49
49
  },
50
50
  "packageManager": "pnpm@7.5.2",
51
51
  "scripts": {
52
52
  "build": "unbuild",
53
+ "build:all": "unbuild && pnpm -r build",
53
54
  "format": "prettier --write src/**/*.ts test/*.ts examples/*.ts",
54
- "release": "bumpp --commit --push --tag && pnpm publish",
55
+ "release": "bumpp package.json packages/*/package.json --commit --push --tag && pnpm publish && pnpm -r publish --access public",
55
56
  "test": "vitest",
56
57
  "typecheck": "tsc --noEmit",
57
- "preversion": "pnpm typecheck && pnpm build"
58
+ "typecheck:all": "tsc --noEmit && pnpm -r typecheck",
59
+ "preversion": "pnpm typecheck:all && pnpm build:all"
58
60
  }
59
61
  }