1- import { getAdditionByName , getAvailableAdditions , runAddition } from '../additions/manager.js' ;
1+ import {
2+ AdditionOptions ,
3+ getAdditionByName ,
4+ getAdditionFlags ,
5+ getAvailableAdditions ,
6+ parseAdditionFlags ,
7+ runAddition ,
8+ } from '../additions/manager.js' ;
29import { isGitDirectory , isGitDirectoryClean } from '../utils/utils.git.js' ;
310
411import { isPluginDirectory } from '../utils/utils.plugin.js' ;
512import minimist from 'minimist' ;
613import { output } from '../utils/utils.console.js' ;
7- import { promptI18nOptions } from './add/prompts.js' ;
814
915export const add = async ( argv : minimist . ParsedArgs ) => {
1016 const subCommand = argv . _ [ 1 ] ;
1117
1218 if ( ! subCommand ) {
1319 const availableAdditions = getAvailableAdditions ( ) ;
14- const additionsList = Object . values ( availableAdditions ) . map (
15- ( addition ) => `${ addition . name } - ${ addition . description } `
20+ const additionsList = await Promise . all (
21+ Object . values ( availableAdditions ) . map ( async ( addition ) => {
22+ let info = `${ addition . name } - ${ addition . description } ` ;
23+ const flags = await getAdditionFlags ( addition ) ;
24+ if ( flags . length > 0 ) {
25+ const flagDocs = flags . map ( ( flag ) => {
26+ const req = flag . required ? ' (required)' : ' (optional)' ;
27+ return ` --${ flag . name } : ${ flag . description } ${ req } ` ;
28+ } ) ;
29+ info += '\n' + flagDocs . join ( '\n' ) ;
30+ }
31+ return info ;
32+ } )
1633 ) ;
1734
1835 output . error ( {
1936 title : 'No addition specified' ,
2037 body : [
21- 'Usage: npx @grafana/create-plugin add <addition-name>' ,
38+ 'Usage: npx @grafana/create-plugin add <addition-name> [options] ' ,
2239 '' ,
2340 'Available additions:' ,
2441 ...output . bulletList ( additionsList ) ,
@@ -43,16 +60,11 @@ export const add = async (argv: minimist.ParsedArgs) => {
4360 }
4461
4562 try {
46- // Gather options based on the addition type
47- let options = { } ;
48-
49- switch ( addition . name ) {
50- case 'i18n' :
51- options = await promptI18nOptions ( ) ;
52- break ;
53- default :
54- break ;
55- }
63+ // Parse addition-specific options from argv flags using the addition's own parser
64+ const options = await parseAdditionFlags ( addition , argv ) ;
65+
66+ // Validate required flags
67+ await validateAdditionOptions ( addition , options ) ;
5668
5769 const commitChanges = argv . commit ;
5870 await runAddition ( addition , options , { commitChanges } ) ;
@@ -67,6 +79,43 @@ export const add = async (argv: minimist.ParsedArgs) => {
6779 }
6880} ;
6981
82+ async function validateAdditionOptions ( addition : any , options : AdditionOptions ) : Promise < void > {
83+ const flags = await getAdditionFlags ( addition ) ;
84+
85+ if ( ! flags || flags . length === 0 ) {
86+ return ;
87+ }
88+
89+ const missingFlags : string [ ] = [ ] ;
90+
91+ for ( const flag of flags ) {
92+ if ( flag . required ) {
93+ const value = options [ flag . name ] ;
94+ if ( value === undefined || value === null || ( Array . isArray ( value ) && value . length === 0 ) ) {
95+ missingFlags . push ( flag . name ) ;
96+ }
97+ }
98+ }
99+
100+ if ( missingFlags . length > 0 ) {
101+ const flagDocs = flags
102+ . filter ( ( f : any ) => missingFlags . includes ( f . name ) )
103+ . map ( ( f : any ) => ` --${ f . name } : ${ f . description } ` ) ;
104+
105+ output . error ( {
106+ title : `Missing required flag${ missingFlags . length > 1 ? 's' : '' } ` ,
107+ body : [
108+ `The following required flag${ missingFlags . length > 1 ? 's are' : ' is' } missing:` ,
109+ '' ,
110+ ...flagDocs ,
111+ '' ,
112+ `Example: npx @grafana/create-plugin add ${ addition . name } --${ missingFlags [ 0 ] } =value` ,
113+ ] ,
114+ } ) ;
115+ process . exit ( 1 ) ;
116+ }
117+ }
118+
70119async function performPreAddChecks ( argv : minimist . ParsedArgs ) {
71120 if ( ! ( await isGitDirectory ( ) ) && ! argv . force ) {
72121 output . error ( {
0 commit comments