@fougere/oclif 0.12.1-alpha.0 → 0.12.4-alpha.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/bridge.d.ts +9 -0
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js +36 -14
- package/dist/bridge.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/bridge.ts +48 -14
- package/src/index.ts +9 -6
package/dist/bridge.d.ts
CHANGED
|
@@ -24,4 +24,13 @@ export declare function paramsToShape(params: readonly {
|
|
|
24
24
|
}[]): Shape;
|
|
25
25
|
/** One operation's input, as the pair oclif parses a command line into. */
|
|
26
26
|
export declare function inputToShape(fields: Fields): Shape;
|
|
27
|
+
/** The dual of `inputToShape`: what oclif parsed, handed back as the entity declares it. */
|
|
28
|
+
export declare function inputOf(fields: Fields, parsed: Record<string, unknown>): Record<string, unknown>;
|
|
29
|
+
/** The dual of `paramsToShape`: an operation's bare parameters, under their own names. */
|
|
30
|
+
export declare function paramsOf(params: readonly {
|
|
31
|
+
name: string;
|
|
32
|
+
type?: {
|
|
33
|
+
name?: string;
|
|
34
|
+
};
|
|
35
|
+
}[], parsed: Record<string, unknown>): Record<string, unknown>;
|
|
27
36
|
//# sourceMappingURL=bridge.d.ts.map
|
package/dist/bridge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAuC,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEnF,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAclE,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;CAClB;AAcD,w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EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
|
package/dist/bridge.js
CHANGED
|
@@ -16,7 +16,7 @@ function suppliedIn(fields) {
|
|
|
16
16
|
const written = Visibility.of(fields).input;
|
|
17
17
|
if (Object.keys(written).length > 0)
|
|
18
18
|
return written;
|
|
19
|
-
return Object.fromEntries(Object.entries(fields).filter(([, field]) => Role.of(field).isPrimary));
|
|
19
|
+
return Object.fromEntries(Object.entries(fields).filter(([, field]) => Role.of(field).isPrimary()));
|
|
20
20
|
}
|
|
21
21
|
const kebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
22
22
|
/**
|
|
@@ -47,9 +47,9 @@ export function paramsToShape(params) {
|
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
49
|
const at = kebab(param.name);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// A flag is text, and `paramsOf` reads it back: `Flags.integer` turned `9.5` away for a
|
|
51
|
+
// parameter declared `number`, which admits it.
|
|
52
|
+
flags[at] = type === 'boolean' ? Flags.boolean({}) : Flags.string({ required });
|
|
53
53
|
}
|
|
54
54
|
return { args: args, flags: flags };
|
|
55
55
|
}
|
|
@@ -59,14 +59,14 @@ export function inputToShape(fields) {
|
|
|
59
59
|
const flags = {};
|
|
60
60
|
let positional = false;
|
|
61
61
|
for (const [key, field] of Object.entries(suppliedIn(fields))) {
|
|
62
|
-
if (Role.of(field).isRelation)
|
|
62
|
+
if (Role.of(field).isRelation())
|
|
63
63
|
continue;
|
|
64
64
|
const { base: shape, nullable } = Shapes.of(field.shape);
|
|
65
65
|
const type = Shapes.typeOf(field.shape);
|
|
66
|
-
const description = field.
|
|
67
|
-
const required = Role.of(field).isPrimary || (!nullable && Lifecycle.of(field).requiredAtCreate);
|
|
68
|
-
const options = shape
|
|
69
|
-
? shape.enum.filter((value) =>
|
|
66
|
+
const description = field.shape?.description;
|
|
67
|
+
const required = Role.of(field).isPrimary() || (!nullable && Lifecycle.of(field).requiredAtCreate());
|
|
68
|
+
const options = shape && 'enum' in shape && shape.enum?.length
|
|
69
|
+
? shape.enum.filter((value) => value !== null).map(String)
|
|
70
70
|
: undefined;
|
|
71
71
|
// The first required plain string becomes positional, the rule `fougere explain --root`
|
|
72
72
|
// and `fougere graph <root>` already follow. A closed set stays a flag: its legal values
|
|
@@ -78,12 +78,34 @@ export function inputToShape(fields) {
|
|
|
78
78
|
}
|
|
79
79
|
const at = kebab(key);
|
|
80
80
|
const fallback = Lifecycle.of(field).literal?.value;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
// A flag is text; `inputOf` reads it back as the shape declares it, so a number needs no
|
|
82
|
+
// flag of its own — `Flags.integer` refused `9.5` for a `number()` and passed an integer on
|
|
83
|
+
// as a string.
|
|
84
|
+
flags[at] = type === 'boolean'
|
|
85
|
+
? Flags.boolean({ description, default: fallback })
|
|
86
|
+
: Flags.string({ description, options, required, default: fallback === undefined ? undefined : String(fallback) });
|
|
86
87
|
}
|
|
87
88
|
return { args: args, flags: flags };
|
|
88
89
|
}
|
|
90
|
+
/** What oclif parsed, under the names the operation declared: a flag is kebab, a field is not. */
|
|
91
|
+
function renamed(parsed, names) {
|
|
92
|
+
const byFlag = new Map(names.map((name) => [kebab(name), name]));
|
|
93
|
+
return Object.fromEntries(Object.entries(parsed).map(([at, value]) => [byFlag.get(at) ?? at, value]));
|
|
94
|
+
}
|
|
95
|
+
/** The dual of `inputToShape`: what oclif parsed, handed back as the entity declares it. */
|
|
96
|
+
export function inputOf(fields, parsed) {
|
|
97
|
+
return Object.fromEntries(Object.entries(renamed(parsed, Object.keys(fields)))
|
|
98
|
+
.map(([key, value]) => [key, Shapes.fromText(fields[key]?.shape, value)]));
|
|
99
|
+
}
|
|
100
|
+
/** The dual of `paramsToShape`: an operation's bare parameters, under their own names. */
|
|
101
|
+
export function paramsOf(params, parsed) {
|
|
102
|
+
const declared = new Map(params.map((param) => [param.name, param.type?.name]));
|
|
103
|
+
return Object.fromEntries(Object.entries(renamed(parsed, params.map((param) => param.name)))
|
|
104
|
+
// A bare parameter states a TypeScript type, not a shape — `number` is the one that
|
|
105
|
+
// stands for a value the terminal can only hand over as text.
|
|
106
|
+
.map(([name, value]) => [
|
|
107
|
+
name,
|
|
108
|
+
declared.get(name) === 'number' ? Shapes.fromText({ type: 'number' }, value) : value,
|
|
109
|
+
]));
|
|
110
|
+
}
|
|
89
111
|
//# sourceMappingURL=bridge.js.map
|
package/dist/bridge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAG1C,iGAAiG;AACjG,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC;IAC5C,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAEpD,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAe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AC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAEhF,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,oFAAoF;QACpF,8DAA8D;SAC7D,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACtB,IAAI;QACJ,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;KACrF,CAAC,CACL,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAmC,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,GAAG,EAAmB,MAAM,eAAe,CAAC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAmC,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,GAAG,EAAmB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAkD,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzF;;;;;GAKG;AACH,UAAU,QAAQ;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,IAAI,OAAO,CAAC,OAAO,OAAO,CAAC,CAAC;CACjC;AAgCD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,EAAE,CA0C/C;AAED;;;;;;;GAOG;AACH,wBAAsB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,MAAM,EAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAgC3F"}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* the topics that make this worth its weight.
|
|
13
13
|
*/
|
|
14
14
|
import { Command, Config, handle, run as runOclif } from '@oclif/core';
|
|
15
|
-
import { inputToShape, paramsToShape } from './bridge.js';
|
|
15
|
+
import { inputOf, inputToShape, paramsOf, paramsToShape } from './bridge.js';
|
|
16
16
|
const kebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`).replace(/^-/, '');
|
|
17
17
|
/** Each entry carries the key it is filed under — what a class-on-disk gets for free. */
|
|
18
18
|
function named(entries) {
|
|
@@ -27,7 +27,9 @@ function commandFor(id, call, shape, describe) {
|
|
|
27
27
|
static enableJsonFlag = true;
|
|
28
28
|
async run() {
|
|
29
29
|
const { args, flags } = await this.parse(Built);
|
|
30
|
-
|
|
30
|
+
// `--json` is oclif's own flag (`enableJsonFlag`), not a field: it reached the judge as one.
|
|
31
|
+
const own = Object.fromEntries(Object.entries(flags).filter(([at]) => at in shape.flags));
|
|
32
|
+
return this.logJson(await call({ ...args, ...own }));
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
Built.id = id;
|
|
@@ -49,10 +51,9 @@ export function commandsOf(app) {
|
|
|
49
51
|
// A view when the op names one, its signature otherwise: `findById(id: string)` takes
|
|
50
52
|
// a bare parameter, and an entity-shaped derivation would offer nothing at all for it.
|
|
51
53
|
const fields = contract.input?.getFields?.();
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const Built = commandFor(`${handler.address}:${kebab(name)}`, (parsed) => facade[name](fields ? { input: parsed } : { params: parsed }), shape, contract.description);
|
|
54
|
+
const params = contract.signature?.params ?? [];
|
|
55
|
+
const shape = fields ? inputToShape(fields) : paramsToShape(params);
|
|
56
|
+
const Built = commandFor(`${handler.address}:${kebab(name)}`, (parsed) => facade[name](fields ? { input: inputOf(fields, parsed) } : { params: paramsOf(params, parsed) }), shape, contract.description);
|
|
56
57
|
loadables.push({
|
|
57
58
|
id: Built.id,
|
|
58
59
|
aliases: [],
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAc,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAc,MAAM,aAAa,CAAC;AAqBzF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAA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G,EAAE;YACnB,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,OAAO;YAChB,KAAK,EAAE,EAAE;YACT,WAAW,EAAE,KAAK;YAClB,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,SAAS;YACtB,IAAI,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;YACpB,WAAW,EAAE,KAAK,EAAE,EAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE;SACjF,CAAC,CAAC,CAAC;IAEJ,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/oclif",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4-alpha.0",
|
|
4
4
|
"description": "A frond's operations, as a terminal: topics, flags and help derived from what it declares.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"template"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@fougere/core": "0.12.
|
|
32
|
-
"@fougere/schema": "0.12.
|
|
31
|
+
"@fougere/core": "0.12.4-alpha.0",
|
|
32
|
+
"@fougere/schema": "0.12.4-alpha.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@oclif/core": "^5.0.0",
|
package/src/bridge.ts
CHANGED
|
@@ -19,7 +19,7 @@ function suppliedIn(fields: Fields): Fields {
|
|
|
19
19
|
if (Object.keys(written).length > 0) return written;
|
|
20
20
|
|
|
21
21
|
return Object.fromEntries(
|
|
22
|
-
Object.entries(fields).filter(([, field]) => Role.of(field).isPrimary),
|
|
22
|
+
Object.entries(fields).filter(([, field]) => Role.of(field).isPrimary()),
|
|
23
23
|
) as Fields;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -60,9 +60,9 @@ export function paramsToShape(params: readonly { name: string; type: { name?: st
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const at = kebab(param.name);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
// A flag is text, and `paramsOf` reads it back: `Flags.integer` turned `9.5` away for a
|
|
64
|
+
// parameter declared `number`, which admits it.
|
|
65
|
+
flags[at] = type === 'boolean' ? Flags.boolean({}) : Flags.string({ required });
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
return { args: args as ArgInput, flags: flags as FlagInput };
|
|
@@ -75,14 +75,14 @@ export function inputToShape(fields: Fields): Shape {
|
|
|
75
75
|
let positional = false;
|
|
76
76
|
|
|
77
77
|
for (const [key, field] of Object.entries(suppliedIn(fields))) {
|
|
78
|
-
if (Role.of(field).isRelation) continue;
|
|
78
|
+
if (Role.of(field).isRelation()) continue;
|
|
79
79
|
|
|
80
80
|
const { base: shape, nullable } = Shapes.of(field.shape);
|
|
81
81
|
const type = Shapes.typeOf(field.shape);
|
|
82
|
-
const description = field.
|
|
83
|
-
const required = Role.of(field).isPrimary || (!nullable && Lifecycle.of(field).requiredAtCreate);
|
|
84
|
-
const options = shape
|
|
85
|
-
? shape.enum.filter((value)
|
|
82
|
+
const description = field.shape?.description;
|
|
83
|
+
const required = Role.of(field).isPrimary() || (!nullable && Lifecycle.of(field).requiredAtCreate());
|
|
84
|
+
const options = shape && 'enum' in shape && shape.enum?.length
|
|
85
|
+
? shape.enum.filter((value) => value !== null).map(String)
|
|
86
86
|
: undefined;
|
|
87
87
|
|
|
88
88
|
// The first required plain string becomes positional, the rule `fougere explain --root`
|
|
@@ -96,12 +96,46 @@ export function inputToShape(fields: Fields): Shape {
|
|
|
96
96
|
|
|
97
97
|
const at = kebab(key);
|
|
98
98
|
const fallback = Lifecycle.of(field).literal?.value;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
// A flag is text; `inputOf` reads it back as the shape declares it, so a number needs no
|
|
100
|
+
// flag of its own — `Flags.integer` refused `9.5` for a `number()` and passed an integer on
|
|
101
|
+
// as a string.
|
|
102
|
+
flags[at] = type === 'boolean'
|
|
103
|
+
? Flags.boolean({ description, default: fallback as boolean | undefined })
|
|
104
|
+
: Flags.string({ description, options, required, default: fallback === undefined ? undefined : String(fallback) });
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
return { args: args as ArgInput, flags: flags as FlagInput };
|
|
107
108
|
}
|
|
109
|
+
|
|
110
|
+
/** What oclif parsed, under the names the operation declared: a flag is kebab, a field is not. */
|
|
111
|
+
function renamed(parsed: Record<string, unknown>, names: readonly string[]): Record<string, unknown> {
|
|
112
|
+
const byFlag = new Map(names.map((name) => [kebab(name), name]));
|
|
113
|
+
|
|
114
|
+
return Object.fromEntries(Object.entries(parsed).map(([at, value]) => [byFlag.get(at) ?? at, value]));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The dual of `inputToShape`: what oclif parsed, handed back as the entity declares it. */
|
|
118
|
+
export function inputOf(fields: Fields, parsed: Record<string, unknown>): Record<string, unknown> {
|
|
119
|
+
return Object.fromEntries(
|
|
120
|
+
Object.entries(renamed(parsed, Object.keys(fields)))
|
|
121
|
+
.map(([key, value]) => [key, Shapes.fromText(fields[key]?.shape, value)]),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The dual of `paramsToShape`: an operation's bare parameters, under their own names. */
|
|
126
|
+
export function paramsOf(
|
|
127
|
+
params: readonly { name: string; type?: { name?: string } }[],
|
|
128
|
+
parsed: Record<string, unknown>,
|
|
129
|
+
): Record<string, unknown> {
|
|
130
|
+
const declared = new Map(params.map((param) => [param.name, param.type?.name]));
|
|
131
|
+
|
|
132
|
+
return Object.fromEntries(
|
|
133
|
+
Object.entries(renamed(parsed, params.map((param) => param.name)))
|
|
134
|
+
// A bare parameter states a TypeScript type, not a shape — `number` is the one that
|
|
135
|
+
// stands for a value the terminal can only hand over as text.
|
|
136
|
+
.map(([name, value]) => [
|
|
137
|
+
name,
|
|
138
|
+
declared.get(name) === 'number' ? Shapes.fromText({ type: 'number' }, value) : value,
|
|
139
|
+
]),
|
|
140
|
+
);
|
|
141
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { Command, Config, handle, run as runOclif } from '@oclif/core';
|
|
15
15
|
import type { App, FrondDescriptor } from '@fougere/core';
|
|
16
|
-
import { inputToShape, paramsToShape, type Shape } from './bridge.js';
|
|
16
|
+
import { inputOf, inputToShape, paramsOf, paramsToShape, type Shape } from './bridge.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* What oclif runs: a command's shape in its cache, plus the way to reach the class.
|
|
@@ -53,8 +53,10 @@ function commandFor(id: string, call: (input: Record<string, unknown>) => Promis
|
|
|
53
53
|
|
|
54
54
|
async run(): Promise<unknown> {
|
|
55
55
|
const { args, flags } = await this.parse(Built);
|
|
56
|
+
// `--json` is oclif's own flag (`enableJsonFlag`), not a field: it reached the judge as one.
|
|
57
|
+
const own = Object.fromEntries(Object.entries(flags).filter(([at]) => at in shape.flags));
|
|
56
58
|
|
|
57
|
-
return this.logJson(await call({ ...args, ...
|
|
59
|
+
return this.logJson(await call({ ...args, ...own }));
|
|
58
60
|
}
|
|
59
61
|
};
|
|
60
62
|
Built.id = id;
|
|
@@ -80,12 +82,13 @@ export function commandsOf(app: App): Loadable[] {
|
|
|
80
82
|
// A view when the op names one, its signature otherwise: `findById(id: string)` takes
|
|
81
83
|
// a bare parameter, and an entity-shaped derivation would offer nothing at all for it.
|
|
82
84
|
const fields = contract.input?.getFields?.();
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
: paramsToShape(contract.signature?.params ?? []);
|
|
85
|
+
const params = contract.signature?.params ?? [];
|
|
86
|
+
const shape = fields ? inputToShape(fields) : paramsToShape(params);
|
|
86
87
|
const Built = commandFor(
|
|
87
88
|
`${handler.address}:${kebab(name)}`,
|
|
88
|
-
(parsed) => facade[name]!(
|
|
89
|
+
(parsed) => facade[name]!(
|
|
90
|
+
fields ? { input: inputOf(fields, parsed) } : { params: paramsOf(params, parsed) },
|
|
91
|
+
),
|
|
89
92
|
shape,
|
|
90
93
|
contract.description,
|
|
91
94
|
);
|