File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,6 +54,10 @@ Commands:
5454
5555### ` generate `
5656
57+ You must provide either ` --target ` (one or more generators to run) or
58+ ` --config-file ` (which supplies the targets). Running ` generate ` without either
59+ exits with an error pointing you to the help output.
60+
5761```
5862Usage: @node-core/doc-kit generate [options]
5963
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ import { Command, Option } from 'commander';
22
33import { publicGenerators } from '../../src/generators/index.mjs' ;
44import createGenerator from '../../src/generators.mjs' ;
5- import { setConfig } from '../../src/utils/configuration/index.mjs' ;
5+ import {
6+ assertRunnableOptions ,
7+ setConfig ,
8+ } from '../../src/utils/configuration/index.mjs' ;
69import { errorWrap } from '../utils.mjs' ;
710
811const { runGenerators } = createGenerator ( ) ;
@@ -62,6 +65,8 @@ export default new Command('generate')
6265 . action (
6366 errorWrap ( async opts => {
6467 const config = await setConfig ( opts ) ;
68+ assertRunnableOptions ( config ) ;
69+
6570 await runGenerators ( config ) ;
6671 } )
6772 ) ;
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ mock.module('../../loaders.mjs', {
3333} ) ;
3434
3535const {
36+ assertRunnableOptions,
3637 loadConfigFile,
3738 createConfigFromCLIOptions,
3839 createRunConfiguration,
@@ -125,6 +126,28 @@ describe('config.mjs', () => {
125126 } ) ;
126127 } ) ;
127128
129+ describe ( 'assertRunnableOptions' , ( ) => {
130+ it ( 'should throw when target is missing' , ( ) => {
131+ assert . throws (
132+ ( ) => assertRunnableOptions ( { global : { input : 'src/' } } ) ,
133+ / B o t h a ` t a r g e t ` a n d a n ` i n p u t ` m u s t b e p r o v i d e d /
134+ ) ;
135+ } ) ;
136+
137+ it ( 'should throw when input is missing' , ( ) => {
138+ assert . throws (
139+ ( ) => assertRunnableOptions ( { target : [ 'json' ] , global : { } } ) ,
140+ / B o t h a ` t a r g e t ` a n d a n ` i n p u t ` m u s t b e p r o v i d e d /
141+ ) ;
142+ } ) ;
143+
144+ it ( 'should not throw when both target and input are provided' , ( ) => {
145+ assert . doesNotThrow ( ( ) =>
146+ assertRunnableOptions ( { target : [ 'json' ] , global : { input : 'src/' } } )
147+ ) ;
148+ } ) ;
149+ } ) ;
150+
128151 describe ( 'createRunConfiguration' , ( ) => {
129152 it ( 'should merge config sources in correct order' , async ( ) => {
130153 mockImportFromURL . mock . mockImplementationOnce ( async ( ) =>
Original file line number Diff line number Diff line change @@ -104,6 +104,24 @@ export const createConfigFromCLIOptions = options => ({
104104 chunkSize : options . chunkSize ,
105105} ) ;
106106
107+ /**
108+ * Asserts that the resolved configuration has everything needed to run:
109+ * at least one generator `target` and an `input` to read source files from.
110+ * These may come from CLI flags or a config file; by this point both sources
111+ * have been merged, so we validate the result rather than the raw options.
112+ *
113+ * @param {import('./types').Configuration } config - The merged configuration
114+ */
115+ export const assertRunnableOptions = config => {
116+ if ( ! config . target || ! config . global ?. input ) {
117+ throw new Error (
118+ 'Both a `target` and an `input` must be provided, either via ' +
119+ '`--target`/`--input` or a `--config-file`. ' +
120+ 'Run `doc-kit generate --help` for usage.'
121+ ) ;
122+ }
123+ } ;
124+
107125/**
108126 * Creates a complete run configuration by merging config file, user options, and defaults.
109127 * Processes and validates configuration values including version coercion, changelog parsing,
You can’t perform that action at this time.
0 commit comments