Skip to content

Commit

Permalink
feat(examples arguments): replacing multiple arguments format for the…
Browse files Browse the repository at this point in the history
… 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"
  • Loading branch information
DariusIMP committed Apr 9, 2024
1 parent 0052738 commit 93d9c1f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 70 deletions.
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/src/main/kotlin/io.zenoh/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ data class Multicast(
internal fun loadConfig(
emptyArgs: Boolean,
configFile: String?,
connectEndpoints: List<String>?,
listenEndpoints: List<String>?,
connectEndpoints: List<String>,
listenEndpoints: List<String>,
noMulticastScouting: Boolean,
mode: String?
): Config {
val config = if (emptyArgs) {
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)
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZDelete.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> 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"
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZGet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> by option(
"-l", "--listen", help = "Endpoints to listen on.", metavar = "listen"
).varargValues()
).multiple()
private val attachment by option(
"-a",
"--attach",
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZPub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> by option(
"-l", "--listen", help = "Endpoints to listen on.", metavar = "listen"
).varargValues()
).multiple()
private val mode by option(
"-m",
"--mode",
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZPubThr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> by option(
"-l", "--listen", help = "Endpoints to listen on.", metavar = "listen"
).varargValues()
).multiple()
private val mode by option(
"-m",
"--mode",
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZPut.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> by option(
"-l", "--listen", help = "Endpoints to listen on.", metavar = "listen"
).varargValues()
).multiple()
private val mode by option(
"-m",
"--mode",
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZQueryable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> 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)
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZSub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> by option(
"-l", "--listen", help = "Endpoints to listen on.", metavar = "listen"
).varargValues()
).multiple()
private val mode by option(
"-m",
"--mode",
Expand Down
13 changes: 5 additions & 8 deletions examples/src/main/kotlin/io.zenoh/ZSubThr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String>? by option(
private val connect: List<String> by option(
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect"
).varargValues()
private val listen: List<String>? by option(
).multiple()
private val listen: List<String> by option(
"-l", "--listen", help = "Endpoints to listen on.", metavar = "listen"
).varargValues()
).multiple()
private val mode by option(
"-m",
"--mode",
Expand Down

0 comments on commit 93d9c1f

Please sign in to comment.