MCPcopy
hub / github.com/smapiot/piral / generateBody

Function generateBody

tools/generate-command-docs.js:253–310  ·  view source on GitHub ↗
(command, validators)

Source from the content-addressed store, hash-verified

251}
252
253function generateBody(command, validators) {
254 const { positionals, flags } = getCommandData(command.flags);
255
256 for (let i = 0; i < flags.length; i++) {
257 const flag = flags[i];
258 if (flag.type === 'boolean' && !flag.name.startsWith('no-')) {
259 flags.splice(i + 1, 0, {
260 ...flag,
261 name: `no-${flag.name}`,
262 describe: `Opposite of:\n${flag.describe}`,
263 default: printValue(!JSON.parse(flag.default)),
264 });
265 }
266 }
267
268 const content = `
269${command.description || 'No description available.'}
270
271## Syntax
272
273From the command line:
274
275${shell(`${getCall(command)} ${command.arguments.join(' ')}`)}
276
277Alternative:
278
279${shell(`pb ${command.name} ${command.arguments.join(' ')}`)}
280
281## Aliases
282
283Instead of \`${command.name}\` you can also use:
284
285${printAlias(command.alias)}
286
287## Positionals
288
289${details(command, positionals)}
290
291## Flags
292
293${details(
294 command,
295 flags.map((flag) => ({ ...flag, name: `--${flag.name}` })),
296)}
297`;
298
299 if (['validate-piral', 'validate-pilet'].includes(command.name)) {
300 const [target] = command.name.split('-').reverse();
301 const currentValidators = validators.filter((m) => m.target === target);
302 return `${content}
303## Validators
304
305${currentValidators.map(generateValidator).join('\n')}
306`;
307 }
308
309 return content;
310}

Callers 1

generateCommandDocsFunction · 0.85

Calls 8

printValueFunction · 0.85
shellFunction · 0.85
getCallFunction · 0.85
printAliasFunction · 0.85
detailsFunction · 0.85
mapMethod · 0.80
getCommandDataFunction · 0.70
filterMethod · 0.65

Tested by

no test coverage detected