diff --git a/README.md b/README.md index dd029a1..148a2de 100644 --- a/README.md +++ b/README.md @@ -30,5 +30,5 @@ As of the `0.8.0` release, example apps for testing are included when initializi --author ......... Author name and email (e.g. "Name ") --license ............ SPDX License ID (e.g. "MIT") --description ...... Short description of plugin features ---android-lang ..... Language for Android plugin development (either "kotlin" or "java") +--android-lang ..... Language for Android plugin development (either "kotlin" or "java", default is "java") ``` diff --git a/src/help.ts b/src/help.ts index df38983..726ff7f 100644 --- a/src/help.ts +++ b/src/help.ts @@ -10,7 +10,7 @@ const help = ` --author ......... Author name and email (e.g. "Name ") --license ............ SPDX License ID (e.g. "MIT") --description ...... Short description of plugin features - --android-lang ............ Language for Android plugin development (either "kotlin" or "java") + --android-lang ............ Language for Android plugin development (either "kotlin" or "java", default is "java") -h, --help ................ Print help, then quit --verbose ................. Print verbose output to stderr diff --git a/src/options.ts b/src/options.ts index e15a25d..7f296a0 100644 --- a/src/options.ts +++ b/src/options.ts @@ -68,7 +68,7 @@ export const VALIDATORS: Validators = { description: (value) => typeof value !== 'string' || value.trim().length === 0 ? `Must provide a description` : true, 'android-lang': (value) => - typeof value === 'string' && value.trim().length > 0 && /^(kotlin|kt|java)$/i.test(value) + value === undefined || value === '' || (typeof value === 'string' && /^(kotlin|java)$/i.test(value)) ? true : `Must be either "kotlin" or "java"`, dir: (value) => @@ -99,6 +99,12 @@ export const getOptions = (): Options => { if (typeof validatorResult === 'string') { debug(`invalid option: --%s %O: %s`, option, value, validatorResult); + + // 'android-lang' is not prompted, so it should fail if invalid + if (option === 'android-lang') { + process.stderr.write(`ERR: Invalid --android-lang value "${value}": ${validatorResult}\n`); + process.exit(1); + } } opts[option] = validatorResult === true ? value : undefined; @@ -106,5 +112,11 @@ export const getOptions = (): Options => { return opts; }, {} as Options); - return { ...argValues, ...optionValues }; + const allOptions = { ...argValues, ...optionValues }; + + if (!allOptions['android-lang']) { + allOptions['android-lang'] = 'java'; + } + + return allOptions; }; diff --git a/src/prompt.ts b/src/prompt.ts index 3249d95..4fb5b75 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -82,15 +82,6 @@ export const gatherDetails = (initialOptions: Options): Promise => message: `Enter a SPDX license identifier for your plugin.\n`, validate: VALIDATORS.license, }, - { - type: 'select', - name: 'android-lang', - message: `What language would you like to use for your Android plugin?\n`, - choices: [ - { title: 'Kotlin', value: 'kotlin' }, - { title: 'Java', value: 'java' }, - ], - }, { type: 'text', name: 'description', @@ -105,5 +96,11 @@ export const gatherDetails = (initialOptions: Options): Promise => process.exit(1); }, }, + ).then( + (result) => + ({ + ...result, + 'android-lang': initialOptions['android-lang'], + }) as OptionValues, ); };