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

Feature/3274/use-current-directory-if-input-empty #3319

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

- Add metric tooltips that display attribute descriptors and provide hyperlinks in the sidebar to the metric's documentation [#3273](https://github.com/MaibornWolff/codecharta/pull/3273) </br>
<img src="https://user-images.githubusercontent.com/65733509/241383211-d9e8e54b-6b06-45bb-8b99-81cc8e0a4596.png" width="450px"/> <img src="https://github.com/MaibornWolff/codecharta/assets/65733509/0ade9ad4-e60b-4911-aadc-d8142167b21a" width="300px"/>
- Add current working directors as hint or default value to interactive parser when asking for input [#3319](https://github.com/MaibornWolff/codecharta/pull/3319)

## [1.117.0] - 2023-05-19

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import com.github.kinquirer.components.promptInput
import com.github.kinquirer.components.promptInputNumber
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.math.BigDecimal
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {
override fun collectParserArgs(): List<String> {
val inputFileName = KInquirer.promptInput(
message = "What is the cc.json file that has to be parsed?",
hint = Paths.get("").toAbsolutePath().toString()
moritz-suckow-mw marked this conversation as resolved.
Show resolved Hide resolved
)

val defaultOutputFileName = getOutputFileName(inputFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import mu.KotlinLogging
import java.nio.file.Paths

private val logger = KotlinLogging.logger {}

Expand All @@ -13,7 +14,9 @@ class ParserDialog {

override fun collectParserArgs(): List<String> {

val inputFileName = KInquirer.promptInput(message = "What is the $EXTENSION file that has to be parsed?")
val inputFileName = KInquirer.promptInput(
message = "What is the $EXTENSION file that has to be parsed?",
hint = Paths.get("").toAbsolutePath().toString())
moritz-suckow-mw marked this conversation as resolved.
Show resolved Hide resolved
logger.info { "File path: $inputFileName" }

val defaultOutputFileName = getOutputFileName(inputFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptConfirm
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {

override fun collectParserArgs(): List<String> {

val inputFolderName =
KInquirer.promptInput(message = "What is the folder of cc.json files that has to be merged?")
KInquirer.promptInput(
message = "What is the folder of cc.json files that has to be merged?",
default = Paths.get("").toAbsolutePath().toString())

val outputFileName: String = KInquirer.promptInput(
message = "What is the name of the output file?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import com.github.kinquirer.components.promptInput
import com.github.kinquirer.components.promptInputNumber
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.math.BigDecimal
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {

override fun collectParserArgs(): List<String> {
val inputFolderName =
KInquirer.promptInput(message = "What is the cc.json file that has to be modified?")
KInquirer.promptInput(
message = "What is the cc.json file that has to be modified?",
hint = Paths.get("").toAbsolutePath().toString())
moritz-suckow-mw marked this conversation as resolved.
Show resolved Hide resolved

val outputFileName: String = KInquirer.promptInput(
message = "What is the name of the output file?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@ package de.maibornwolff.codecharta.importer.csv
import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptConfirm
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.importer.util.ParserDialogHelper
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface

class ParserDialog {
companion object : ParserDialogInterface {

override fun collectParserArgs(): List<String> {
val inputFileNames = mutableListOf(KInquirer.promptInput(
message = "Please specify the name of the first sourcemonitor CSV file to be parsed:",
hint = "input.csv"
))
while (true) {
val additionalFile = KInquirer.promptInput(
message = "If you want to parse additional sourcemonitor CSV files, specify the name of the next file. Otherwise, leave this field empty to skip.",
)
if (additionalFile.isNotBlank()) {
inputFileNames.add(additionalFile)
} else {
break
}
}
val inputFileNames = ParserDialogHelper.getInputFiles(false)

val outputFileName: String = KInquirer.promptInput(
message = "What is the name of the output file?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@ package de.maibornwolff.codecharta.importer.sourcemonitor
import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptConfirm
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.importer.util.ParserDialogHelper
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface

class ParserDialog {
companion object : ParserDialogInterface {

override fun collectParserArgs(): List<String> {
val inputFileNames = mutableListOf(KInquirer.promptInput(
message = "What is the sourcemonitor CSV file that has to be parsed?",
hint = "sourcemonitor.csv"
))
while (true) {
val additionalFile = KInquirer.promptInput(
message = "If you want to parse additional sourcemonitor CSV files, specify the name of the next file. Otherwise, leave this field empty to skip.",
)
if (additionalFile.isNotBlank()) {
inputFileNames.add(additionalFile)
} else {
break
}
}
val inputFileNames = ParserDialogHelper.getInputFiles(true)

val outputFileName: String = KInquirer.promptInput(
message = "What is the name of the output file?",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.maibornwolff.codecharta.importer.util

import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptInput
import java.io.File
import java.nio.file.Paths

class ParserDialogHelper {

companion object {
fun getInputFiles(isSourceMonitor: Boolean): MutableList<String> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made this class to avoid some duplication, only thing new here is the KInquirer hint.

val inputFileNames = mutableListOf(KInquirer.promptInput(
message = if (isSourceMonitor) { "What is the sourcemonitor CSV file that has to be parsed?" } else { "Please specify the name of the first sourcemonitor CSV file to be parsed" },
moritz-suckow-mw marked this conversation as resolved.
Show resolved Hide resolved
hint = Paths.get("").toAbsolutePath().toString() + File.separator + "yourInput.csv"))

while (true) {
val additionalFile = KInquirer.promptInput(
message = "If you want to parse additional sourcemonitor CSV files, specify the name of the next file. Otherwise, leave this field empty to skip.",
moritz-suckow-mw marked this conversation as resolved.
Show resolved Hide resolved
)
if (additionalFile.isNotBlank()) {
inputFileNames.add(additionalFile)
} else {
break
}
}

return inputFileNames
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptConfirm
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.io.File
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {
Expand All @@ -13,8 +15,8 @@ class ParserDialog {
val defaultInputFileName = "edges.$EXTENSION"
val inputFileName = KInquirer.promptInput(
message = "What is the $EXTENSION file that has to be parsed?",
hint = defaultInputFileName,
default = defaultInputFileName
hint = Paths.get("").toAbsolutePath().toString() + File.separator + defaultInputFileName,
default = Paths.get("").toAbsolutePath().toString() + File.separator + defaultInputFileName
)

val defaultOutputFileName = getOutputFileName(inputFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package de.maibornwolff.codecharta.importer.gitlogparser.subcommands
import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.io.File
import java.nio.file.Paths

class LogScanParserDialog {
companion object : ParserDialogInterface {
Expand All @@ -11,12 +13,14 @@ class LogScanParserDialog {

print("You can generate this file with: git log --numstat --raw --topo-order --reverse -m > git.log")
val gitLogFile = KInquirer.promptInput(
message = "What is the git.log file that has to be parsed?", hint = "path/to/git.log"
message = "What is the git.log file that has to be parsed?",
hint = Paths.get("").toAbsolutePath().toString() + File.separator + "git.log"
)

print("You can generate this file with: git ls-files > file-name-list.txt")
val gitLsFile = KInquirer.promptInput(
message = "What is the path to the file name list?", hint = "path/to/file-name-list.txt"
message = "What is the path to the file name list?",
hint = Paths.get("").toAbsolutePath().toString() + File.separator + "file-name-list.txt"
)

return listOfNotNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package de.maibornwolff.codecharta.importer.gitlogparser.subcommands
import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.nio.file.Paths

class RepoScanParserDialog {
companion object : ParserDialogInterface {
Expand All @@ -11,7 +12,7 @@ class RepoScanParserDialog {

val repoPath = KInquirer.promptInput(
message = "What is the root directory of the git project you want to parse? If empty, \".\" is assumed",
hint = "path/to/repo/root"
default = Paths.get("").toAbsolutePath().toString()
)

return listOfNotNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptConfirm
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.io.File
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {
Expand All @@ -18,7 +20,7 @@ class ParserDialog {
val inputFile = KInquirer.promptInput(
message = if (isJsonFile) "Which MetricGardener json-File do you want to import?"
else "What Project do you want to parse?",
hint = if (isJsonFile) "path/to/metricgardener/file.json" else "path/to/my/project"
hint = if (isJsonFile) { Paths.get("").toAbsolutePath().toString() + File.separator + "file.json" } else Paths.get("").toAbsolutePath().toString()
)

val outputFileName: String = KInquirer.promptInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ class MetricGardenerImporterTest {
return listOf(
Arguments.of("src/test/resources/my/supported-multi-language/repo"),
Arguments.of("src/test/resources/my/supported-multi-language/repo/dummyFile.js"),
Arguments.of("src/test/resources/my"),
Arguments.of(""))
Arguments.of("src/test/resources/my"))
}

@JvmStatic
fun provideInvalidInputFiles(): List<Arguments> {
return listOf(
Arguments.of("src/test/resources/my/empty/repo"),
Arguments.of("src/test/resources/this/does/not/exist"),
Arguments.of("src/test/resources/my/non-supported-language/repo"))
Arguments.of("src/test/resources/my/non-supported-language/repo"),
Arguments.of(""))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptConfirm
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.io.File
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {
Expand All @@ -15,8 +17,8 @@ class ParserDialog {
val defaultInputFileName = "svn.$EXTENSION"
val inputFileName = KInquirer.promptInput(
message = "What is the $EXTENSION file that has to be parsed?",
hint = defaultInputFileName,
default = defaultInputFileName
hint = Paths.get("").toAbsolutePath().toString() + File.separator + defaultInputFileName,
default = Paths.get("").toAbsolutePath().toString() + File.separator + defaultInputFileName
)

val defaultOutputFileName = getOutputFileName(inputFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class SonarImporterMainTest {
return listOf(
Arguments.of("src/test/resources/my/sonar/repo"),
Arguments.of("src/test/resources/my/sonar/repo/sonar-project.properties"),
Arguments.of("src/test/resources/my/sonar"),
Arguments.of(""))
Arguments.of("src/test/resources/my/sonar"))
}

@JvmStatic
fun provideInvalidInputFiles(): List<Arguments> {
return listOf(
Arguments.of("src/test/resources/my/nonsonar/repo"),
Arguments.of("src/test/resources/this/does/not/exist"))
Arguments.of("src/test/resources/this/does/not/exist"),
Arguments.of(""))
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import com.github.kinquirer.components.promptInput
import com.github.kinquirer.components.promptListObject
import com.github.kinquirer.core.Choice
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {

override fun collectParserArgs(): List<String> {
val inputFileName = KInquirer.promptInput(
message = "Which project folder or code file should be parsed?",
hint = "file.java"
default = Paths.get("").toAbsolutePath().toString()
)

val outputFormat = KInquirer.promptListObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class SourceCodeParserMainTest {
return listOf(
Arguments.of("src/test/resources/my/java/repo"),
Arguments.of("src/test/resources/my/java/repo/hello_world.java"),
Arguments.of("src/test/resources/my"),
Arguments.of(""))
Arguments.of("src/test/resources/my"))
}

@JvmStatic
fun provideInvalidInputFiles(): List<Arguments> {
return listOf(
Arguments.of("src/test/resources/my/empty/repo"),
Arguments.of("src/test/resources/this/does/not/exist"),
Arguments.of("src/test/resources/my/non-java/repo"))
Arguments.of("src/test/resources/my/non-java/repo"),
Arguments.of(""))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import com.github.kinquirer.KInquirer
import com.github.kinquirer.components.promptConfirm
import com.github.kinquirer.components.promptInput
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import java.io.File
import java.nio.file.Paths

class ParserDialog {
companion object : ParserDialogInterface {

override fun collectParserArgs(): List<String> {
val inputFileName = KInquirer.promptInput(
message = "Please specify the name of the Tokei JSON file to be parsed:",
hint = "input.json"
hint = Paths.get("").toAbsolutePath().toString() + File.separator + "yourInput.json"
)

val outputFileName: String = KInquirer.promptInput(
Expand Down
Loading