All files / cli/src index.ts

0% Statements 0/4
0% Branches 0/7
0% Functions 0/2
0% Lines 0/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                                                           
import { fileURLToPath } from 'node:url';
import { handleOpenCliRequest } from '@clidoc/core';
import yargs from 'yargs';
import { fileCommands } from 'yargs-file-commands';
import { cliDocument, info } from './definition.js';
 
export { servePreview, type PreviewServer } from './preview.js';
export { cliDocument } from './definition.js';
 
/** Run the CLI without terminating the embedding process. Commands live in individual files under ./commands. */
export async function main(argv = process.argv.slice(2)): Promise<void> {
  if (await handleOpenCliRequest(argv, cliDocument)) return;
  await yargs(argv.length ? argv : ['--help'])
    .scriptName(info.binary)
    .usage('$0 <command> [options]\n\nValidate, inspect, convert and preview IES and EULUMDAT photometric files.')
    .command(await fileCommands({ commandDirs: [fileURLToPath(new URL('./commands', import.meta.url))] }))
    .demandCommand(1)
    .strict()
    .help()
    .alias('h', 'help')
    .version(info.version)
    .alias('v', 'version')
    .epilogue('Files remain on your computer. The viewer binds to 127.0.0.1.')
    .exitProcess(false)
    .fail((message, error) => {
      throw error ?? new Error(`${message}. Run ies --help.`);
    })
    .parseAsync();
}