diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2019-04-03 15:07:22 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2019-04-04 12:57:15 +0200 |
commit | c775e8677cdbf69f2b1c1390d225329c658c0ee2 (patch) | |
tree | 707456ffe0817ed2d29d9a62ccf98b9d267283ba /sources/hv-collector-commandline | |
parent | c7a3e0738abf581640059587dbb81790339340c9 (diff) |
Get rid of arrow-effects usage
Also clean-up dependencies + use Kotlin BOM to force single
kotlin-stdlib on classpath.
Issue-ID: DCAEGEN2-1392
Change-Id: I447c4686707de81f35f7734255ce0b13c997c4a4
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'sources/hv-collector-commandline')
4 files changed, 14 insertions, 25 deletions
diff --git a/sources/hv-collector-commandline/pom.xml b/sources/hv-collector-commandline/pom.xml index 078a3cb5..a2ab34fa 100644 --- a/sources/hv-collector-commandline/pom.xml +++ b/sources/hv-collector-commandline/pom.xml @@ -37,20 +37,11 @@ <artifactId>commons-cli</artifactId> </dependency> <dependency> - <groupId>org.jetbrains.kotlin</groupId> - <artifactId>kotlin-reflect</artifactId> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>org.jetbrains.kotlin</groupId> - <artifactId>kotlin-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.jetbrains.spek</groupId> <artifactId>spek-api</artifactId> <scope>test</scope> diff --git a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt index d8c83ea0..4656d46b 100644 --- a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt +++ b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt @@ -36,7 +36,7 @@ abstract class ArgBasedConfiguration<T>(private val parser: CommandLineParser) { Try { parseArgumentsArray(args) } .toEither() .mapLeft { WrongArgumentError(it, cmdLineOptionsList) } - .map(this::getConfiguration) + .map(::getConfiguration) .flatMap { it.toEither { WrongArgumentError( diff --git a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/WrongArgumentError.kt b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/WrongArgumentError.kt index f3749b35..3e4814f8 100644 --- a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/WrongArgumentError.kt +++ b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/WrongArgumentError.kt @@ -19,7 +19,6 @@ */ package org.onap.dcae.collectors.veshv.commandline -import arrow.core.Option import org.apache.commons.cli.HelpFormatter import org.apache.commons.cli.Options @@ -53,17 +52,15 @@ data class WrongArgumentError( private fun getOptions() = cmdLineOptionsList.map { it.option }.fold(Options(), Options::addOption) companion object { - fun generateRequiredParametersNote(cmdLineOptionsList: List<CommandLineOption>): String { - val requiredParams = Option.fromNullable(cmdLineOptionsList.filter { it.required } - .takeUnless { it.isEmpty() }) - return requiredParams.fold( - { "" }, - { - it.map { commandLineOption -> commandLineOption.option.opt } + fun generateRequiredParametersNote(cmdLineOptionsList: List<CommandLineOption>): String = + cmdLineOptionsList.filter { it.required }.let { requiredParams -> + if (requiredParams.isEmpty()) + "" + else + requiredParams.map { commandLineOption -> commandLineOption.option.opt } .joinToString(prefix = "Required parameters: ", separator = ", ") - } - ) - } + } + } } diff --git a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/extensions.kt b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/extensions.kt index 48cac69a..6d8ba3ff 100644 --- a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/extensions.kt +++ b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/extensions.kt @@ -21,10 +21,10 @@ package org.onap.dcae.collectors.veshv.commandline import arrow.core.Option import arrow.core.getOrElse -import arrow.effects.IO import arrow.syntax.function.curried import org.apache.commons.cli.CommandLine -import org.onap.dcae.collectors.veshv.utils.arrow.ExitFailure +import org.onap.dcae.collectors.veshv.utils.process.ExitCode +import org.onap.dcae.collectors.veshv.utils.process.ExitFailure import org.onap.dcae.collectors.veshv.utils.arrow.fromNullablesChain /** @@ -34,10 +34,11 @@ import org.onap.dcae.collectors.veshv.utils.arrow.fromNullablesChain val handleWrongArgumentErrorCurried = ::handleWrongArgumentError.curried() -fun handleWrongArgumentError(programName: String, err: WrongArgumentError): IO<Unit> = IO { +fun handleWrongArgumentError(programName: String, err: WrongArgumentError): ExitCode { err.printMessage() err.printHelp(programName) -}.flatMap { ExitFailure(2).io() } + return ExitFailure(2) +} fun CommandLine.longValue(cmdLineOpt: CommandLineOption, default: Long): Long = longValue(cmdLineOpt).getOrElse { default } |