Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech/3483/integrate kotter #3609

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
82f8c52
Built first function with kotter
Nereboss Jan 15, 2024
b87a411
Fix import format and unused imports
phanlezz Jan 22, 2024
c5c51cf
Refactor Inquirer into own module #3483
Nereboss Jan 23, 2024
d68cb18
Add inputNumber function #3483
Nereboss Jan 23, 2024
543fab1
Add promptConfirm function #3483
Nereboss Jan 23, 2024
95a3622
Add promptList function #3483
Nereboss Jan 23, 2024
299e3ae
Add promptCheckbox function #3483
Nereboss Jan 23, 2024
5be202f
Refactor inquirer functions #3483
Nereboss Jan 24, 2024
99d9a49
Test Inquirer on StructureModifier; WIP Commit #3483
Nereboss Feb 2, 2024
1407f45
Update Kotter version #3483
Nereboss Feb 20, 2024
c2f66ef
Add text for invalid input in checkbox-function #3483
Nereboss Feb 21, 2024
8dad8fa
Changed PromptConfirm to color-code the selection #3483
Nereboss Feb 21, 2024
6921374
Improve error handling for promptInput #3483
Nereboss Feb 21, 2024
6b2f9fb
Add test file for Inquirer #3483
Nereboss Mar 11, 2024
c27c0b3
Refactor Inquirer and add testing module for it #3483
Nereboss Mar 14, 2024
0ee393f
Fix a bug that invalidInputMessages were not displayed anymore #3483
Nereboss Mar 14, 2024
7ce8c04
Add callback for promptConfirm and write first test #3483
Nereboss Mar 15, 2024
bedd3b1
Add public API and a variety of tests#3483
Nereboss Mar 20, 2024
458f4be
Fix test for warning message in promptInput #3483
Nereboss Apr 8, 2024
dad62c5
Refactor test for warning message and add more #3483
Nereboss Apr 11, 2024
5857aa3
Add last remaining test #3483
Nereboss Apr 11, 2024
2ea5a8b
Push temporary kotter test #3456
Nereboss Apr 30, 2024
69d8b83
Add remaining Kotter Tests to modify
phanlezz May 3, 2024
7913afe
Small code style fixes #3456
Nereboss May 6, 2024
11807b5
Add build gradle and format
phanlezz May 6, 2024
24af888
Add test functions and tests to help debug flaky tests #3483
Nereboss May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions analysis/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ buildscript {
mavenCentral()
maven(url = "https://plugins.gradle.org/m2/")
maven(url = "https://jitpack.io")
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}

Expand Down
3 changes: 3 additions & 0 deletions analysis/filter/StructureModifier/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
dependencies {
implementation(project(":model"))
implementation(project(":tools:InteractiveParser"))
implementation(project(":tools:Inquirer"))

implementation(libs.picocli)
implementation(libs.kotlin.inquirer)
implementation(libs.kotter)
implementation(libs.kotter.test)

testImplementation(libs.kotlin.test)
testImplementation(libs.junit.jupiter.api)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,92 +1,148 @@
package de.maibornwolff.codecharta.filter.structuremodifier

import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptInput
import com.github.kinquirer.components.promptInputNumber
import com.github.kinquirer.components.promptList
import com.varabyte.kotter.foundation.session
import com.varabyte.kotter.runtime.RunScope
import com.varabyte.kotter.runtime.Session
import de.maibornwolff.codecharta.tools.inquirer.myPromptInput
import de.maibornwolff.codecharta.tools.inquirer.myPromptInputNumber
import de.maibornwolff.codecharta.tools.inquirer.myPromptList
import de.maibornwolff.codecharta.tools.inquirer.testFun1
import de.maibornwolff.codecharta.tools.inquirer.testFun2
import de.maibornwolff.codecharta.tools.inquirer.util.InputValidator
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import de.maibornwolff.codecharta.util.InputHelper
import java.io.File
import java.math.BigDecimal
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {
override fun collectParserArgs(): List<String> {
var inputFileName: String
do {
inputFileName =
KInquirer.promptInput(
message = "What is the cc.json file that has to be modified?",
hint = Paths.get("").toAbsolutePath().toString() + File.separator + "yourInput.cc.json",
)
} while (!InputHelper.isInputValidAndNotNull(arrayOf(File(inputFileName)), canInputContainFolders = false))
var res = listOf<String>()
session { res = myCollectParserArgs() }
return res
}

val selectedAction: String =
KInquirer.promptList(
message = "Which action do you want to perform?",
choices =
listOf(
StructureModifierAction.PRINT_STRUCTURE.descripton,
StructureModifierAction.SET_ROOT.descripton,
StructureModifierAction.MOVE_NODES.descripton,
StructureModifierAction.REMOVE_NODES.descripton,
),
)
fun Session.callTestFun(
callback1: suspend RunScope.() -> Unit = {},
callback2: suspend RunScope.() -> Unit = {},
): String {
val result1: String =
testFun1(
// message = "any test meessage",
callback = callback1,
)
val result2: String =
testFun2(
callback = callback2,
)

return when (selectedAction) {
StructureModifierAction.PRINT_STRUCTURE.descripton -> listOf(inputFileName, *collectPrintArguments())
StructureModifierAction.SET_ROOT.descripton -> listOf(inputFileName, *collectSetRootArguments())
StructureModifierAction.MOVE_NODES.descripton ->
listOf(
inputFileName,
*collectMoveNodesArguments(),
)
return result1 + result2
}

// TODO: check if its a problem that this is in a companion object
internal fun Session.myCollectParserArgs(
fileCallback: suspend RunScope.() -> Unit = {},
actionCallback: suspend RunScope.() -> Unit = {},
printCallback: suspend RunScope.() -> Unit = {},
setRootCallback: suspend RunScope.() -> Unit = {},
moveFromCallback: suspend RunScope.() -> Unit = {},
moveToCallback: suspend RunScope.() -> Unit = {},
removeNodesCallback: suspend RunScope.() -> Unit = {},
outFileCallback: suspend RunScope.() -> Unit = {},
): List<String> {
val result: List<String>

StructureModifierAction.REMOVE_NODES.descripton ->
val inputFileName: String =
myPromptInput(
message = "What is the cc.json file that should be modified?",
hint = Paths.get("").toAbsolutePath().toString() + File.separator + "yourInput.cc.json",
invalidInputMessage = "Please input a valid cc.json file!",
inputValidator = InputValidator.isInputAnExistingFile("cc.json", "cc.json.gz"),
onInputReady = fileCallback,
)

val selectedAction: String =
myPromptList(
message = "Which action do you want to perform?",
choices =
listOf(
inputFileName,
*collectRemoveNodesArguments(),
)
StructureModifierAction.PRINT_STRUCTURE.descripton,
StructureModifierAction.SET_ROOT.descripton,
StructureModifierAction.MOVE_NODES.descripton,
StructureModifierAction.REMOVE_NODES.descripton,
),
onInputReady = actionCallback,
)

result =
when (selectedAction) {
StructureModifierAction.PRINT_STRUCTURE.descripton -> listOf(inputFileName, *collectPrintArguments(printCallback))
StructureModifierAction.SET_ROOT.descripton -> listOf(inputFileName, *collectSetRootArguments(setRootCallback, outFileCallback))
StructureModifierAction.MOVE_NODES.descripton -> listOf(inputFileName, *collectMoveNodesArguments(moveFromCallback, moveToCallback, outFileCallback))
StructureModifierAction.REMOVE_NODES.descripton -> listOf(inputFileName, *collectRemoveNodesArguments(removeNodesCallback, outFileCallback))
else -> listOf()
}
return result
}
}
}

