Skip to content

Commit

Permalink
feat: #195 add option trace
Browse files Browse the repository at this point in the history
  • Loading branch information
nroulon committed Dec 13, 2022
1 parent 16c5aeb commit 6c51d7f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ abstract class DatamaintainCliCommand(name: String, help: String = "") : CliktCo
applyLoggerLevel(CliDatamaintainLoggerLevel.VERBOSE)
config.log()
} else {
val level = if (props.getBooleanCliProperty(CliSpecificKey.VERBOSE)) {
val level = if (props.getBooleanCliProperty(CliSpecificKey.TRACE)) {
CliDatamaintainLoggerLevel.TRACE
} else if (props.getBooleanCliProperty(CliSpecificKey.VERBOSE)) {
CliDatamaintainLoggerLevel.VERBOSE
} else if (props.getBooleanCliProperty(CliSpecificKey.PORCELAIN)) {
CliDatamaintainLoggerLevel.PORCELAIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ class MarkOneScriptAsExecuted(runner: (DatamaintainConfig, Boolean) -> Unit = ::
defaultValue = CoreConfigKey.SCAN_PATH.default
)

private val verbose: Boolean? by detailedOption(
private val verbose: Boolean? by detailedOption("-v",
help = "verbose",
defaultValue = CliSpecificKey.VERBOSE.default
).flag()

private val trace: Boolean? by detailedOption("-vv",
help = "trace is more verbose than verbose",
defaultValue = CliSpecificKey.VERBOSE.default
).flag()

override fun overloadProps(props: Properties) {
props[CoreConfigKey.DEFAULT_SCRIPT_ACTION.key] = ScriptAction.MARK_AS_EXECUTED.name

// Overload from arguments
path?.let { props.put(CoreConfigKey.SCAN_PATH.key, it) }
verbose?.let { props.put(CliSpecificKey.VERBOSE.key, it.toString()) }
trace?.let { props.put(CliSpecificKey.TRACE.key, it.toString()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ class UpdateDb(runner: (DatamaintainConfig, Boolean) -> Unit = ::defaultUpdateDb
defaultValue = CoreConfigKey.PRUNE_OVERRIDE_UPDATED_SCRIPTS.default
).flag()

private val verbose: Boolean? by detailedOption(
private val verbose: Boolean? by detailedOption("--verbose", "-v",
help = "verbose",
defaultValue = CliSpecificKey.VERBOSE.default
).flag()

private val trace: Boolean? by detailedOption("-vv",
help = "trace is more verbose than verbose",
defaultValue = CliSpecificKey.VERBOSE.default
).flag()

private val saveDbOutput: Boolean? by detailedOption(
help = "save your script and db output",
defaultValue = DriverConfigKey.DB_SAVE_OUTPUT.default
Expand Down Expand Up @@ -128,6 +133,7 @@ class UpdateDb(runner: (DatamaintainConfig, Boolean) -> Unit = ::defaultUpdateDb
tagsToPlayAgain?.let { props.put(CoreConfigKey.PRUNE_TAGS_TO_RUN_AGAIN.key, it) }
createTagsFromFolder?.let { props.put(CoreConfigKey.CREATE_TAGS_FROM_FOLDER.key, it.toString()) }
verbose?.let { props.put(CliSpecificKey.VERBOSE.key, it.toString()) }
trace?.let { props.put(CliSpecificKey.TRACE.key, it.toString()) }
saveDbOutput?.let { props.put(DriverConfigKey.DB_SAVE_OUTPUT.key, it.toString()) }
printDbOutput?.let { props.put(DriverConfigKey.DB_PRINT_OUTPUT.key, it.toString()) }
executionMode?.let { props.put(CoreConfigKey.EXECUTION_MODE.key, it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fun applyLoggerLevel(level: CliDatamaintainLoggerLevel) {
when(level) {
CliDatamaintainLoggerLevel.INFO -> datamaintainLogger.level = Level.INFO
CliDatamaintainLoggerLevel.VERBOSE -> datamaintainLogger.level = Level.DEBUG
CliDatamaintainLoggerLevel.TRACE -> datamaintainLogger.level = Level.TRACE
CliDatamaintainLoggerLevel.PORCELAIN -> datamaintainLogger.level = Level.ERROR
else -> error("Cannot set log level of $level")
}
Expand All @@ -26,6 +27,9 @@ enum class CliDatamaintainLoggerLevel {
// debug log level
VERBOSE,

// trace log level
TRACE,

// special mode for cli, the datamaintain logs are disabled (except error) and specific logs are print.
// This is use for scripts that may need to parse datamaintain logs (e.g: for take in account execution results)
PORCELAIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class CliSpecificKey(
__PRINT_CONFIG_ONLY("__PRINT_CONFIG_ONLY", "false"),
VERSION("version", "dev"),
VERBOSE("verbose", "false"),
TRACE("trace", "false"),
PORCELAIN("porcelain", "false"),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ internal class UpdateDbTest : BaseCliTest() {
// Then
expectThat(datamaintainLogger.level).isEqualTo(Level.INFO)
}

@Test
fun `should build config with trace set to true`() {
// Given
val updateDbArguments = listOf("-vv")

// When
runUpdateDb(updateDbArguments)

// Then
expectThat(datamaintainLogger.level).isEqualTo(Level.TRACE)
}

@Test
fun `should build config with trace set to true even if verbose is set`() {
// Given
val updateDbArguments = listOf("--verbose", "-vv")

// When
runUpdateDb(updateDbArguments)

// Then
expectThat(datamaintainLogger.level).isEqualTo(Level.TRACE)
}
}

@Nested
Expand Down

0 comments on commit 6c51d7f

Please sign in to comment.