@@ -21,6 +21,7 @@ import com.haulmont.cuba.cli.ModuleStructure.Companion.CORE_MODULE
2121import com.haulmont.cuba.cli.ModuleStructure.Companion.WEB_MODULE
2222import com.haulmont.cuba.cli.PrintHelper
2323import com.haulmont.cuba.cli.commands.GeneratorCommand
24+ import com.haulmont.cuba.cli.commands.NonInteractiveInfo
2425import com.haulmont.cuba.cli.cubaplugin.CubaPlugin
2526import com.haulmont.cuba.cli.generation.Properties
2627import com.haulmont.cuba.cli.generation.Snippets
@@ -33,7 +34,7 @@ import org.kodein.di.generic.instance
3334import java.nio.file.Path
3435
3536@Parameters(commandDescription = " Generates app-component.xml" )
36- class AppComponentCommand : GeneratorCommand <AppComponentModel >() {
37+ class AppComponentCommand : GeneratorCommand <AppComponentModel >(), NonInteractiveInfo {
3738 private val messages by localMessages()
3839
3940 private val printHelper: PrintHelper by kodein.instance()
@@ -48,30 +49,44 @@ class AppComponentCommand : GeneratorCommand<AppComponentModel>() {
4849
4950 override fun getModelName (): String = AppComponentModel .MODEL_NAME
5051
52+ override fun getNonInteractiveParameters (): Map <String , String > = mapOf (
53+ " modulePrefix" to " If specified, changes module prefix for project"
54+ )
55+
5156 override fun QuestionsList.prompting () {
52- if (projectModel.modulePrefix == " app" ) {
57+ if (isNonInteractiveMode()) {
58+ askPrefix(projectModel.modulePrefix)
59+ } else if (projectModel.modulePrefix == " app" ) {
5360 confirmation(" changePrefix" , messages[" changePrefix" ])
5461
55- question(" modulePrefix" , " New prefix" ) {
56- askIf(" changePrefix" )
62+ askPrefix()
63+ }
64+ }
65+
66+ private fun QuestionsList.askPrefix (defaultPrefix : String? = null) {
67+ question(" modulePrefix" , " New prefix" ) {
68+ askIf(" changePrefix" )
69+
70+ defaultPrefix?.let {
71+ default(it)
72+ }
5773
58- validate {
59- if (value.isBlank())
60- fail(" Empty project prefix is not allowed" )
74+ validate {
75+ if (value.isBlank())
76+ fail(" Empty project prefix is not allowed" )
6177
62- val invalidNameRegex = Regex (" [^\\ w\\ -]" )
78+ val invalidNameRegex = Regex (" [^\\ w\\ -]" )
6379
64- if (invalidNameRegex.find(value) != null ) {
65- fail(" Project name should contain only Latin letters, digits, dashes and underscores." )
66- }
80+ if (invalidNameRegex.find(value) != null ) {
81+ fail(" Project name should contain only Latin letters, digits, dashes and underscores." )
6782 }
6883 }
6984 }
7085 }
7186
7287 override fun createModel (answers : Answers ): AppComponentModel {
7388 val modulePrefix: String = answers[" modulePrefix" ] as String? ? : projectModel.modulePrefix
74- val changePrefix = answers[ " changePrefix " ] as Boolean? ? : false
89+ val changePrefix = modulePrefix != projectModel.modulePrefix
7590 return AppComponentModel (changePrefix, modulePrefix)
7691 }
7792
0 commit comments