Skip to content

Commit

Permalink
fixed cli crash + added dummy TemplateCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoMarlir committed May 24, 2024
1 parent 7eed32c commit 23151b9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.blueamethyst.bluecloud.common.terminal.cli

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.CliktError
import com.github.ajalt.clikt.core.subcommands
import me.blueamethyst.bluecloud.common.terminal.Logger
import me.blueamethyst.bluecloud.common.terminal.cli.command.RootCommand
Expand Down Expand Up @@ -37,7 +38,16 @@ class CLI(
if (input.isBlank()) {
continue
}
RootCommand().subcommands(subCommands).main(input.split(" ").toTypedArray())
val command = RootCommand().subcommands(subCommands)

try {
command.parse(input.split(" ").toTypedArray())
} catch (e: CliktError) {
command.echoFormattedHelp(e)
print("\r$prompt")
}

// RootCommand().subcommands(subCommands).main(input.split(" ").toTypedArray())
}
}

Expand Down
1 change: 1 addition & 0 deletions node/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.guice)
implementation(libs.mordant)
implementation(libs.mordantCoroutines)
implementation(libs.clikt)
implementation(kotlin("reflect"))

// Ktor
Expand Down
3 changes: 2 additions & 1 deletion node/src/main/kotlin/me/blueamethyst/bluecloud/node/Node.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import me.blueamethyst.bluecloud.common.terminal.Logger
import me.blueamethyst.bluecloud.common.terminal.Terminal
import me.blueamethyst.bluecloud.common.terminal.cli.CLI
import me.blueamethyst.bluecloud.common.utils.LoggingUtils
import me.blueamethyst.bluecloud.node.commands.TemplateCommand
import me.blueamethyst.bluecloud.node.injector.BlueCloudApiImpl
import me.blueamethyst.bluecloud.node.models.ClusterConfigModel
import me.blueamethyst.bluecloud.node.models.NodeConfigModel
Expand Down Expand Up @@ -117,7 +118,7 @@ class Node: AbstractSystemPart(InternalSystemPartType.NODE) {
cli = CLI(
logger,
"${ConsoleColors.YELLOW_BRIGHT}CLI${ConsoleColors.BLACK_BRIGHT}@${ConsoleColors.BLUE_BRIGHT}BlueCloud ${ConsoleColors.BLACK_BRIGHT}» ${ConsoleColors.RESET}",
listOf()
listOf(TemplateCommand())
)
cli.start()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package me.blueamethyst.bluecloud.node.commands

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option

class TemplateCommand: NoOpCliktCommand(name = "templates", help = "Manage Templates") {

init {
subcommands(Create(), Delete(), Pull(), List(), Info())
}

class Create: CliktCommand(name = "create", help = "Create a new Template") {
private val templateName by argument("name", help = "Name of the new template")

override fun run() {
println("Creating template $templateName")
//TODO
}
}
class Delete: CliktCommand(name = "delete", help = "Delete a Template") {
private val templateName by argument("name", help = "Name of the template to delete")
private val global by option("-g", "--global", help = "Delete the template globally").flag()
private val force by option("-f", "--force", help = "Force delete the template").flag()

override fun run() {
println("Deleting template $templateName with global=$global and force=$force")
//TODO
}
}

class Pull: CliktCommand(name = "pull", help = "Pull a Template") {
private val templateName by argument("name", help = "Name of the template to pull")

override fun run() {
println("Pulling template $templateName")
//TODO
}
}

class List: CliktCommand(name = "list", help = "List all Templates") {
override fun run() {
println("Listing all templates")
//TODO
}
}

class Info: CliktCommand(name = "info", help = "Get info about a Template") {
private val templateName by argument("name", help = "Name of the template to get info about")

override fun run() {
println("Getting info about template $templateName")
//TODO
}
}
}

0 comments on commit 23151b9

Please sign in to comment.