Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
},
"dependencies": {
"@clidoc/core": "^1.0.0",
"@clidoc/yargs": "^0.1.0",
"@clidoc/yargs": "^1.1.0",
"hdrify": "workspace:*",
"sharp": "^0.34.5",
"yargs": "^18.0.0",
"yargs-file-commands": "^1.2.2"
"yargs-file-commands": "^2.1.0"
},
"devDependencies": {
"@types/yargs": "^17.0.35"
Expand Down
21 changes: 10 additions & 11 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { fileURLToPath } from 'node:url';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { fileCommands } from 'yargs-file-commands';
import { createDocgenCommand, fromYargs } from '@clidoc/yargs';
import { createDocgenCommand, fromYargsAsync } from '@clidoc/yargs';
import { handleOpenCliRequest, infoFromPackageJson } from '@clidoc/core';
import type { OpenCliDocument } from '@clidoc/core';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const commandsDir = path.join(__dirname, 'commands');
Expand All @@ -30,12 +29,14 @@ function isCommandError(msg: string): boolean {
* the caller handles exit codes.
*/
export async function runCli(argv: string[]): Promise<unknown> {
let document: OpenCliDocument;
const commands = await fileCommands({ commandDirs: [commandsDir] });
const getDocument = () => fromYargsAsync([...commands, docgen], info);
const docgen = createDocgenCommand(getDocument);
const y = yargs(argv)
.scriptName('hdrify')
.usage('$0 <command> [options]')
.command(await fileCommands({ commandDirs: [commandsDir] }))
.command(createDocgenCommand(() => document))
.command(commands)
.command(docgen)
.demandCommand(1, 'You must specify a command.')
.help()
.alias('h', 'help')
Expand All @@ -52,21 +53,19 @@ export async function runCli(argv: string[]): Promise<unknown> {
if (err) throw err;
throw new Error(msg);
});
// generate the document once every command, including docgen, is registered
document = fromYargs(y, info);

if (argv.length === 0) {
console.error('You must specify a command.\n');
y.showHelp();
return;
}

if (await handleOpenCliRequest(argv, () => document)) {
return;
if (argv[0] === '__opencli') {
const document = await getDocument();
if (await handleOpenCliRequest(argv, () => document)) return;
}

try {
return await y.parse();
return await y.parseAsync();
} catch (error) {
if (error instanceof HelpShownError) {
throw error;
Expand Down
40 changes: 20 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ linkWorkspacePackages: true
minimumReleaseAgeExclude:
- tanstack-router-ga4
- yargs-file-commands
- '@clidoc/core@1.1.0'
- '@clidoc/yargs@1.1.0'
Loading