Skip to content

Commit

Permalink
refactor: #195 verbose and porcelain are a cli feature and not in core
Browse files Browse the repository at this point in the history
+ add option trace
  • Loading branch information
nroulon committed Feb 7, 2023
1 parent 3a3d7cd commit 922e2e2
Show file tree
Hide file tree
Showing 49 changed files with 537 additions and 464 deletions.
41 changes: 21 additions & 20 deletions docs/cli-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@
## update-db
### Options

|Names|Default value|Needs argument|Possible arguments|Description|Examples|
|---|---|---|---|---|---|
|--path|./scripts/||TEXT|path to directory containing scripts|```src/main/resources/scripts/```|
|--identifier-regex|(.*)||TEXT|regex to extract identifier part from scripts|```v(.*)_.*```|
|--whitelisted-tags|No default value||TEXT|tags to whitelist (separated by ',')|```WHITELISTED_TAG1,WHITELISTED_TAG2```|
|--blacklisted-tags|No default value||TEXT|tags to blacklist (separated by ',')|```BLACKLISTED_TAG1,BLACKLISTED_TAG2```|
|--tags-to-play-again|No default value||TEXT|tags to play again at each datamaintain execution (separated by ',')|```TAG_TO_PLAY_AGAIN1,TAG_TO_PLAY_AGAIN2```|
|--create-tags-from-folder|false||N/A|create automatically tags from parent folders||
|--execution-mode|NORMAL||```NORMAL``` or ```DRY```|execution mode||
|--action|RUN||```RUN``` or ```MARK_AS_EXECUTED``` or ```OVERRIDE_EXECUTED```|script action||
|--allow-auto-override|false||N/A|Allow datamaintain to automaticaly override scripts||
|--verbose|false||N/A|verbose||
|--save-db-output|false||N/A|save your script and db output||
|--print-db-output|false||N/A|print your script and db output||
|--tag|No default value|| |Tag defined using glob path matchers. To define multiple tags, use option multiple times. Syntax example: MYTAG1=[pathMatcher1, pathMatcher2]|```MYTAG1=[pathMatcher1, pathMatcher2]```|
|--rule|No default value||```SameScriptsAsExecutedCheck```|check rule to play. To define multiple rules, use option multiple times.||
|--mongo-shell|mongo||```mongo``` or ```mongosh```|mongo binary, can be mongo or mongosh. mongo by default||
|--porcelain|false||N/A|for each executed script, display relative path to scan path||
|--flags|No default value||TEXT|add a flag on the executed scripts. To define multiple rules, use option multiple times.||
|-h, --help|No default value||N/A|Display command help and exit||
| Names |Default value|Needs argument|Possible arguments| Description |Examples|
|---------------------------|---|---|---|-----------------------------------------------------------------------------------------------------------------------------------------------|---|
| --path |./scripts/||TEXT| path to directory containing scripts |```src/main/resources/scripts/```|
| --identifier-regex |(.*)||TEXT| regex to extract identifier part from scripts |```v(.*)_.*```|
| --whitelisted-tags |No default value||TEXT| tags to whitelist (separated by ',') |```WHITELISTED_TAG1,WHITELISTED_TAG2```|
| --blacklisted-tags |No default value||TEXT| tags to blacklist (separated by ',') |```BLACKLISTED_TAG1,BLACKLISTED_TAG2```|
| --tags-to-play-again |No default value||TEXT| tags to play again at each datamaintain execution (separated by ',') |```TAG_TO_PLAY_AGAIN1,TAG_TO_PLAY_AGAIN2```|
| --create-tags-from-folder |false||N/A| create automatically tags from parent folders ||
| --execution-mode |NORMAL||```NORMAL``` or ```DRY```| execution mode ||
| --action |RUN||```RUN``` or ```MARK_AS_EXECUTED``` or ```OVERRIDE_EXECUTED```| script action ||
| --allow-auto-override |false||N/A| Allow datamaintain to automaticaly override scripts ||
| --verbose |false||N/A| verbose ||
| -vv |false||N/A| verbose level 2 ||
| --save-db-output |false||N/A| save your script and db output ||
| --print-db-output |false||N/A| print your script and db output ||
| --tag |No default value|| | Tag defined using glob path matchers. To define multiple tags, use option multiple times. Syntax example: MYTAG1=[pathMatcher1, pathMatcher2] |```MYTAG1=[pathMatcher1, pathMatcher2]```|
| --rule |No default value||```SameScriptsAsExecutedCheck```| check rule to play. To define multiple rules, use option multiple times. ||
| --mongo-shell |mongo||```mongo``` or ```mongosh```| mongo binary, can be mongo or mongosh. mongo by default ||
| --porcelain |false||N/A| for each executed script, display relative path to scan path ||
| --flags |No default value||TEXT| add a flag on the executed scripts. To define multiple rules, use option multiple times. ||
| -h, --help |No default value||N/A| Display command help and exit ||
## list
### Options

