Skip to content

Commit f9b6340

Browse files
committed
refactor: update add meter & add view commands with latest protocol
1 parent 2c0328a commit f9b6340

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/main/kotlin/spp/cli/commands/developer/instrument/AddMeter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class AddMeter : CliktCommand(name = "meter", help = "Add a live meter instrumen
4646

4747
val source by argument(help = "Qualified class name")
4848
val line by argument(help = "Line number").int()
49-
val meterName by argument(help = "Meter name")
5049
val meterType by argument(help = "Meter type").enum<MeterType>()
5150
val valueType by argument(help = "Metric value type").enum<MetricValueType>()
5251
val value by option("-value", "-v", help = "Metric value")
52+
val meterId by option("-id", help = "Meter identifier")
53+
val meterDescription by option("-desc", help = "Meter description")
5354
val condition by option("-condition", "-c", help = "Trigger condition")
5455
val expiresAt by option("-expiresAt", "-e", help = "Expiration time (epoch time [ms])").long()
5556
val hitLimit by option("-hitLimit", "-h", help = "Trigger hit limit").int()
@@ -59,12 +60,13 @@ class AddMeter : CliktCommand(name = "meter", help = "Add a live meter instrumen
5960

6061
override fun run() = runBlocking {
6162
val input = LiveMeterInput(
62-
meterName = meterName,
6363
meterType = spp.cli.protocol.type.MeterType.valueOf(meterType.toString()),
6464
metricValue = MetricValueInput(
6565
valueType = spp.cli.protocol.type.MetricValueType.valueOf(valueType.toString()),
6666
value = Optional.presentIfNotNull(value)
6767
),
68+
id = Optional.presentIfNotNull(meterId),
69+
meterDescription = Optional.presentIfNotNull(meterDescription),
6870
location = LiveSourceLocationInput(source, line),
6971
condition = Optional.Present(condition),
7072
expiresAt = Optional.Present(expiresAt),

src/main/kotlin/spp/cli/commands/developer/view/AddView.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,34 @@ import com.apollographql.apollo3.api.json.MapJsonWriter
2121
import com.github.ajalt.clikt.core.CliktCommand
2222
import com.github.ajalt.clikt.parameters.arguments.argument
2323
import com.github.ajalt.clikt.parameters.arguments.multiple
24+
import com.github.ajalt.clikt.parameters.options.default
25+
import com.github.ajalt.clikt.parameters.options.multiple
26+
import com.github.ajalt.clikt.parameters.options.option
2427
import kotlinx.coroutines.runBlocking
2528
import spp.cli.Main
2629
import spp.cli.PlatformCLI.apolloClient
2730
import spp.cli.PlatformCLI.echoError
31+
import spp.cli.protocol.type.LiveViewConfigInput
2832
import spp.cli.protocol.type.LiveViewInput
2933
import spp.cli.protocol.view.AddLiveViewMutation
3034
import spp.cli.protocol.view.adapter.AddLiveViewMutation_ResponseAdapter.AddLiveView
3135
import spp.cli.util.JsonCleaner
36+
import java.util.*
3237
import kotlin.system.exitProcess
3338

3439
class AddView : CliktCommand(name = "view", help = "Add a live view") {
3540

3641
val entityIds by argument(name = "Entity IDs").multiple(required = true)
42+
val viewName by option("-name", "-n", help = "View name").default("cli-" + UUID.randomUUID().toString())
43+
val viewMetrics by option("-metrics", "-m", help = "View metrics").multiple()
3744

3845
override fun run() = runBlocking {
3946
val input = LiveViewInput(
4047
entityIds = entityIds.toList(),
48+
viewConfig = LiveViewConfigInput(
49+
viewName,
50+
viewMetrics.ifEmpty { entityIds }
51+
)
4152
)
4253
val response = try {
4354
apolloClient.mutation(AddLiveViewMutation(input)).execute()

0 commit comments

Comments
 (0)