Skip to content

Commit

Permalink
Merge pull request #468 from nimblehq/chore/437-add-red-cross-emoji-t…
Browse files Browse the repository at this point in the history
…o-error-messages-when-new_projectkts-fails

[#437] Add red cross emoji to error messages when new_project.kts fails
  • Loading branch information
ryan-conway authored May 30, 2023
2 parents 1d2e496 + da7e1c4 commit 31e1269
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions scripts/new_project.kts
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,27 @@ object NewProject {
else -> {
showMessage(
message = "ERROR: Invalid argument name: $arg \n$helpMessage",
exitAfterMessage = true
exitAfterMessage = true,
isError = true,
)
}
}
}
when {
!hasAppName -> showMessage(
message = "ERROR: No app name has been provided \n$helpMessage",
exitAfterMessage = true
exitAfterMessage = true,
isError = true,
)
!hasPackageName -> showMessage(
message = "ERROR: No package name has been provided \n$helpMessage",
exitAfterMessage = true
exitAfterMessage = true,
isError = true,
)
!hasTemplate -> showMessage(
message = "ERROR: No template has been provided \n$helpMessage",
exitAfterMessage = true
exitAfterMessage = true,
isError = true,
)
}
}
Expand All @@ -171,7 +175,8 @@ object NewProject {
} else {
showMessage(
message = "ERROR: Invalid App Name: $value (needs to follow standard pattern {MyProject} or {My Project}) or {my-project} \n$helpMessage",
exitAfterMessage = true
exitAfterMessage = true,
isError = true,
)
}
}
Expand All @@ -181,8 +186,9 @@ object NewProject {
packageName = value.trim()
} else {
showMessage(
message = "ERROR: Invalid Package Name: $value (needs to follow standard pattern {com.example.package}) \n$helpMessage",
exitAfterMessage = true
message = "Error: Invalid Package Name: $value (needs to follow standard pattern {com.example.package}) \n$helpMessage",
exitAfterMessage = true,
isError = true,
)
}
}
Expand All @@ -192,8 +198,9 @@ object NewProject {
template = value.trim()
} else {
showMessage(
message = "ERROR: Invalid Template: $value (can either be $TEMPLATE_XML or $TEMPLATE_COMPOSE) \n$helpMessage",
exitAfterMessage = true
message = "Error: Invalid Template: $value (can either be $TEMPLATE_XML or $TEMPLATE_COMPOSE) \n$helpMessage",
exitAfterMessage = true,
isError = true,
)
}
}
Expand Down Expand Up @@ -305,7 +312,10 @@ object NewProject {
val targetFolder = File(toPath)
val sourceFolder = File(fromPath)
sourceFolder.copyRecursively(targetFolder, true) { file, exception ->
showMessage(exception?.message ?: "Error copying files")
showMessage(
message = "${exception?.message ?: "Error copying files"}",
isError = true,
)
return@copyRecursively OnErrorAction.TERMINATE
}
}
Expand All @@ -329,9 +339,10 @@ object NewProject {
val exitValue = process.waitFor()
if (exitValue != 0) {
showMessage(
message = "Something went wrong! when executing command: ${command.joinToString(" ")}",
message = "Something went wrong! when executing command: ${command.joinToString(" ")}",
exitAfterMessage = true,
exitValue = exitValue
exitValue = exitValue,
isError = true,
)
}
}
Expand Down Expand Up @@ -360,9 +371,10 @@ object NewProject {
private fun showMessage(
message: String,
exitAfterMessage: Boolean = false,
exitValue: Int = 0
exitValue: Int = 0,
isError: Boolean = false,
) {
println("\n${message}\n")
println("\n${if (isError) "" else ""}${message}\n")
if (exitAfterMessage) System.exit(exitValue)
}

Expand Down

0 comments on commit 31e1269

Please sign in to comment.