private fun collectPrintArguments(): Array<String> {
val printLevels: BigDecimal =
KInquirer.promptInputNumber(
message = "How many print levels do you want to print?", default = "0",
hint = "0",
)
return arrayOf("--print-levels=$printLevels")
}
private fun Session.collectPrintArguments(printCallback: suspend RunScope.() -> Unit): Array<String> {
val printLevels: String =
myPromptInputNumber(
message = "How many print levels do you want to print?", hint = "0",
onInputReady = printCallback,
)
return arrayOf("--print-levels=$printLevels")
}

private fun collectSetRootArguments(): Array<String> {
val setRoot: String =
KInquirer.promptInput(message = "What path within the project should be extracted as the new root?")
val outputFileName = collectOutputFileName()
return arrayOf("--set-root=$setRoot", "--output-file=$outputFileName")
}
private fun Session.collectSetRootArguments(
setRootCallback: suspend RunScope.() -> Unit,
outFileCallback: suspend RunScope.() -> Unit,
): Array<String> {
val setRoot: String =
myPromptInput(
message = "What path within the project should be extracted as the new root?",
onInputReady = setRootCallback,
)
val outputFileName = collectOutputFileName(outFileCallback)
return arrayOf("--set-root=$setRoot", "--output-file=$outputFileName")
}

private fun collectMoveNodesArguments(): Array<String> {
val moveFrom: String =
KInquirer.promptInput(
message = "What path should be moved (contained children will be moved as well)?",
)
val moveTo: String = KInquirer.promptInput(message = "What is the target path to move them?")
val outputFileName = collectOutputFileName()
return arrayOf("--move-from=$moveFrom", "--move-to=$moveTo", "--output-file=$outputFileName")
}
private fun Session.collectMoveNodesArguments(
moveFromCallback: suspend RunScope.() -> Unit,
moveToCallback: suspend RunScope.() -> Unit,
outFileCallback: suspend RunScope.() -> Unit,
): Array<String> {
val moveFrom: String =
myPromptInput(
message = "What path should be moved (contained children will be moved as well)?",
onInputReady = moveFromCallback,
)
val moveTo: String =
myPromptInput(
message = "What is the target path to move them?",
onInputReady = moveToCallback,
)
val outputFileName = collectOutputFileName(outFileCallback)
return arrayOf("--move-from=$moveFrom", "--move-to=$moveTo", "--output-file=$outputFileName")
}

private fun collectRemoveNodesArguments(): Array<String> {
val remove: String = KInquirer.promptInput(message = "What are the paths of the nodes to be removed?")
val outputFileName = collectOutputFileName()
return arrayOf("--remove=$remove", "--output-file=$outputFileName")
}
private fun Session.collectRemoveNodesArguments(
removeNodesCallback: suspend RunScope.() -> Unit,
outFileCallback: suspend RunScope.() -> Unit,
): Array<String> {
val remove: String =
myPromptInput(
message = "What are the paths of the nodes to be removed?",
onInputReady = removeNodesCallback,
)
val outputFileName = collectOutputFileName(outFileCallback)
return arrayOf("--remove=$remove", "--output-file=$outputFileName")
}

private fun collectOutputFileName(): String {
return KInquirer.promptInput(message = "What is the name of the output file?")
}
}
private fun Session.collectOutputFileName(outFileCallback: suspend RunScope.() -> Unit): String {
return myPromptInput(
message = "What is the name of the output file?",
onInputReady = outFileCallback,
)
}
Loading
Loading