@turingcode/cli 0.2.8 → 0.2.9
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/cli/create-cli.js
CHANGED
|
@@ -9,8 +9,13 @@ const commands = [contract, table, tool];
|
|
|
9
9
|
*
|
|
10
10
|
* @param {string[]} args - Arguments after `turingcode`.
|
|
11
11
|
* @returns The parser; call `parseAsync()` to run it.
|
|
12
|
+
* @throws {Error} When the first word is not a command (yargs alone would print help and exit 0 for `<unknown> --help`).
|
|
12
13
|
*/
|
|
13
14
|
export function createCli(args) {
|
|
15
|
+
const first = args.find(a => !a.startsWith("-"));
|
|
16
|
+
if (first !== undefined && !commands.some(c => String(c.command).split(" ")[0] === first)) {
|
|
17
|
+
throw new Error(`Unknown command: ${first}`);
|
|
18
|
+
}
|
|
14
19
|
const cli = yargs(args)
|
|
15
20
|
.scriptName("turingcode")
|
|
16
21
|
.usage("Usage: $0 <command> [options]; $0 <command> --help for each command's usage")
|
|
@@ -14,7 +14,8 @@ field is optional. "(default)" marks the value used when a field is left out; ot
|
|
|
14
14
|
// but an empty cell forbidden is "required": true plus
|
|
15
15
|
// "match": {"$or": [{"$eq": "-"}, {"$every": {"$ref": "Tests.ID"}}]}
|
|
16
16
|
"allow_extra_tables": false, // (default) true: tables not declared here are allowed
|
|
17
|
-
"depends_on": { "customers": "customers.contract.json" }, //
|
|
17
|
+
"depends_on": { "customers": "customers.contract.json" }, // path absolute or relative to this contract;
|
|
18
|
+
// its tables passed with --dep customers=<file>, referenced as "customers:Table"
|
|
18
19
|
"tables": [{
|
|
19
20
|
"name": "Orders",
|
|
20
21
|
"required": true, // (default) the table must be in the document
|
|
@@ -90,9 +90,16 @@ export function validateContract(data, deps) {
|
|
|
90
90
|
return null; // the dependency's own problems are reported with it
|
|
91
91
|
}
|
|
92
92
|
const table = target.tables.find(t => t.name === name);
|
|
93
|
-
if (
|
|
93
|
+
if (table)
|
|
94
|
+
return table;
|
|
95
|
+
const owner = alias ? undefined : [...deps].find(([, dep]) => dep.contract?.tables.some(t => t.name === name))?.[0];
|
|
96
|
+
if (owner) {
|
|
97
|
+
report("CONTRACT.UNKNOWN_TABLE", `'${name}' is a table of dependency '${owner}': write ${owner}:${name}`, text, `${owner}:${name}`);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
94
100
|
report("CONTRACT.UNKNOWN_TABLE", `table '${name}' does not exist`, text, target.tables.map(t => t.name).join(", "));
|
|
95
|
-
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
96
103
|
};
|
|
97
104
|
/** A validation context for queries on `scope`'s rows; findings are placed at `at`, the field prefixed to messages when given. */
|
|
98
105
|
const context = (scope, at, prefix = "") => {
|
|
@@ -127,8 +127,8 @@ const call = {
|
|
|
127
127
|
.epilogue([
|
|
128
128
|
"Calls one tool of the Turing Code server. <name> comes from `tool list`, its arguments from",
|
|
129
129
|
"`tool describe <name>`.",
|
|
130
|
-
"--args is a JSON object
|
|
131
|
-
"
|
|
130
|
+
"--args is a JSON object, inline or a path to a .json file;",
|
|
131
|
+
"leave it out for a tool without arguments.",
|
|
132
132
|
"The tool's text result goes to stdout: redirect it (`> file`) to save a large result without",
|
|
133
133
|
"reading it. A tool error is printed to stderr.",
|
|
134
134
|
"Exit: 0 ok, 1 tool error or failed request.",
|
package/package.json
CHANGED