Expand Down
37 changes: 19 additions & 18 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

## Core configuration

| Key | Description | Default value | Mandatory? | Values examples |
|---|---|---|---|---|
| name | Allow to name your config. For now will only be used to logging purpose | None | no | |
| working.directory.path | Indicates the directory to use to find relative paths | Java default working directory path | no | |
| parent.config.path | Path to an other configuration file to inherit properties. Can be absolute or relative to `working.directory.path` | None | no | |
| default.script.action | The default script action | ```RUN``` | no | ```RUN``` or ```MARK_AS_EXECUTED``` |
| scan.path | Path to the folder containing all your scripts. Can be absolute or relative to `working.directory.path` | ```./scripts/``` | yes | |
| scan.identifier.regex | Regex that will be used to determine an identifier for each file. It has to contain a capturing group. Identifiers are then used to sort the scripts before running them. | ```(.*)``` (with this regex, the script's whole name will be its identifier) | no | With the regex ```(.*?)_.*```, a script named ```1.23_my-script.js``` will have ```1.23``` as its identifier |
| scan.tags.createFromFolder | If true, scripts will have their parent folders names as tags. Relative path to ```scan.path``` is used. | ```false``` | no | ```false``` or ```true``` |
| tag.*your_tag* | Glob paths to your scripts that you want to apply the tag "your_tag" on. To declare multiple tags, you will have to add multiple properties in your settings. A tag ```my_tag``` will have as as property name ```tag.my_tag``` **WARNING:** ALWAYS declare your tags using absolute paths. Relative paths and even using a tilde (~) won't do the trick. | | no | ```[data/*, script1.js, old/old_script1.js]``` |
| filter.tags.whitelisted | Scripts that have these tags will be considered | None | no | ```DATA,tag``` |
| filter.tags.blacklisted | Scripts that have these tags will be ignored. A script having a whitelisted tag and a blacklisted tag will be ignored | None | no | ```DATA,tag``` |
| prune.tags.to.run.again | Scripts that have these tags will be run, even they were already executed | None | no | ```tag,again``` |
| execution.mode | Execution mode. Possible values:<br />- ```NORMAL```: Regular execution: your scripts will be run on your database.<br />- ```DRY```: Scripts will not be executed. A full report of what would happen is you ran Datamaintain normally will be logged.<br /> | ```NORMAL``` | no | ```NORMAL```, ```DRY``` |
| verbose | If true, more logs will be printed. **WARNING:** Can't be used alongside with porcelain. If both are set, porcelain will prevail | ```false``` | no | ```true``` or ```false``` |
| prune.scripts.override.executed | Allow datamaintain to override a script if it detect a checksum change on a script already runned (assuming its filename) | ```false``` | no | ```true``` or ```false``` |
| db.trust.uri | Bypass all checks that could be done on your URI because you are very sure of it and think our checks are just liars | ```false``` | no | ```true``` or ```false``` |
| porcelain | For each executed script, print path relative to scan path **WARNING:** Can't be used alongside with verbose. If both are set, porcelain will prevail | ```false``` | no | ```true``` or ```false``` |
| Key | Description | Default value | Mandatory? | Values examples |
|---------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|---|---|
| name | Allow to name your config. For now will only be used to logging purpose | None | no | |
| working.directory.path | Indicates the directory to use to find relative paths | Java default working directory path | no | |
| parent.config.path | Path to an other configuration file to inherit properties. Can be absolute or relative to `working.directory.path` | None | no | |
| default.script.action | The default script action | ```RUN``` | no | ```RUN``` or ```MARK_AS_EXECUTED``` |
| scan.path | Path to the folder containing all your scripts. Can be absolute or relative to `working.directory.path` | ```./scripts/``` | yes | |
| scan.identifier.regex | Regex that will be used to determine an identifier for each file. It has to contain a capturing group. Identifiers are then used to sort the scripts before running them. | ```(.*)``` (with this regex, the script's whole name will be its identifier) | no | With the regex ```(.*?)_.*```, a script named ```1.23_my-script.js``` will have ```1.23``` as its identifier |
| scan.tags.createFromFolder | If true, scripts will have their parent folders names as tags. Relative path to ```scan.path``` is used. | ```false``` | no | ```false``` or ```true``` |
| tag.*your_tag* | Glob paths to your scripts that you want to apply the tag "your_tag" on. To declare multiple tags, you will have to add multiple properties in your settings. A tag ```my_tag``` will have as as property name ```tag.my_tag``` **WARNING:** ALWAYS declare your tags using absolute paths. Relative paths and even using a tilde (~) won't do the trick. | | no | ```[data/*, script1.js, old/old_script1.js]``` |
| filter.tags.whitelisted | Scripts that have these tags will be considered | None | no | ```DATA,tag``` |
| filter.tags.blacklisted | Scripts that have these tags will be ignored. A script having a whitelisted tag and a blacklisted tag will be ignored | None | no | ```DATA,tag``` |
| prune.tags.to.run.again | Scripts that have these tags will be run, even they were already executed | None | no | ```tag,again``` |
| execution.mode | Execution mode. Possible values:<br />- ```NORMAL```: Regular execution: your scripts will be run on your database.<br />- ```DRY```: Scripts will not be executed. A full report of what would happen is you ran Datamaintain normally will be logged.<br /> | ```NORMAL``` | no | ```NORMAL```, ```DRY``` |
| verbose | If true, more logs will be printed. **WARNING:** Can't be used alongside with porcelain. If both are set, porcelain will prevail | ```false``` | no | ```true``` or ```false``` |
| trace | If true, more logs will be printed than verbose. **WARNING:** Can't be used alongside with porcelain. If both are set, porcelain will prevail | ```false``` | no | ```true``` or ```false``` |
| prune.scripts.override.executed | Allow datamaintain to override a script if it detect a checksum change on a script already runned (assuming its filename) | ```false``` | no | ```true``` or ```false``` |
| db.trust.uri | Bypass all checks that could be done on your URI because you are very sure of it and think our checks are just liars | ```false``` | no | ```true``` or ```false``` |
| porcelain | For each executed script, print path relative to scan path **WARNING:** Can't be used alongside with verbose. If both are set, porcelain will prevail | ```false``` | no | ```true``` or ```false``` |

### Common driver configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package datamaintain.cli.app

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.findObject
import datamaintain.cli.app.utils.CliSpecificKey
import datamaintain.cli.app.utils.loadConfig
import datamaintain.cli.app.utils.*
import datamaintain.core.config.DatamaintainConfig
import datamaintain.core.exception.DatamaintainBaseException
import java.util.*
Expand All @@ -17,10 +16,24 @@ abstract class DatamaintainCliCommand(name: String, help: String = "") : CliktCo
overloadProps(props)
val config = loadConfig(props)

if (props.getProperty(CliSpecificKey.__PRINT_CONFIG_ONLY.key, CliSpecificKey.__PRINT_CONFIG_ONLY.default)!!.toBoolean()) {
val isPrintConfigOnly = props.getBooleanCliProperty(CliSpecificKey.__PRINT_CONFIG_ONLY)
if (isPrintConfigOnly) {
// config log nothing in INFO level so apply DEBUG level
applyLoggerLevel(CliDatamaintainLoggerLevel.VERBOSE)
config.log()
} else {
executeCommand(config)
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
} else {
CliDatamaintainLoggerLevel.INFO
}
applyLoggerLevel(level)

executeCommand(config, level == CliDatamaintainLoggerLevel.PORCELAIN)
}
} catch (e: DatamaintainBaseException) {
echo(e.message, err = true)
Expand All @@ -37,5 +50,5 @@ abstract class DatamaintainCliCommand(name: String, help: String = "") : CliktCo

protected abstract fun overloadProps(props: Properties)

protected abstract fun executeCommand(config: DatamaintainConfig)
protected abstract fun executeCommand(config: DatamaintainConfig, porcelain: Boolean)
}
Loading

0 comments on commit 922e2e2

Please sign in to comment.