optional cli arguments against selector

This commit is contained in:
Danya H 2024-06-13 19:26:30 +01:00
parent 839dff9b78
commit 1fd65c6b86
2 changed files with 54 additions and 27 deletions

View File

@ -1,33 +1,59 @@
import type { CommandModule, ArgumentsCamelCase } from 'yargs' import type { CommandModule, Argv, ArgumentsCamelCase } from 'yargs'
import c from 'chalk' import c from 'chalk'
import { input, select } from '@inquirer/prompts' import { input, select } from '@inquirer/prompts'
import clone from 'git-clone' import clone from 'git-clone'
import path from 'node:path' import path from 'node:path'
// the handler function will be called when our command is executed function builder(yargs: Argv) {
// it will receive the command line arguments parsed by yargs return yargs
async function handler() { .option('projectName', {
const folder = await input({ alias: 'p',
message: c.gray('Enter project name:'), description: 'Name of the folder to scaffold a project to',
default: 'rage-fw', type: 'string',
}) demandOption: false,
const framework = await select({ })
message: c.gray('Select frontend:'), .option('template', {
default: 'react', alias: 't',
loop: true, description: 'Frontend framework to use for CEF',
choices: [ type: 'string',
{ demandOption: false,
name: 'React + TypeScript (Vite)', })
value: 'react', }
description: 'React + TypeScript (Vite) as a frontend',
}, async function handler(args: ArgumentsCamelCase) {
// { let folder = (args.projectName as string) ?? args.p
// name: 'vue', let framework = (args.template as string) ?? args.t
// value: 'vue',
// description: 'npm is the most popular package manager', if (!folder) {
// }, folder = await input({
], message: c.gray('Enter project name:'),
}) default: 'rage-fw',
})
} else {
console.log(c.gray('Project name:'), folder)
}
if (!framework) {
framework = await select({
message: c.gray('Select frontend:'),
default: 'react',
loop: true,
choices: [
{
name: 'React + TypeScript (Vite)',
value: 'react',
description: 'React + TypeScript (Vite) as a frontend',
},
// {
// name: 'vue',
// value: 'vue',
// description: 'npm is the most popular package manager',
// },
],
})
} else {
console.log(c.gray('Frontend:'), framework)
}
console.log( console.log(
c.gray('\nScaffolding template project into'), c.gray('\nScaffolding template project into'),
@ -56,11 +82,11 @@ async function handler() {
) )
} }
// name and description for our command module
const init: CommandModule = { const init: CommandModule = {
command: 'create [template]', command: 'create [folderName] [template]',
aliases: 'c', aliases: 'c',
describe: 'Scaffold a template project using RageFW', describe: 'Scaffold a template project using RageFW',
builder,
handler, handler,
} }

View File

@ -6,5 +6,6 @@ yargs
.usage('<cmd> [args]') .usage('<cmd> [args]')
// .scriptName('rage-fw') // .scriptName('rage-fw')
// .usage('$0 <cmd> [args]') // .usage('$0 <cmd> [args]')
// @ts-ignore
.command(create) .command(create)
.help().argv .help().argv