poad 2.45.0 → 2.46.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/global/cli.js +8 -8
- package/package.json +1 -1
- package/poad.js +6 -207
- package/project/cli.js +11 -11
- package/test/help.test.js +9 -2
- package/test/layout.test.js +176 -0
- package/utils/banner.js +131 -0
- package/utils/help-details.js +163 -0
- package/utils/help.js +35 -9
- package/utils/layout.js +99 -0
package/global/cli.js
CHANGED
|
@@ -7,19 +7,19 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
module.exports = {
|
|
10
|
-
install:
|
|
11
|
-
init:
|
|
12
|
-
create: 'Create a poad project
|
|
13
|
-
start: 'Start the project,
|
|
14
|
-
stop: 'Stop
|
|
15
|
-
run: 'Run an optional service next to the project
|
|
10
|
+
install: 'Install poad environment: pull the latest engine image',
|
|
11
|
+
init: 'Init a poad project in this folder: poad/ (config, secrets, migrations)',
|
|
12
|
+
create: 'Create a poad project: poad/ (backend), apps/<app> (first front-end), workspace, first git commit. Inside a project: add a front-end on its own port. Templates angular, next, nuxt, vanilla from npm, integrity checked',
|
|
13
|
+
start: 'Start the project: engine, migrations, services chosen with poad setup, then its state (secrets hidden)',
|
|
14
|
+
stop: 'Stop the project and its services, or one service (stop kc|valkey|runner)',
|
|
15
|
+
run: 'Run an optional service next to the project: keycloak|kc, valkey|redis, runner, --all',
|
|
16
16
|
ai: {
|
|
17
|
-
description: 'AI providers (engine 0.30.0
|
|
17
|
+
description: 'AI providers (engine 0.30.0+): keys of this machine and their copy into a project, then POST /ai/v1/chat',
|
|
18
18
|
login: 'Save the key of a provider for this machine: ai login anthropic|openai|mistral|gemini (hidden prompt, or stdin; never as an argument)',
|
|
19
19
|
logout: 'Forget the key of a provider on this machine: ai logout <provider>',
|
|
20
20
|
list: 'Providers and masked keys (last 4 characters); in a started project, what its engine has and the usage of the month',
|
|
21
21
|
use: 'Copy the machine key of a provider into the Credentials of the started project (vault) and use it for ai.<provider>: ai use <provider> [--yes]',
|
|
22
22
|
models: 'Model catalog (poadio/permalink, cached): default model, prices and status per provider: ai models [provider] [--refresh]',
|
|
23
23
|
},
|
|
24
|
-
clean: 'Remove what stopped poad projects left on this machine: orphan
|
|
24
|
+
clean: 'Remove what stopped poad projects left on this machine: orphan services, networks, unused engine images',
|
|
25
25
|
};
|
package/package.json
CHANGED
package/poad.js
CHANGED
|
@@ -116,34 +116,11 @@ const checkVersion = async () => {
|
|
|
116
116
|
});
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
console.log(' ');
|
|
125
|
-
console.log(
|
|
126
|
-
`${chalk.bold(' Usage :')} ${chalk.cyanBright(
|
|
127
|
-
POAD_COMMAND + ' <command>'
|
|
128
|
-
)} ${chalk.cyan('[<args>]')}`
|
|
129
|
-
);
|
|
130
|
-
console.log(' ');
|
|
131
|
-
console.log(chalk.bold(' Global commands :'));
|
|
132
|
-
console.log(' ');
|
|
133
|
-
display(POAD_GLOBAL_COMMANDS);
|
|
134
|
-
console.log(' ');
|
|
135
|
-
console.log(chalk.bold(' Project commands :'));
|
|
136
|
-
if (!POAD_PATH) {
|
|
137
|
-
console.log(`\n You are not in a project directory. `);
|
|
138
|
-
console.log(' ');
|
|
139
|
-
} else {
|
|
140
|
-
POAD_COMMANDS = loadPoadCommands(__dirname + '/project/cli.js');
|
|
141
|
-
console.log(' ');
|
|
142
|
-
display(POAD_COMMANDS);
|
|
143
|
-
console.log(' ');
|
|
144
|
-
}
|
|
145
|
-
console.log(' ');
|
|
146
|
-
});
|
|
119
|
+
// Liste des commandes (utils/banner.js) : vue courte pour « poad », liste
|
|
120
|
+
// complète pour « poad --help », « poad -h » et « poad help ».
|
|
121
|
+
const displayBanner = ({ full = false } = {}) => {
|
|
122
|
+
const lines = require('./utils/banner').render({ full, inProject: Boolean(POAD_PATH), version: package.version });
|
|
123
|
+
console.log(lines.join('\n'));
|
|
147
124
|
};
|
|
148
125
|
|
|
149
126
|
// Function to load project specific commands.
|
|
@@ -215,102 +192,6 @@ const loadPoadCommands = (path) => {
|
|
|
215
192
|
}
|
|
216
193
|
};
|
|
217
194
|
|
|
218
|
-
/**
|
|
219
|
-
* Displays the subcommands and their descriptions for a given command.
|
|
220
|
-
*
|
|
221
|
-
* @param {string} path - The path of the command.
|
|
222
|
-
* @param {string} title - The title of the command.
|
|
223
|
-
* @param {string} description - The description of the command.
|
|
224
|
-
* @param {object} cli - The command line interface object.
|
|
225
|
-
*/
|
|
226
|
-
const displaySub = (path, title, description, cli) => {
|
|
227
|
-
POAD_COMMANDS = {};
|
|
228
|
-
delete cli.description;
|
|
229
|
-
for (let el in cli) {
|
|
230
|
-
if (cli[el].description) {
|
|
231
|
-
let subs = [];
|
|
232
|
-
for (let s in cli[el]) {
|
|
233
|
-
if (s !== 'description') subs.push({ title: s });
|
|
234
|
-
}
|
|
235
|
-
let description = '';
|
|
236
|
-
if (hasLabel(cli[el].description)) {
|
|
237
|
-
description = cli[el].description.slice(cli[el].description.indexOf('] ') + 2);
|
|
238
|
-
let lbl = cli[el].description
|
|
239
|
-
.split('] ')[0]
|
|
240
|
-
.replace('[', '')
|
|
241
|
-
.replace(']', '');
|
|
242
|
-
POAD_COMMANDS[el] = {
|
|
243
|
-
info: {
|
|
244
|
-
title: el,
|
|
245
|
-
description: description,
|
|
246
|
-
label: lbl.toLowerCase(),
|
|
247
|
-
sub: subs,
|
|
248
|
-
},
|
|
249
|
-
};
|
|
250
|
-
} else {
|
|
251
|
-
description = cli[el].description;
|
|
252
|
-
POAD_COMMANDS[el] = {
|
|
253
|
-
info: {
|
|
254
|
-
title: el,
|
|
255
|
-
description: cli[el].description,
|
|
256
|
-
sub: subs,
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
let description = '';
|
|
262
|
-
if (hasLabel(cli[el])) {
|
|
263
|
-
description = cli[el].slice(cli[el].indexOf('] ') + 2);
|
|
264
|
-
let lbl = cli[el].split('] ')[0].replace('[', '').replace(']', '');
|
|
265
|
-
POAD_COMMANDS[el] = {
|
|
266
|
-
info: {
|
|
267
|
-
title: el,
|
|
268
|
-
description: description,
|
|
269
|
-
label: lbl.toLowerCase(),
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
} else {
|
|
273
|
-
POAD_COMMANDS[el] = {
|
|
274
|
-
info: {
|
|
275
|
-
title: el,
|
|
276
|
-
description: cli[el],
|
|
277
|
-
},
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
console.log(
|
|
284
|
-
`${chalk.bold(' Usage :')} ${chalk.cyanBright(
|
|
285
|
-
POAD_COMMAND + ' ' + args.join(' ')
|
|
286
|
-
)} ${chalk.cyan('[<args>]')}`
|
|
287
|
-
);
|
|
288
|
-
console.log(' ');
|
|
289
|
-
display(POAD_COMMANDS);
|
|
290
|
-
console.log(' ');
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
// Function to parse commands.
|
|
294
|
-
const parseCommand = (args) => {
|
|
295
|
-
const cli = require(__dirname + '/project/cli');
|
|
296
|
-
let cmd = cli;
|
|
297
|
-
let arguments = [];
|
|
298
|
-
let title = '';
|
|
299
|
-
let path = '';
|
|
300
|
-
for (let i = 0; i < args.length; i++) {
|
|
301
|
-
if (!cmd[args[i]]) arguments.push(args[i]);
|
|
302
|
-
else {
|
|
303
|
-
cmd = cmd[args[i]];
|
|
304
|
-
title = args[i];
|
|
305
|
-
path += ' ' + title;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (cmd.description) displaySub(path, title, cmd.description, cmd);
|
|
309
|
-
else {
|
|
310
|
-
ExecCommand(path.replace(/ /g, '/'), arguments);
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
|
|
314
195
|
/**
|
|
315
196
|
* Fonction qui vérifie si un chemin existe dans un objet donné
|
|
316
197
|
* @param {object} obj - L'objet dans lequel chercher
|
|
@@ -361,8 +242,6 @@ const parseCommandArgs = (commands, args) => {
|
|
|
361
242
|
// Function to process entered commands.
|
|
362
243
|
const processCommands = (args) => {
|
|
363
244
|
const command = args[0];
|
|
364
|
-
const maxWidth = 30;
|
|
365
|
-
const maxDescriptionLength = 50;
|
|
366
245
|
|
|
367
246
|
POAD_COMMANDS = loadPoadCommands(__dirname + '/project/cli.js');
|
|
368
247
|
|
|
@@ -389,86 +268,6 @@ const processCommands = (args) => {
|
|
|
389
268
|
}
|
|
390
269
|
};
|
|
391
270
|
|
|
392
|
-
// Function to format command labels with chalk for color coding.
|
|
393
|
-
const label = (o) => {
|
|
394
|
-
const caption = o.label;
|
|
395
|
-
|
|
396
|
-
if (caption === 'experimental') return chalk.red(' (' + caption + ')');
|
|
397
|
-
if (caption === 'alpha') return chalk.cyan(' (' + caption + ')');
|
|
398
|
-
if (caption === 'beta') return chalk.magenta(' (' + caption + ')');
|
|
399
|
-
if (caption === 'docker') return chalk.green(' (' + caption + ')');
|
|
400
|
-
if (caption === 'ai') return chalk.yellow(' (' + caption.toUpperCase() + ')');
|
|
401
|
-
return '';
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
// Function to execute commands.
|
|
405
|
-
const ExecCommand = (p, args) => {
|
|
406
|
-
console.log(p, args);
|
|
407
|
-
const unit = require(__dirname + p);
|
|
408
|
-
const params = {
|
|
409
|
-
dir: {
|
|
410
|
-
home: `${userHomeDir}/.cadriciel`,
|
|
411
|
-
cadriciel: path.normalize(CADRICIEL_PATH + '/..'),
|
|
412
|
-
root: path.normalize(CADRICIEL_PATH + '/../..'),
|
|
413
|
-
},
|
|
414
|
-
};
|
|
415
|
-
unit(args, params);
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
// Function to format command descriptions.
|
|
419
|
-
const formatDescription = (description, maxLength) => {
|
|
420
|
-
if (description.length <= maxLength) return description;
|
|
421
|
-
|
|
422
|
-
const breakPoint = description.lastIndexOf(' ', maxLength);
|
|
423
|
-
const firstPart = description.substring(0, breakPoint);
|
|
424
|
-
const secondPart = description.substring(breakPoint + 1).trim();
|
|
425
|
-
|
|
426
|
-
return firstPart + '\n ' + secondPart;
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
// Function to display commands.
|
|
430
|
-
const display = (commands) => {
|
|
431
|
-
const maxWidth = 30;
|
|
432
|
-
const maxDescriptionLength = 50;
|
|
433
|
-
|
|
434
|
-
for (let el in commands) {
|
|
435
|
-
let title = el;
|
|
436
|
-
if (commands[el].info.title != '---') {
|
|
437
|
-
if (commands[el].info) {
|
|
438
|
-
let description = commands[el].info.description;
|
|
439
|
-
if (commands[el].info.sub) {
|
|
440
|
-
title += ' <subcommand>';
|
|
441
|
-
const sc = [];
|
|
442
|
-
for (let i = 0; i < commands[el].info.sub.length; i++) {
|
|
443
|
-
sc.push(commands[el].info.sub[i].title);
|
|
444
|
-
}
|
|
445
|
-
description += chalk.white(' ');
|
|
446
|
-
description += chalk.grey(' (subcommands: ');
|
|
447
|
-
description += chalk.cyan(sc.join(', '));
|
|
448
|
-
description += chalk.grey(')');
|
|
449
|
-
}
|
|
450
|
-
const dots = '.'.repeat(maxWidth - title.length);
|
|
451
|
-
|
|
452
|
-
const formattedDesc = formatDescription(
|
|
453
|
-
description,
|
|
454
|
-
maxDescriptionLength
|
|
455
|
-
);
|
|
456
|
-
|
|
457
|
-
console.log(
|
|
458
|
-
' ' +
|
|
459
|
-
chalk.cyanBright(title) +
|
|
460
|
-
' ' +
|
|
461
|
-
chalk.grey(dots) +
|
|
462
|
-
' ' +
|
|
463
|
-
label(commands[el].info) +
|
|
464
|
-
' ' +
|
|
465
|
-
chalk.white(formattedDesc)
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
|
|
472
271
|
// True when version `a` is strictly newer than `b` (major.minor.patch).
|
|
473
272
|
const isNewerVersion = (a, b) => {
|
|
474
273
|
const pa = String(a).split('.').map(Number);
|
|
@@ -493,7 +292,7 @@ const helpGuard = () => {
|
|
|
493
292
|
POAD_GLOBAL_COMMANDS = loadPoadCommands(__dirname + '/global/cli.js');
|
|
494
293
|
const words = argv.filter((a) => !help.HELP_FLAGS.includes(a));
|
|
495
294
|
if (!words.length) {
|
|
496
|
-
displayBanner();
|
|
295
|
+
displayBanner({ full: true });
|
|
497
296
|
return true;
|
|
498
297
|
}
|
|
499
298
|
if (!help.printHelp(argv)) {
|
package/project/cli.js
CHANGED
|
@@ -7,33 +7,33 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
module.exports = {
|
|
10
|
-
info: '
|
|
10
|
+
info: 'URLs, keys, migrations and services of the running project (secrets hidden)',
|
|
11
11
|
client: {
|
|
12
|
-
description: 'Front-end of the project: client init
|
|
12
|
+
description: 'Front-end of the project: client init, kept as an alias of poad create <app> --template t',
|
|
13
13
|
init: 'Alias of poad create <app>: adds a front-end (angular | next | nuxt | vanilla, dir=<folder>, from=<local template>, --yes)',
|
|
14
14
|
},
|
|
15
15
|
console: 'Open the administration console of the running project in the browser (engine 0.11.0+, no password, this machine only)',
|
|
16
16
|
kc: 'Keycloak test set of the project (poad/keycloak.json; kc export saves the running realm)',
|
|
17
|
-
setup: 'Choose what "poad start" starts: e-mails (Mailpit/SMTP), Keycloak, Valkey, migrations
|
|
17
|
+
setup: 'Choose what "poad start" starts: e-mails (Mailpit/SMTP), Keycloak, Valkey, migrations',
|
|
18
18
|
db: {
|
|
19
|
-
description: 'Local database
|
|
19
|
+
description: 'Local database of the project',
|
|
20
20
|
reset: 'Erase the database and storage files, restart, apply migrations then poad/seed.sql (--yes outside a terminal)',
|
|
21
21
|
seed: 'Apply poad/seed.sql (development data)',
|
|
22
22
|
diff: 'Structure changes made outside the migrations (console SQL, psql…): diff to list them, diff <name> to write them as a migration, diff --discard to forget them',
|
|
23
23
|
},
|
|
24
|
-
upgrade: 'Upgrade the engine of the project (
|
|
25
|
-
logs: 'Unified logs of the project
|
|
24
|
+
upgrade: 'Upgrade the engine of the project (backup first), or roll back to a backup',
|
|
25
|
+
logs: 'Unified logs of the project, every service, with filters (level, since, request, flow, function, AI…) and -f',
|
|
26
26
|
gen: {
|
|
27
|
-
description: 'Generators
|
|
27
|
+
description: 'Generators of TypeScript types: the database, the public variables',
|
|
28
28
|
types: 'TypeScript types of the database for createClient<Database>() (out=src/types/database.ts)',
|
|
29
29
|
env: 'TypeScript types of the public variables (PUBLIC_*) for poad.env (out=src/types/poad-env.ts)',
|
|
30
30
|
},
|
|
31
31
|
migrate: 'Apply pending migrations of poad/migrations and named queries of poad/queries (poad start does it too)',
|
|
32
32
|
migration: 'Database migrations: migration new <name>, migration list',
|
|
33
|
-
functions: 'Functions of the project (JS/TS, served on /functions/v1/<name>):
|
|
34
|
-
function: '
|
|
35
|
-
flows: 'Flows of the project (automations in poad/flows/<name>.json, engine 0.18.0+, needs Valkey):
|
|
36
|
-
flow: '
|
|
33
|
+
functions: 'Functions of the project (JS/TS, served on /functions/v1/<name>): new, list, types',
|
|
34
|
+
function: 'Alias of poad functions',
|
|
35
|
+
flows: 'Flows of the project (automations in poad/flows/<name>.json, engine 0.18.0+, needs Valkey): new, list, run, runs, show, cancel',
|
|
36
|
+
flow: 'Alias of poad flows',
|
|
37
37
|
/* status: `[AI] Vérification du statut de l'environnement`,
|
|
38
38
|
gen: {
|
|
39
39
|
description: 'Génération automatique des éléments clés pour votre projet',
|
package/test/help.test.js
CHANGED
|
@@ -123,9 +123,16 @@ test('unknown command with --help: error and command list, exit 1', (t) => {
|
|
|
123
123
|
assert.ok(!fs.existsSync(box.calls));
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
test('--help : une description qui contient [section] plus loin n’est pas coupée
|
|
126
|
+
test('--help : une description qui contient [section] plus loin n’est pas coupée, seul un [Libellé] en tête en est un', (t) => {
|
|
127
|
+
const { entries } = require('../utils/banner');
|
|
128
|
+
const [start, beta] = entries({ start: 'Start the project. [gateway] max_body of poad/config.toml', x: { description: '[BETA] Something new', a: 'sub' } });
|
|
129
|
+
assert.strictEqual(start.label, null);
|
|
130
|
+
assert.strictEqual(start.description, 'Start the project. [gateway] max_body of poad/config.toml');
|
|
131
|
+
assert.strictEqual(beta.label, 'beta');
|
|
132
|
+
assert.strictEqual(beta.description, 'Something new');
|
|
133
|
+
assert.deepStrictEqual(beta.subs, ['a']);
|
|
127
134
|
const box = sandbox(t);
|
|
128
135
|
const r = poad(box, ['--help']);
|
|
129
|
-
assert.match(r.stdout, /start \.+\s+Start the project,
|
|
136
|
+
assert.match(r.stdout, /start \.+\s+Start the project: engine, migrations/);
|
|
130
137
|
assert.match(r.stdout, /create \.+\s+Create a poad project/);
|
|
131
138
|
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Mise en page de l'aide : coupure aux espaces, retrait suspendu, largeur du
|
|
2
|
+
// terminal ; vue courte de « poad » et liste complète de « poad --help ».
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const assert = require('node:assert');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
const { tmpdir } = require('./helpers');
|
|
9
|
+
const { wrap, row, paragraph, terminalColumns, visible } = require('../utils/layout');
|
|
10
|
+
const banner = require('../utils/banner');
|
|
11
|
+
|
|
12
|
+
const chalk = require('chalk-v2');
|
|
13
|
+
const colored = new chalk.Instance({ level: 1 });
|
|
14
|
+
const POAD = path.join(__dirname, '..', 'poad.js');
|
|
15
|
+
const STUB = path.join(__dirname, 'help-stub.js');
|
|
16
|
+
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
17
|
+
|
|
18
|
+
test('wrap: word boundaries, never wider than the width', () => {
|
|
19
|
+
const text = 'Start the project, apply migrations, start the services chosen with poad setup, then show its state';
|
|
20
|
+
for (const width of [12, 20, 33, 50, 80]) {
|
|
21
|
+
const lines = wrap(text, width);
|
|
22
|
+
assert.ok(lines.every((l) => l.length <= width), `${width}: ${JSON.stringify(lines)}`);
|
|
23
|
+
assert.strictEqual(lines.join(' '), text, `${width}: no word lost or cut`);
|
|
24
|
+
}
|
|
25
|
+
assert.deepStrictEqual(wrap('a b c', 100), ['a b c']);
|
|
26
|
+
assert.deepStrictEqual(wrap('', 20), []);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('wrap: a word longer than the width is cut into pieces of that width', () => {
|
|
30
|
+
assert.deepStrictEqual(wrap('go abcdefghijklmnop end', 6), ['go', 'abcdef', 'ghijkl', 'mnop', 'end']);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('row: hanging indent under the description column, dotted leader', () => {
|
|
34
|
+
const lines = row({ name: 'start', nameWidth: 12, columns: 50, segments: 'Start the project, apply migrations, start the services chosen with poad setup' });
|
|
35
|
+
const column = 3 + 12 + 2;
|
|
36
|
+
assert.match(lines[0], /^ {3}start \.{6} {2}Start/);
|
|
37
|
+
assert.strictEqual(lines[0].indexOf('Start'), column);
|
|
38
|
+
for (const l of lines.slice(1)) {
|
|
39
|
+
assert.strictEqual(l.length - l.trimStart().length, column, JSON.stringify(l));
|
|
40
|
+
}
|
|
41
|
+
assert.ok(lines.every((l) => l.length <= 50));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('row: colour codes do not count in the width, a label stays in front', () => {
|
|
45
|
+
const segs = [
|
|
46
|
+
{ text: '(AI)', style: colored.yellow },
|
|
47
|
+
{ text: 'AI providers: keys of this machine and their copy into a project', style: colored.white },
|
|
48
|
+
{ text: '(subcommands:', style: colored.grey },
|
|
49
|
+
{ text: 'login,', style: colored.cyan },
|
|
50
|
+
{ text: 'models)', style: colored.cyan },
|
|
51
|
+
];
|
|
52
|
+
const lines = row({ name: 'ai', nameStyle: colored.cyanBright, dotStyle: colored.grey, nameWidth: 10, columns: 60, segments: segs });
|
|
53
|
+
assert.ok(lines[0].includes('\x1b['), 'coloured');
|
|
54
|
+
assert.ok(lines.every((l) => visible(l) <= 60), lines.map(strip).join('\n'));
|
|
55
|
+
assert.match(strip(lines[0]), /^ {3}ai \.{7} {2}\(AI\) AI providers/);
|
|
56
|
+
for (const l of lines.slice(1)) assert.match(strip(l), /^ {15}\S/);
|
|
57
|
+
assert.match(strip(lines.join(" ")).replace(/\s+/g, " "), /\(subcommands: login, models\)/);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('row: too narrow for two columns, the description goes under the command', () => {
|
|
61
|
+
const lines = row({ name: 'client <subcommand>', nameWidth: 23, columns: 44, segments: 'Front-end of the project: client init, kept as an alias' });
|
|
62
|
+
assert.strictEqual(lines[0], ' client <subcommand>');
|
|
63
|
+
assert.ok(lines.slice(1).every((l) => /^ {7}\S/.test(l) && l.length <= 44), lines.join('\n'));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('paragraph and terminalColumns', () => {
|
|
67
|
+
assert.ok(paragraph('one two three four five six', { columns: 12, indent: 3 }).every((l) => l.startsWith(' ') && l.length <= 12));
|
|
68
|
+
assert.strictEqual(terminalColumns({ isTTY: true, columns: 132 }, {}), 132);
|
|
69
|
+
assert.strictEqual(terminalColumns({ isTTY: false }, {}), 100);
|
|
70
|
+
assert.strictEqual(terminalColumns({ isTTY: false }, { COLUMNS: '80' }), 80);
|
|
71
|
+
assert.strictEqual(terminalColumns({ isTTY: true, columns: 12 }, {}), 40);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('short view: only the commands of SHORT, each on one line at 100 columns', () => {
|
|
75
|
+
const lines = banner.render({ full: false, columns: 100, version: '9.9.9', chalk: colored });
|
|
76
|
+
const plain = lines.map(strip);
|
|
77
|
+
assert.ok(plain.length <= 36, `${plain.length} lines`);
|
|
78
|
+
assert.ok(plain.every((l) => l.length <= 100));
|
|
79
|
+
const listed = plain.filter((l) => /^ {3}\S+ \.+ {2}/.test(l)).map((l) => l.trim().split(' ')[0]);
|
|
80
|
+
assert.deepStrictEqual(listed, [...Object.keys(banner.SHORT.global), ...Object.keys(banner.SHORT.project)]);
|
|
81
|
+
for (const hidden of ['flows', 'flow', 'functions', 'function', 'gen', 'kc', 'migration', 'migrate', 'client', 'install']) {
|
|
82
|
+
assert.ok(!listed.includes(hidden), hidden);
|
|
83
|
+
}
|
|
84
|
+
assert.ok(plain.some((l) => /poad --help +every command/.test(l)));
|
|
85
|
+
assert.ok(plain.some((l) => /poad <command> --help +details of a command/.test(l)));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('SHORT names only existing commands', () => {
|
|
89
|
+
for (const scope of ['global', 'project']) {
|
|
90
|
+
const table = require(`../${scope}/cli`);
|
|
91
|
+
for (const name of Object.keys(banner.SHORT[scope])) assert.ok(table[name], `${scope} ${name}`);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('full list: every line within the width, at 100, 80 and 50 columns', () => {
|
|
96
|
+
for (const columns of [100, 80, 50]) {
|
|
97
|
+
const plain = banner.render({ full: true, columns, version: '9.9.9', chalk: colored }).map(strip);
|
|
98
|
+
assert.ok(plain.every((l) => l.length <= columns || /^[ _|.'\\/()`,-]+$/.test(l)), `${columns}: ${plain.find((l) => l.length > columns)}`);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/** Projet factice ; version déjà vérifiée pour que « poad » sans argument n'appelle pas npm */
|
|
103
|
+
function sandbox(t) {
|
|
104
|
+
const dir = tmpdir(t);
|
|
105
|
+
fs.mkdirSync(path.join(dir, 'poad'));
|
|
106
|
+
fs.writeFileSync(path.join(dir, 'poad', 'config.toml'), 'project_id = "t"\nproject_uuid = "poad-layout-test"\nengine = "0.28.0"\n');
|
|
107
|
+
fs.mkdirSync(path.join(dir, 'home'));
|
|
108
|
+
fs.writeFileSync(path.join(dir, 'home', '.poad_last_check.json'), JSON.stringify({ date: new Date(), version: require('../package.json').version }));
|
|
109
|
+
return dir;
|
|
110
|
+
}
|
|
111
|
+
const poad = (dir, args, columns = 100) =>
|
|
112
|
+
spawnSync(process.execPath, ['--require', STUB, POAD, ...args], {
|
|
113
|
+
cwd: dir,
|
|
114
|
+
encoding: 'utf8',
|
|
115
|
+
input: '',
|
|
116
|
+
timeout: 15000,
|
|
117
|
+
env: { ...process.env, HOME: path.join(dir, 'home'), POAD_TEST_CALLS: path.join(dir, 'calls.log'), COLUMNS: String(columns), NODE_OPTIONS: '', FORCE_COLOR: '0' },
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('poad --help, -h and help: every command and subcommand listed, no colour codes when piped', (t) => {
|
|
121
|
+
const dir = sandbox(t);
|
|
122
|
+
const full = poad(dir, ['--help']);
|
|
123
|
+
assert.strictEqual(full.status, 0, full.stderr);
|
|
124
|
+
assert.ok(!full.stdout.includes('\x1b['), 'no colour codes');
|
|
125
|
+
assert.strictEqual(poad(dir, ['-h']).stdout, full.stdout);
|
|
126
|
+
assert.strictEqual(poad(dir, ['help']).stdout, full.stdout);
|
|
127
|
+
const text = full.stdout.replace(/\s+/g, ' ');
|
|
128
|
+
for (const scope of ['global', 'project']) {
|
|
129
|
+
for (const [name, v] of Object.entries(require(`../${scope}/cli`))) {
|
|
130
|
+
assert.match(full.stdout, new RegExp(`^ {3}${name}( <subcommand>)? \\.`, 'm'), name);
|
|
131
|
+
if (v && typeof v === 'object') {
|
|
132
|
+
const subs = Object.keys(v).filter((k) => k !== 'description');
|
|
133
|
+
assert.ok(text.includes(`(subcommands: ${subs.join(', ')})`), `${name}: ${subs}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
assert.ok(full.stdout.split('\n').every((l) => l.length <= 100 || /^[ _|.'\\/()`,-]+$/.test(l)));
|
|
138
|
+
assert.ok(!fs.existsSync(path.join(dir, 'calls.log')));
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('plain poad: the short view, under 36 lines at 100 columns', (t) => {
|
|
142
|
+
const dir = sandbox(t);
|
|
143
|
+
const r = poad(dir, []);
|
|
144
|
+
assert.strictEqual(r.status, 0, r.stderr);
|
|
145
|
+
const lines = r.stdout.replace(/\n+$/, '').split('\n');
|
|
146
|
+
assert.ok(lines.length <= 36, `${lines.length} lines`);
|
|
147
|
+
assert.match(r.stdout, /version /);
|
|
148
|
+
assert.doesNotMatch(r.stdout, /^ {3}flows /m);
|
|
149
|
+
assert.ok(!fs.existsSync(path.join(dir, 'calls.log')));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('poad <command> --help: the details moved out of the list are there, wrapped', (t) => {
|
|
153
|
+
const dir = sandbox(t);
|
|
154
|
+
const expect = {
|
|
155
|
+
start: ['--bare', '--quiet', 'max_body', 'replaced by a free one', 'poad info --secrets'],
|
|
156
|
+
stop: ['runner', 'valkey (or redis)'],
|
|
157
|
+
logs: ['level=warn', 'since=15m', 'run=<id>', 'token=<name>', 'event=<event>', 'provider=<provider>', '--json'],
|
|
158
|
+
upgrade: ['to=<version>', 'channel=beta', 'POAD_CHANNEL=beta', '--rollback', '--list'],
|
|
159
|
+
setup: ['kc=shared', '--none', '--list', 'migrate=off'],
|
|
160
|
+
clean: ['--dry-run', '--yes'],
|
|
161
|
+
flows: ['input=<file.json>', '--no-wait', 'cancel <run_id>'],
|
|
162
|
+
functions: ['new <name>', 'types'],
|
|
163
|
+
db: ['poad db reset', 'diff --discard'],
|
|
164
|
+
};
|
|
165
|
+
for (const [cmd, words] of Object.entries(expect)) {
|
|
166
|
+
for (const columns of [100, 60]) {
|
|
167
|
+
const r = poad(dir, [cmd, '--help'], columns);
|
|
168
|
+
assert.strictEqual(r.status, 0, r.stderr);
|
|
169
|
+
const flat = r.stdout.replace(/\s+/g, ' ');
|
|
170
|
+
for (const w of words) assert.ok(flat.includes(w), `${cmd} --help (${columns}): ${w}`);
|
|
171
|
+
// seules les lignes « Usage » peuvent dépasser (une commande ne se coupe pas)
|
|
172
|
+
const long = r.stdout.split('\n').filter((l) => l.length > columns && !/^ (Usage : | {8})poad /.test(l));
|
|
173
|
+
assert.deepStrictEqual(long, [], `${cmd} at ${columns}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
package/utils/banner.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Liste des commandes de « poad » :
|
|
2
|
+
// poad vue courte : logo, usage, les commandes de tous les jours
|
|
3
|
+
// (une ligne chacune), de quoi aller plus loin ; tient sur
|
|
4
|
+
// un écran, le logo reste visible
|
|
5
|
+
// poad --help, -h, liste complète : toutes les commandes de global/cli.js et
|
|
6
|
+
// poad help project/cli.js, avec leurs sous-commandes
|
|
7
|
+
// Le détail d'une commande (options, filtres) : poad <commande> --help (utils/help.js).
|
|
8
|
+
//
|
|
9
|
+
// Les commandes de la vue courte et leur ligne sont ici (SHORT) ; une commande
|
|
10
|
+
// absente de SHORT n'y paraît pas (flows, functions, gen, kc, migration…).
|
|
11
|
+
|
|
12
|
+
const { row, paragraph, terminalColumns } = require('./layout');
|
|
13
|
+
|
|
14
|
+
const SHORT = {
|
|
15
|
+
global: {
|
|
16
|
+
create: 'Create a project, or add a front-end to it',
|
|
17
|
+
init: 'Init poad/ in an existing folder',
|
|
18
|
+
start: 'Start the project and its services',
|
|
19
|
+
stop: 'Stop the project',
|
|
20
|
+
run: 'Run an optional service (kc, valkey, runner)',
|
|
21
|
+
ai: 'AI providers: keys of this machine, use in a project',
|
|
22
|
+
clean: 'Remove what stopped projects left on this machine',
|
|
23
|
+
},
|
|
24
|
+
project: {
|
|
25
|
+
info: 'URLs, keys and state of the running project',
|
|
26
|
+
console: 'Open the administration console in the browser',
|
|
27
|
+
logs: 'Logs of every service, with filters',
|
|
28
|
+
setup: 'Choose what poad start starts',
|
|
29
|
+
db: 'Local database: reset, seed, diff',
|
|
30
|
+
upgrade: 'Upgrade the engine of the project',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// « [Libellé] description » : un libellé seulement en tête du texte. Un crochet plus loin
|
|
35
|
+
// (« [gateway] max_body ») fait partie de la description.
|
|
36
|
+
const LABEL = /^\[([^\]]*)\] /;
|
|
37
|
+
|
|
38
|
+
/** Commandes d'une table de cli.js : [{ name, description, label, subs }] */
|
|
39
|
+
function entries(table) {
|
|
40
|
+
return Object.entries(table).map(([name, v]) => {
|
|
41
|
+
const text = typeof v === 'string' ? v : (v && v.description) || '';
|
|
42
|
+
const m = LABEL.exec(text);
|
|
43
|
+
const subs = v && typeof v === 'object' ? Object.keys(v).filter((k) => k !== 'description') : null;
|
|
44
|
+
return { name, description: m ? text.slice(m[0].length) : text, label: m ? m[1].toLowerCase() : null, subs };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function labelSegment(label, chalk) {
|
|
49
|
+
if (!label) return [];
|
|
50
|
+
const styles = { experimental: chalk.red, alpha: chalk.cyan, beta: chalk.magenta, docker: chalk.green, ai: chalk.yellow };
|
|
51
|
+
const style = styles[label];
|
|
52
|
+
if (!style) return [];
|
|
53
|
+
return [{ text: `(${label === 'ai' ? 'AI' : label})`, style }];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Segments de la description d'une commande : libellé, texte, sous-commandes */
|
|
57
|
+
function segmentsOf(e, chalk, { text = e.description, subs = true } = {}) {
|
|
58
|
+
const segs = [...labelSegment(e.label, chalk), { text, style: chalk.white }];
|
|
59
|
+
if (subs && e.subs && e.subs.length) {
|
|
60
|
+
segs.push({ text: '(subcommands:', style: chalk.grey });
|
|
61
|
+
// « login, » : la virgule en gris ; la dernière garde sa parenthèse collée
|
|
62
|
+
const tail = (mark) => (w) => chalk.cyan(w.slice(0, -1)) + chalk.grey(mark);
|
|
63
|
+
e.subs.forEach((s, i) => segs.push(i < e.subs.length - 1 ? { text: s + ',', style: tail(',') } : { text: s + ')', style: tail(')') }));
|
|
64
|
+
}
|
|
65
|
+
return segs;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Lignes de la liste des commandes (sans saut de ligne final).
|
|
70
|
+
* full true : liste complète ; false : vue courte (SHORT)
|
|
71
|
+
* inProject dans un projet poad (sinon les commandes de projet ne sont pas listées)
|
|
72
|
+
*/
|
|
73
|
+
function render({ full = false, inProject = true, columns = terminalColumns(), version, chalk = require('chalk-v2'), tables } = {}) {
|
|
74
|
+
tables = tables || { global: require('../global/cli'), project: require('../project/cli') };
|
|
75
|
+
const pick = (scope) => {
|
|
76
|
+
const all = entries(tables[scope]);
|
|
77
|
+
if (full) return all;
|
|
78
|
+
return Object.keys(SHORT[scope])
|
|
79
|
+
.map((name) => all.find((e) => e.name === name))
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.map((e) => ({ ...e, short: SHORT[scope][e.name] }));
|
|
82
|
+
};
|
|
83
|
+
const groups = { global: pick('global'), project: inProject ? pick('project') : [] };
|
|
84
|
+
const title = (e) => (full && e.subs && e.subs.length ? `${e.name} <subcommand>` : e.name);
|
|
85
|
+
const nameWidth = Math.max(...[...groups.global, ...groups.project].map((e) => title(e).length)) + 4;
|
|
86
|
+
|
|
87
|
+
const lines = [];
|
|
88
|
+
const figlet = require('figlet');
|
|
89
|
+
lines.push(...figlet.textSync('poad').replace(/\s+$/, '').split('\n').map((l) => chalk.cyan(l)));
|
|
90
|
+
lines.push(chalk.white.bold(` version ${version}`));
|
|
91
|
+
lines.push('');
|
|
92
|
+
lines.push(`${chalk.bold(' Usage :')} ${chalk.cyanBright('poad <command>')} ${chalk.cyan('[<args>]')}`);
|
|
93
|
+
|
|
94
|
+
const table = (list) => {
|
|
95
|
+
for (const e of list) {
|
|
96
|
+
lines.push(
|
|
97
|
+
...row({
|
|
98
|
+
name: title(e),
|
|
99
|
+
nameStyle: chalk.cyanBright,
|
|
100
|
+
dotStyle: chalk.grey,
|
|
101
|
+
nameWidth,
|
|
102
|
+
columns,
|
|
103
|
+
segments: full ? segmentsOf(e, chalk) : segmentsOf(e, chalk, { text: e.short, subs: false }),
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
lines.push('');
|
|
110
|
+
lines.push(chalk.bold(' Global commands :'));
|
|
111
|
+
table(groups.global);
|
|
112
|
+
lines.push('');
|
|
113
|
+
lines.push(chalk.bold(' Project commands :'));
|
|
114
|
+
if (!inProject) lines.push(...paragraph([{ text: 'You are not in a project directory.' }], { columns }));
|
|
115
|
+
else table(groups.project);
|
|
116
|
+
lines.push('');
|
|
117
|
+
if (full) {
|
|
118
|
+
lines.push(...paragraph([{ text: 'poad <command> --help', style: chalk.cyanBright }, { text: ': usage, options and details of a command', style: chalk.grey }], { columns, indent: 1 }));
|
|
119
|
+
} else {
|
|
120
|
+
const more = [
|
|
121
|
+
['poad --help', 'every command and its options'],
|
|
122
|
+
['poad <command> --help', 'details of a command'],
|
|
123
|
+
];
|
|
124
|
+
const w = Math.max(...more.map(([k]) => k.length)) + 2;
|
|
125
|
+
for (const [k, v] of more) lines.push(...row({ name: k, nameStyle: chalk.cyanBright, nameWidth: w, columns, indent: 1, dots: false, segments: [{ text: v, style: chalk.grey }] }));
|
|
126
|
+
}
|
|
127
|
+
lines.push('');
|
|
128
|
+
return lines;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = { SHORT, entries, render };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Fiches d'aide des commandes qui n'exportent pas help() : ce que la liste
|
|
2
|
+
// des commandes (poad --help) ne dit pas, options et filtres compris. Rendu
|
|
3
|
+
// par utils/help.js (poad <commande> --help), coupé à la largeur du terminal.
|
|
4
|
+
//
|
|
5
|
+
// usage lignes « poad … » (la première après « Usage : »)
|
|
6
|
+
// text paragraphes avant les options (sinon la description de cli.js)
|
|
7
|
+
// options [option, explication]
|
|
8
|
+
// notes paragraphes après les options
|
|
9
|
+
|
|
10
|
+
const sheets = {
|
|
11
|
+
start: {
|
|
12
|
+
usage: ['poad start [--all | --bare | --quiet]'],
|
|
13
|
+
text: [
|
|
14
|
+
'Start the project: the engine and Mailpit, the migrations of poad/migrations (unless "poad setup migrate=off"), the services chosen with poad setup, then show its state (as poad info).',
|
|
15
|
+
],
|
|
16
|
+
options: [
|
|
17
|
+
['--all', 'every configured optional service (Keycloak, Valkey, flows runner), autostart or not'],
|
|
18
|
+
['--bare', 'the engine and Mailpit only, this time'],
|
|
19
|
+
['--quiet', 'nothing if the project already runs (bun start of a front-end)'],
|
|
20
|
+
],
|
|
21
|
+
notes: [
|
|
22
|
+
'Secrets are hidden in the state shown at the end: poad info --secrets shows them.',
|
|
23
|
+
'A port of poad/config.toml already used on this machine is replaced by a free one.',
|
|
24
|
+
'Request bodies are limited by the gateway to [gateway] max_body of poad/config.toml (default "10m", storage uploads excepted).',
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
stop: {
|
|
28
|
+
usage: ['poad stop [keycloak | valkey | runner]'],
|
|
29
|
+
text: ['Stop the project: engine, Mailpit, Keycloak, Valkey, flows runner, network. Its data stays in poad/data.'],
|
|
30
|
+
options: [
|
|
31
|
+
['keycloak (or kc)', 'Keycloak only (a shared Keycloak is released, and stops when no project uses it any more)'],
|
|
32
|
+
['valkey (or redis)', 'Valkey only'],
|
|
33
|
+
['runner', 'the flows runner only'],
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
clean: {
|
|
37
|
+
usage: ['poad clean [--dry-run | --yes]'],
|
|
38
|
+
text: [
|
|
39
|
+
'Remove what stopped poad projects left on this machine: optional services (Mailpit, Keycloak, Valkey, flows runner) whose engine no longer runs, stopped poad containers, networks of stopped projects, a shared Keycloak no running project uses, engine images (about 3 GB each) no container uses.',
|
|
40
|
+
],
|
|
41
|
+
options: [
|
|
42
|
+
['--dry-run', 'list only'],
|
|
43
|
+
['--yes', 'no question (required outside a terminal)'],
|
|
44
|
+
],
|
|
45
|
+
notes: [
|
|
46
|
+
'Nothing of a running project is touched. A stopped project loses nothing: its data is in its poad/data folder, and a removed engine image is pulled again by poad start when needed.',
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
setup: {
|
|
50
|
+
usage: ['poad setup [<setting>=<value> …] [--all | --none | --list]'],
|
|
51
|
+
text: ['Choose what "poad start" starts with the project: e-mails, Keycloak, Valkey, migrations. Interactive in a terminal.'],
|
|
52
|
+
options: [
|
|
53
|
+
['kc=on valkey=off', 'not interactive: changes only the settings given'],
|
|
54
|
+
['kc=shared | kc=own', 'Keycloak shared by the local projects (one container, one realm per project), or one of its own'],
|
|
55
|
+
['mail=smtp smtp.host=… smtp.port=587 smtp.user=… smtp.pass=…', 'e-mails sent through an SMTP server'],
|
|
56
|
+
['mail=mailpit', 'back to Mailpit (e-mails caught locally)'],
|
|
57
|
+
['migrate=off', 'migrations applied by hand (poad migrate)'],
|
|
58
|
+
['--all | --none', 'every optional service in autostart, or none'],
|
|
59
|
+
['--list', 'show the settings, change nothing'],
|
|
60
|
+
],
|
|
61
|
+
notes: [
|
|
62
|
+
'Everything goes to poad/config.toml, except the SMTP password (poad/secrets.toml). Turning a service off removes its autostart only: its port, data and test set stay. The flows runner is set elsewhere (poad run runner, [flows] runner).',
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
upgrade: {
|
|
66
|
+
usage: ['poad upgrade [to=<version>] [--yes]', 'poad upgrade --rollback [file=<backup>]', 'poad upgrade --list'],
|
|
67
|
+
text: [
|
|
68
|
+
'Upgrade the engine of the project to the latest published one: backup (poad/backups), stop, update of poad/config.toml, restart (the engine migrates poad/data) and migrations.',
|
|
69
|
+
],
|
|
70
|
+
options: [
|
|
71
|
+
['to=<version>', 'a given (newer) version'],
|
|
72
|
+
['channel=beta', 'the beta channel (or channel = "beta" in poad/config.toml, or POAD_CHANNEL=beta)'],
|
|
73
|
+
['--rollback', 'back to the latest backup (file=<name>: another one)'],
|
|
74
|
+
['--list', 'list the backups'],
|
|
75
|
+
['--yes', 'no question (required outside a terminal)'],
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
logs: {
|
|
79
|
+
usage: ['poad logs [service …] [<filter>=<value> …] [-f] [--json]'],
|
|
80
|
+
text: [
|
|
81
|
+
'Unified logs of the project (every service, the project functions and flow steps), the latest 100 lines by default. Services: gateway, data, auth, storage, meta, functions, flows, postgres, logs, engine, mailpit, keycloak, valkey, ai.',
|
|
82
|
+
],
|
|
83
|
+
options: [
|
|
84
|
+
['level=warn', 'warn, error and fatal'],
|
|
85
|
+
['since=15m', 'since 15 minutes (s, m, h, d)'],
|
|
86
|
+
['request=<id>', 'the whole path of a request (the start of the id is enough)'],
|
|
87
|
+
['grep=<text>', 'messages that contain this text'],
|
|
88
|
+
['flow=<name>', 'the lines of a flow (engine and steps)'],
|
|
89
|
+
['run=<id>', 'one run of a flow (its id, or its first 8 characters)'],
|
|
90
|
+
['step=<name>', 'one step (with flow= or run=, most often)'],
|
|
91
|
+
['function=<name>', 'one function: its calls and its console.log'],
|
|
92
|
+
['token=<name>', 'a token of the MCP server (engine 0.29+): its name, id (or its start) or prefix'],
|
|
93
|
+
['tool=<name>', 'a tool of the MCP server'],
|
|
94
|
+
['outcome=<outcome>', 'MCP: ok, error, refused, invalid, not_found, unauthorized, rate_limited; AI: ok, provider_error, budget_exceeded, no_credential, forbidden, invalid'],
|
|
95
|
+
['provider=<provider>', 'calls to an AI provider (engine 0.30+), e.g. poad logs ai provider=openai'],
|
|
96
|
+
['model=<model>', 'calls to an AI model'],
|
|
97
|
+
['event=<event>', 'an event, e.g. ai_default_model_changed'],
|
|
98
|
+
['limit=100', 'number of lines'],
|
|
99
|
+
['-f, --follow', 'follow live'],
|
|
100
|
+
['--json', 'one JSON line per entry (for jq)'],
|
|
101
|
+
],
|
|
102
|
+
notes: ['Everything combines: poad logs flows run=dafb44e1 step=call level=warn -f'],
|
|
103
|
+
},
|
|
104
|
+
functions: {
|
|
105
|
+
usage: ['poad functions new <name>', 'poad functions list', 'poad functions types'],
|
|
106
|
+
text: [
|
|
107
|
+
'Functions of the project: modules in poad/functions/<name>/ that export { fetch(request, env, ctx) } (Cloudflare Workers format), served by the engine on /functions/v1/<name> and reloaded on every save.',
|
|
108
|
+
],
|
|
109
|
+
options: [
|
|
110
|
+
['new <name> (or create)', 'create poad/functions/<name>/index.ts'],
|
|
111
|
+
['list', 'functions of the project and their state in the running engine'],
|
|
112
|
+
['types', 'types for the editor (autocompletion), read from the running engine'],
|
|
113
|
+
],
|
|
114
|
+
notes: ['Their console.log: poad logs function=<name>'],
|
|
115
|
+
},
|
|
116
|
+
flows: {
|
|
117
|
+
usage: [
|
|
118
|
+
'poad flows new <name>',
|
|
119
|
+
'poad flows list',
|
|
120
|
+
'poad flows run <name> [key=value …] [input=<file.json>] [--wait | --no-wait]',
|
|
121
|
+
'poad flows runs [name] [limit=20]',
|
|
122
|
+
'poad flows show <run_id>',
|
|
123
|
+
'poad flows cancel <run_id>',
|
|
124
|
+
],
|
|
125
|
+
text: [
|
|
126
|
+
'Flows of the project: automations (trigger, steps, edges) described in poad/flows/<name>.json, served by the engine (0.18.0+) on /flows/v1. Their queue is on the Valkey of the project (poad run valkey); container steps are started by the runner (poad run runner).',
|
|
127
|
+
],
|
|
128
|
+
options: [
|
|
129
|
+
['new <name>', 'create poad/flows/<name>.json (minimal flow)'],
|
|
130
|
+
['list', 'flows of the project, as the running engine sees them'],
|
|
131
|
+
['run <name>', 'start a flow and follow its steps'],
|
|
132
|
+
['runs [name]', 'latest runs'],
|
|
133
|
+
['show <run_id>', 'detail of a run'],
|
|
134
|
+
['cancel <run_id>', 'cancel a running run'],
|
|
135
|
+
],
|
|
136
|
+
notes: ['Their logs: poad logs flow=<name>, poad logs run=<id>'],
|
|
137
|
+
},
|
|
138
|
+
migration: {
|
|
139
|
+
usage: ['poad migration new <name>', 'poad migration list'],
|
|
140
|
+
options: [
|
|
141
|
+
['new <name>', 'create poad/migrations/<timestamp>_<name>.sql'],
|
|
142
|
+
['list', 'applied and pending migrations'],
|
|
143
|
+
],
|
|
144
|
+
notes: ['poad migrate applies the pending ones (poad start does it too).'],
|
|
145
|
+
},
|
|
146
|
+
kc: {
|
|
147
|
+
usage: ['poad kc', 'poad kc export'],
|
|
148
|
+
options: [
|
|
149
|
+
['(nothing)', 'show the Keycloak test set of the project (poad/keycloak.json)'],
|
|
150
|
+
['export', 'rewrite poad/keycloak.json from the running Keycloak (roles, groups, users created or changed in its console)'],
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const alias = (of, name) => ({
|
|
156
|
+
...sheets[of],
|
|
157
|
+
usage: sheets[of].usage.map((u) => u.replace(`poad ${of}`, `poad ${name}`)),
|
|
158
|
+
text: [`Alias of poad ${of}.`, ...(sheets[of].text || [])],
|
|
159
|
+
});
|
|
160
|
+
sheets.function = alias('functions', 'function');
|
|
161
|
+
sheets.flow = alias('flows', 'flow');
|
|
162
|
+
|
|
163
|
+
module.exports = sheets;
|
package/utils/help.js
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
// connaît pas --help le prenait pour un argument quelconque et faisait son
|
|
6
6
|
// travail (poad stop --help arrêtait le projet).
|
|
7
7
|
//
|
|
8
|
-
// Une commande peut exporter help() pour une aide détaillée ; sinon sa
|
|
9
|
-
//
|
|
8
|
+
// Une commande peut exporter help() pour une aide détaillée ; sinon sa fiche
|
|
9
|
+
// de utils/help-details.js (usage, options, notes), sinon sa description de
|
|
10
|
+
// global/cli.js ou project/cli.js ; ses sous-commandes en plus. Le tout est
|
|
11
|
+
// coupé à la largeur du terminal (utils/layout.js).
|
|
10
12
|
const path = require('path');
|
|
13
|
+
const sheets = require('./help-details');
|
|
11
14
|
|
|
12
15
|
const HELP_FLAGS = ['--help', '-h'];
|
|
13
16
|
|
|
@@ -64,16 +67,39 @@ function printHelp(argv = [], { tables = loadTables(), base = path.join(__dirnam
|
|
|
64
67
|
return true;
|
|
65
68
|
}
|
|
66
69
|
const name = `poad ${cmd.dir.join(' ')}`;
|
|
70
|
+
const { row, paragraph, terminalColumns } = require('./layout');
|
|
71
|
+
const columns = terminalColumns();
|
|
67
72
|
const subs = cmd.entry && typeof cmd.entry === 'object' ? Object.entries(cmd.entry).filter(([k]) => k !== 'description') : [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
const sheet = sheets[cmd.dir.join(' ')];
|
|
74
|
+
const out = [];
|
|
75
|
+
if (sheet) {
|
|
76
|
+
const [first, ...more] = sheet.usage;
|
|
77
|
+
out.push(`${chalk.bold(' Usage :')} ${chalk.cyanBright(first)}`);
|
|
78
|
+
for (const u of more) out.push(` ${chalk.cyanBright(u)}`);
|
|
79
|
+
} else {
|
|
80
|
+
out.push(`${chalk.bold(' Usage :')} ${chalk.cyanBright(name)} ${chalk.cyan(subs.length ? '<subcommand> [<args>]' : '[<args>]')}`);
|
|
81
|
+
}
|
|
82
|
+
out.push('');
|
|
83
|
+
((sheet && sheet.text) || [describe(cmd.entry)]).forEach((p, i) => out.push(...(i ? [''] : []), ...paragraph(p, { columns })));
|
|
71
84
|
if (subs.length) {
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
85
|
+
out.push('');
|
|
86
|
+
const titles = subs.map(([k]) => `${name} ${k}`);
|
|
87
|
+
const nameWidth = Math.max(...titles.map((t) => t.length)) + 2;
|
|
88
|
+
subs.forEach(([, v], i) => out.push(...row({ name: titles[i], nameStyle: chalk.cyanBright, nameWidth, columns, dots: false, segments: describe(v) })));
|
|
89
|
+
}
|
|
90
|
+
if (sheet && sheet.options) {
|
|
91
|
+
out.push('');
|
|
92
|
+
// une option trop longue pour la colonne passe sur sa propre ligne
|
|
93
|
+
const fit = sheet.options.filter(([k]) => k.length <= 24);
|
|
94
|
+
const nameWidth = Math.max(...fit.map(([k]) => k.length), 6) + 2;
|
|
95
|
+
for (const [k, v] of sheet.options) out.push(...row({ name: k, nameStyle: chalk.cyanBright, nameWidth, columns, dots: false, segments: v }));
|
|
96
|
+
}
|
|
97
|
+
for (const p of (sheet && sheet.notes) || []) {
|
|
98
|
+
out.push('');
|
|
99
|
+
out.push(...paragraph(p, { columns }));
|
|
75
100
|
}
|
|
76
|
-
|
|
101
|
+
out.push(' ');
|
|
102
|
+
console.log(out.join('\n'));
|
|
77
103
|
return true;
|
|
78
104
|
}
|
|
79
105
|
|
package/utils/layout.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Mise en page de l'aide dans le terminal : coupure aux espaces à la largeur
|
|
2
|
+
// réelle du terminal, retrait suspendu (les lignes suivantes d'une description
|
|
3
|
+
// repartent sous la colonne des descriptions, jamais en colonne 0).
|
|
4
|
+
//
|
|
5
|
+
// Le texte se donne en segments { text, style } : la coupure se fait sur le
|
|
6
|
+
// texte nu, la couleur (chalk) est posée mot par mot après coup, si bien
|
|
7
|
+
// qu'aucun code de couleur ne compte dans la largeur ni ne déborde d'une ligne.
|
|
8
|
+
|
|
9
|
+
const FALLBACK_COLUMNS = 100; // sortie qui n'est pas un terminal (tube, fichier)
|
|
10
|
+
const MIN_COLUMNS = 40;
|
|
11
|
+
const MIN_DESCRIPTION = 30; // en dessous : la description passe sous la commande
|
|
12
|
+
|
|
13
|
+
/** Largeur utile : celle du terminal, sinon $COLUMNS, sinon 100 (au moins 40) */
|
|
14
|
+
function terminalColumns(stream = process.stdout, env = process.env) {
|
|
15
|
+
const tty = stream && stream.isTTY && Number(stream.columns);
|
|
16
|
+
const n = tty || Number(env.COLUMNS) || FALLBACK_COLUMNS;
|
|
17
|
+
return Math.max(MIN_COLUMNS, Math.floor(n));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
21
|
+
const visible = (s) => String(s).replace(ANSI, '').length;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Coupe en mots ({ word, style }), un mot plus long que la largeur étant
|
|
25
|
+
* découpé en morceaux de cette largeur.
|
|
26
|
+
*/
|
|
27
|
+
function words(segments, width) {
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const seg of segments) {
|
|
30
|
+
const style = seg.style || ((s) => s);
|
|
31
|
+
for (const w of String(seg.text).split(/\s+/).filter(Boolean)) {
|
|
32
|
+
if (w.length <= width) out.push({ word: w, style });
|
|
33
|
+
else for (let i = 0; i < w.length; i += width) out.push({ word: w.slice(i, i + width), style });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Lignes de mots ({ word, style }[][]) d'au plus `width` caractères */
|
|
40
|
+
function wrapWords(segments, width) {
|
|
41
|
+
width = Math.max(1, Math.floor(width));
|
|
42
|
+
const lines = [];
|
|
43
|
+
let line = [];
|
|
44
|
+
let len = 0;
|
|
45
|
+
for (const w of words(segments, width)) {
|
|
46
|
+
const add = (line.length ? 1 : 0) + w.word.length;
|
|
47
|
+
if (line.length && len + add > width) {
|
|
48
|
+
lines.push(line);
|
|
49
|
+
line = [];
|
|
50
|
+
len = 0;
|
|
51
|
+
}
|
|
52
|
+
len += (line.length ? 1 : 0) + w.word.length;
|
|
53
|
+
line.push(w);
|
|
54
|
+
}
|
|
55
|
+
if (line.length) lines.push(line);
|
|
56
|
+
return lines;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const paint = (line) => line.map((w) => w.style(w.word)).join(' ');
|
|
60
|
+
|
|
61
|
+
/** Texte nu coupé aux espaces : tableau de lignes d'au plus `width` caractères */
|
|
62
|
+
function wrap(text, width) {
|
|
63
|
+
return wrapWords([{ text }], width).map((l) => l.map((w) => w.word).join(' '));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Paragraphe : segments coupés à la largeur, chaque ligne précédée de `indent` espaces */
|
|
67
|
+
function paragraph(segments, { columns = terminalColumns(), indent = 3 } = {}) {
|
|
68
|
+
if (typeof segments === 'string') segments = [{ text: segments }];
|
|
69
|
+
const lines = wrapWords(segments, columns - indent).map(paint);
|
|
70
|
+
return lines.map((l) => ' '.repeat(indent) + l);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Une ligne de tableau : « name .... description » à deux colonnes, la
|
|
75
|
+
* description en retrait suspendu. Trop étroit pour deux colonnes : la
|
|
76
|
+
* description passe sur ses propres lignes, sous la commande, plus en retrait.
|
|
77
|
+
*
|
|
78
|
+
* name texte nu de la commande (sa largeur compte), nameStyle sa couleur
|
|
79
|
+
* nameWidth largeur de la colonne des commandes (points compris)
|
|
80
|
+
* segments description : [{ text, style }]
|
|
81
|
+
* dots points de conduite entre la commande et la description
|
|
82
|
+
*/
|
|
83
|
+
function row({ name, nameStyle = (s) => s, dotStyle = (s) => s, segments, nameWidth, columns = terminalColumns(), indent = 3, gap = 2, dots = true }) {
|
|
84
|
+
if (typeof segments === 'string') segments = [{ text: segments }];
|
|
85
|
+
const pad = ' '.repeat(indent);
|
|
86
|
+
const column = indent + nameWidth + gap;
|
|
87
|
+
if (columns - column < MIN_DESCRIPTION || name.length > nameWidth) {
|
|
88
|
+
const sub = indent + 4;
|
|
89
|
+
// la commande elle-même se coupe si elle dépasse la largeur
|
|
90
|
+
return [...paragraph([{ text: name, style: nameStyle }], { columns, indent }), ...paragraph(segments, { columns, indent: sub })];
|
|
91
|
+
}
|
|
92
|
+
const filler = nameWidth - name.length;
|
|
93
|
+
const leader = dots && filler > 1 ? ' ' + dotStyle('.'.repeat(filler - 1)) : ' '.repeat(filler);
|
|
94
|
+
const lines = wrapWords(segments, columns - column).map(paint);
|
|
95
|
+
if (!lines.length) return [pad + nameStyle(name)];
|
|
96
|
+
return lines.map((l, i) => (i === 0 ? pad + nameStyle(name) + leader + ' '.repeat(gap) : ' '.repeat(column)) + l);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = { terminalColumns, wrap, wrapWords, paragraph, row, visible, FALLBACK_COLUMNS, MIN_COLUMNS, MIN_DESCRIPTION };
|