From 93d9c1f676c08776bd7d80d8b3162f8506bd3bd7 Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Tue, 9 Apr 2024 16:35:49 +0200 Subject: [PATCH] feat(examples arguments): replacing multiple arguments format for the listen and connect arguments. For instance: gradle ZPub --args="-l tcp/localhost:7447 tcp/localhost:7448 tcp/localhost:7449" now becomes gradle ZPub --args="-l tcp/localhost:7447 -l tcp/localhost:7448 -l tcp/localhost:7449" --- examples/README.md | 4 ++-- examples/src/main/kotlin/io.zenoh/Config.kt | 8 ++++---- examples/src/main/kotlin/io.zenoh/ZDelete.kt | 13 +++++-------- examples/src/main/kotlin/io.zenoh/ZGet.kt | 13 +++++-------- examples/src/main/kotlin/io.zenoh/ZPub.kt | 13 +++++-------- examples/src/main/kotlin/io.zenoh/ZPubThr.kt | 13 +++++-------- examples/src/main/kotlin/io.zenoh/ZPut.kt | 13 +++++-------- examples/src/main/kotlin/io.zenoh/ZQueryable.kt | 13 +++++-------- examples/src/main/kotlin/io.zenoh/ZSub.kt | 13 +++++-------- examples/src/main/kotlin/io.zenoh/ZSubThr.kt | 13 +++++-------- 10 files changed, 46 insertions(+), 70 deletions(-) diff --git a/examples/README.md b/examples/README.md index 1d7c930e4..782b01b82 100644 --- a/examples/README.md +++ b/examples/README.md @@ -40,11 +40,11 @@ Options: ``` -The connect and listen parameters (that are common to all the examples) accept multiple inputs separated by a whitespace. +The connect and listen parameters (that are common to all the examples) accept multiple repeated inputs. For instance: ```bash - gradle ZPub --args="-l tcp/localhost:7447 tcp/localhost:7448 tcp/localhost:7449" + gradle ZPub --args="-l tcp/localhost:7447 -l tcp/localhost:7448 -l tcp/localhost:7449" ``` There is the possibility to provide a Zenoh config file as follows diff --git a/examples/src/main/kotlin/io.zenoh/Config.kt b/examples/src/main/kotlin/io.zenoh/Config.kt index b246a9a4f..b25ebe614 100644 --- a/examples/src/main/kotlin/io.zenoh/Config.kt +++ b/examples/src/main/kotlin/io.zenoh/Config.kt @@ -52,8 +52,8 @@ data class Multicast( internal fun loadConfig( emptyArgs: Boolean, configFile: String?, - connectEndpoints: List?, - listenEndpoints: List?, + connectEndpoints: List, + listenEndpoints: List, noMulticastScouting: Boolean, mode: String? ): Config { @@ -61,8 +61,8 @@ internal fun loadConfig( Config.default() } else { configFile?.let { Config.from(Path(it)) } ?: run { - val connect = connectEndpoints?.let { Connect(it) } - val listen = listenEndpoints?.let { Listen(listenEndpoints) } + val connect = Connect(connectEndpoints) + val listen = Listen(listenEndpoints) val scouting = Scouting(Multicast(!noMulticastScouting)) val configData = ConfigData(connect, listen, mode, scouting) val jsonConfig = Json.encodeToJsonElement(configData) diff --git a/examples/src/main/kotlin/io.zenoh/ZDelete.kt b/examples/src/main/kotlin/io.zenoh/ZDelete.kt index 93bd14dc1..214cdbe1c 100644 --- a/examples/src/main/kotlin/io.zenoh/ZDelete.kt +++ b/examples/src/main/kotlin/io.zenoh/ZDelete.kt @@ -15,22 +15,19 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import io.zenoh.keyexpr.intoKeyExpr class ZDelete(private val emptyArgs: Boolean) : CliktCommand( help = "Zenoh Delete example" ) { - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val configFile by option("-c", "--config", help = "A configuration file.", metavar = "config") private val key by option( "-k", "--key", help = "The key expression to write to [default: demo/example/zenoh-kotlin-put]", metavar = "key" diff --git a/examples/src/main/kotlin/io.zenoh/ZGet.kt b/examples/src/main/kotlin/io.zenoh/ZGet.kt index 02c0641d7..36724b981 100644 --- a/examples/src/main/kotlin/io.zenoh/ZGet.kt +++ b/examples/src/main/kotlin/io.zenoh/ZGet.kt @@ -15,10 +15,7 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.parameters.types.long import io.zenoh.query.ConsolidationMode import io.zenoh.query.QueryTarget @@ -56,12 +53,12 @@ class ZGet(private val emptyArgs: Boolean) : CliktCommand( help = "The session mode. Default: peer. Possible values: [peer, client, router]", metavar = "mode" ).default("peer") - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val attachment by option( "-a", "--attach", diff --git a/examples/src/main/kotlin/io.zenoh/ZPub.kt b/examples/src/main/kotlin/io.zenoh/ZPub.kt index dfb64e69d..69e8144f0 100644 --- a/examples/src/main/kotlin/io.zenoh/ZPub.kt +++ b/examples/src/main/kotlin/io.zenoh/ZPub.kt @@ -15,10 +15,7 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import io.zenoh.keyexpr.intoKeyExpr class ZPub(private val emptyArgs: Boolean) : CliktCommand( @@ -29,12 +26,12 @@ class ZPub(private val emptyArgs: Boolean) : CliktCommand( "-k", "--key", help = "The key expression to write to [default: demo/example/zenoh-kotlin-pub]", metavar = "key" ).default("demo/example/zenoh-kotlin-pub") private val configFile by option("-c", "--config", help = "A configuration file.", metavar = "config") - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val mode by option( "-m", "--mode", diff --git a/examples/src/main/kotlin/io.zenoh/ZPubThr.kt b/examples/src/main/kotlin/io.zenoh/ZPubThr.kt index 44e5fa42b..6e28947dc 100644 --- a/examples/src/main/kotlin/io.zenoh/ZPubThr.kt +++ b/examples/src/main/kotlin/io.zenoh/ZPubThr.kt @@ -17,10 +17,7 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.default -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.parameters.types.boolean import com.github.ajalt.clikt.parameters.types.int import com.github.ajalt.clikt.parameters.types.ulong @@ -54,12 +51,12 @@ class ZPubThr(private val emptyArgs: Boolean) : CliktCommand( ).ulong().default(100000u) private val statsPrint by option("-t", "--print", help = "Print the statistics").boolean().default(true) private val configFile by option("-c", "--config", help = "A configuration file.", metavar = "config") - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val mode by option( "-m", "--mode", diff --git a/examples/src/main/kotlin/io.zenoh/ZPut.kt b/examples/src/main/kotlin/io.zenoh/ZPut.kt index e0cf1ffde..447839aff 100644 --- a/examples/src/main/kotlin/io.zenoh/ZPut.kt +++ b/examples/src/main/kotlin/io.zenoh/ZPut.kt @@ -15,10 +15,7 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import io.zenoh.keyexpr.intoKeyExpr import io.zenoh.prelude.SampleKind import io.zenoh.publication.CongestionControl @@ -32,12 +29,12 @@ class ZPut(private val emptyArgs: Boolean) : CliktCommand( private val key by option( "-k", "--key", help = "The key expression to write to [default: demo/example/zenoh-kotlin-put]", metavar = "key" ).default("demo/example/zenoh-kotlin-put") - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val mode by option( "-m", "--mode", diff --git a/examples/src/main/kotlin/io.zenoh/ZQueryable.kt b/examples/src/main/kotlin/io.zenoh/ZQueryable.kt index 38b4cee98..dc6a4964e 100644 --- a/examples/src/main/kotlin/io.zenoh/ZQueryable.kt +++ b/examples/src/main/kotlin/io.zenoh/ZQueryable.kt @@ -15,10 +15,7 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import io.zenoh.keyexpr.KeyExpr import io.zenoh.keyexpr.intoKeyExpr import io.zenoh.prelude.SampleKind @@ -47,12 +44,12 @@ class ZQueryable(private val emptyArgs: Boolean) : CliktCommand( help = "The session mode. Default: peer. Possible values: [peer, client, router]", metavar = "mode" ).default("peer") - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val noMulticastScouting: Boolean by option( "--no-multicast-scouting", help = "Disable the multicast-based scouting mechanism." ).flag(default = false) diff --git a/examples/src/main/kotlin/io.zenoh/ZSub.kt b/examples/src/main/kotlin/io.zenoh/ZSub.kt index 0d8074a3d..e29eb7646 100644 --- a/examples/src/main/kotlin/io.zenoh/ZSub.kt +++ b/examples/src/main/kotlin/io.zenoh/ZSub.kt @@ -15,10 +15,7 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import io.zenoh.keyexpr.intoKeyExpr import kotlinx.coroutines.runBlocking @@ -30,12 +27,12 @@ class ZSub(private val emptyArgs: Boolean) : CliktCommand( private val key by option( "-k", "--key", help = "The key expression to subscribe to [default: demo/example/**]", metavar = "key" ).default("demo/example/**") - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val mode by option( "-m", "--mode", diff --git a/examples/src/main/kotlin/io.zenoh/ZSubThr.kt b/examples/src/main/kotlin/io.zenoh/ZSubThr.kt index 90c898b57..4e42be48c 100644 --- a/examples/src/main/kotlin/io.zenoh/ZSubThr.kt +++ b/examples/src/main/kotlin/io.zenoh/ZSubThr.kt @@ -15,10 +15,7 @@ package io.zenoh import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.flag -import com.github.ajalt.clikt.parameters.options.option -import com.github.ajalt.clikt.parameters.options.varargValues +import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.parameters.types.ulong import io.zenoh.keyexpr.intoKeyExpr import io.zenoh.subscriber.Subscriber @@ -38,12 +35,12 @@ class ZSubThr(private val emptyArgs: Boolean) : CliktCommand( metavar = "number" ).ulong().default(10000u) private val configFile by option("-c", "--config", help = "A configuration file.", metavar = "config") - private val connect: List? by option( + private val connect: List by option( "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" - ).varargValues() - private val listen: List? by option( + ).multiple() + private val listen: List by option( "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" - ).varargValues() + ).multiple() private val mode by option( "-m", "--mode",