Skip to content

Commit

Permalink
feat(application): use clikt as cli library
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 12, 2022
1 parent a74fa12 commit 2c72c0e
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 298 deletions.
30 changes: 15 additions & 15 deletions chapi-application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,15 @@ plugins {
kotlin("plugin.serialization") version "1.6.10"

`jacoco-conventions`

id("com.github.johnrengelman.shadow") version "7.0.0"
}

repositories {
mavenCentral()
mavenLocal()
jcenter()
}

application {
mainClassName = "chapi.app.cli.Main"
}

//tasks.withType<Jar> {
// manifest {
// attributes["Main-Class"] = application.mainClassName
// }
//
// from(configurations.runtimeClasspath.get().map({ if (it.isDirectory) it else zipTree(it) }))
//}

dependencies {
// project deps
implementation(project(":chapi-domain"))
Expand All @@ -40,6 +29,8 @@ dependencies {
implementation(project(":chapi-ast-csharp"))
implementation(project(":chapi-ast-kotlin"))

implementation("com.github.ajalt.clikt:clikt:3.4.0")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")

implementation(kotlin("stdlib-jdk8"))
Expand All @@ -57,8 +48,17 @@ dependencies {
implementation("org.antlr:antlr4-runtime:4.8-1")
}

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8

application {
mainClass.set("chapi.app.cli.ChapiKt")
}

tasks{
shadowJar {
manifest {
attributes(Pair("Main-Class", "chapi.app.cli.ChapiKt"))
}
}
}

tasks.withType<Test> {
Expand Down
43 changes: 43 additions & 0 deletions chapi-application/src/main/kotlin/chapi/app/cli/Chapi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package chapi.app.cli

import chapi.app.analyser.ChapiAnalyser
import chapi.app.analyser.TypeScriptAnalyserApp
import chapi.app.frontend.ComponentHttpCallInfo
import chapi.app.frontend.FrontendApiAnalyser
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.File

class Ast : CliktCommand() {
val path: String by option(help="the path to analysis").default(".")

override fun run() {
val results = ChapiAnalyser().analysis(path)
File("chapi.json").writeText(results.toList().toString())
}
}

class Chapi: CliktCommand() {
override fun run() = Unit
}


class Api : CliktCommand() {
val path: String by option(help="the path to analysis").default(".")

override fun run() {
val nodes = TypeScriptAnalyserApp().analysisNodeByPath(path)
val componentCalls: Array<ComponentHttpCallInfo> = FrontendApiAnalyser().analysis(nodes, path)

File("nodes.json").writeText(Json.encodeToString(nodes))
File("api.json").writeText(Json.encodeToString(componentCalls))
}
}

fun main(args: Array<String>) = Chapi()
.subcommands(Ast(), Api())
.main(args)
10 changes: 0 additions & 10 deletions chapi-application/src/main/kotlin/chapi/app/cli/Main.kt

This file was deleted.

Loading

0 comments on commit 2c72c0e

Please # to comment.