Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #90 from TheFruxz/feature/consoleInputSyntaxIssue
Browse files Browse the repository at this point in the history
Feature: syntaxIssue custom process
  • Loading branch information
TheFruxz authored Dec 4, 2021
2 parents 0a634b7 + 9575461 commit dec802d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ConsoleInterchange(
override val path: String,
override val branches: List<ConsoleStructureBranch>,
override val content: ((parameters: List<String>) -> Unit)? = null,
val syntaxIssue: ((parameters: List<String>) -> Unit)? = null,
) : ConsoleInterchangeStructure<ConsoleStructureBranch>(identity) {

fun performInterchange(input: String): Boolean {
Expand All @@ -33,6 +34,7 @@ class ConsoleInterchange(
var path: String,
var branches: MutableList<ConsoleStructureBranch> = mutableListOf(),
var content: ((parameters: List<String>) -> Unit)? = null,
var syntaxIssue: ((parameters: List<String>) -> Unit)? = null,
) : Producible<ConsoleInterchange> {

operator fun plus(branch: ConsoleStructureBranch) = apply {
Expand All @@ -47,6 +49,10 @@ class ConsoleInterchange(
this.content = content
}

fun onSyntaxIssue(syntaxIssue: ((parameters: List<String>) -> Unit)?) = apply {
this.syntaxIssue = syntaxIssue
}

override fun produce() = ConsoleInterchange(
identity, path, branches, content
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ fun requestTerminalInterchangeInput(vararg interchanges: ConsoleInterchange) {
}

if (call != null) {
val inputParameters = input.split(" ").drop(1)
if (!call.performInterchange(inputParameters.joinToString(" "))) {
val syntaxIssueReaction = call.syntaxIssue

if (syntaxIssueReaction != null) {
syntaxIssueReaction(inputParameters)
} else {
println("No response from interchange, seems that your input-syntax was wrong, try again!")
}

if (!call.performInterchange(input.split(" ").drop(1).joinToString(" "))) {
println("No response from interchange, seems that your input-syntax was wrong, try again!")
}

} else {
Expand Down

0 comments on commit dec802d

Please sign in to comment.