Skip to content

Commit

Permalink
feat: add convert command
Browse files Browse the repository at this point in the history
  • Loading branch information
ragunathjawahar committed Oct 13, 2022
1 parent 31ea906 commit e3fff6d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
7 changes: 5 additions & 2 deletions cli/src/main/kotlin/io/redgreen/tumbleweed/cli/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.redgreen.tumbleweed.cli

import io.redgreen.tumbleweed.cli.dev.convert.ConvertCommand
import io.redgreen.tumbleweed.cli.dev.json.JsonCommand
import io.redgreen.tumbleweed.cli.dev.view.ViewCommand
import io.redgreen.tumbleweed.cli.watch.WatchCommand
Expand All @@ -15,11 +16,13 @@ const val DEFAULT_PORT = 7070
WatchCommand::class,
JsonCommand::class,
ViewCommand::class,
ConvertCommand::class,
],
)
class TumbleweedCommand

fun main(args: Array<String>) {
exitProcess(CommandLine(TumbleweedCommand())
.execute(*args))
val status = CommandLine(TumbleweedCommand())
.execute(*args)
exitProcess(status)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.redgreen.tumbleweed.cli.dev.convert

import io.redgreen.tumbleweed.web.observablehq.BilevelEdgeBundlingGraph
import java.io.File
import picocli.CommandLine.Command
import picocli.CommandLine.Parameters

@Command(
name = "convert",
description = ["(dev) converts a CSV file to an ObservableHQ JSON file"],
)
class ConvertCommand : Runnable {
@Parameters(
index = "0",
description = ["path to the CSV file to convert"],
arity = "1",
)
lateinit var csvFile: File

override fun run() {
val graph = BilevelEdgeBundlingGraph.from(csvFile.readText())
println(graph.asJson())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class JsonCommand : Runnable {
if (check) {
classStructure.check()
} else {
println(classStructure.graph.json)
println(classStructure.graph.asJson())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TumbleweedServer {
source: Source,
) {
logger.info("Web socket connection opened. Ready to send updates.")
send(Frame.Text(source.graph.json))
send(Frame.Text(source.graph.asJson()))

while (true) {
val message = withContext(Dispatchers.IO) {
Expand All @@ -104,7 +104,7 @@ class TumbleweedServer {
if (!location.exists()) {
logger.error("Source file does not exist: {}", location)
} else {
structureUpdatesQueue.add(source.graph.json)
structureUpdatesQueue.add(source.graph.asJson())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ data class BilevelEdgeBundlingGraph(
) {
companion object

val json: String
get() {
return jacksonObjectMapper()
.writerWithDefaultPrettyPrinter()
.writeValueAsString(this)
}
fun asJson(): String {
return jacksonObjectMapper()
.writerWithDefaultPrettyPrinter()
.writeValueAsString(this)
}

data class Node(
val id: String,
Expand Down

0 comments on commit e3fff6d

Please sign in to comment.