Skip to content

Commit

Permalink
Implement init & version command
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed Feb 18, 2024
1 parent 4bcfdeb commit f19dd6e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .idea/artifacts/pakku_jvm_0_0_8.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = "teksturepako.pakku"
version = "0.0.8"
version = "0.0.9"

repositories {
mavenCentral()
Expand Down
6 changes: 2 additions & 4 deletions src/commonMain/kotlin/teksturepako/pakku/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ fun main(args: Array<String>)
theme = Theme.Default, ansiLevel = AnsiLevel.TRUECOLOR, interactive = true
)
}.subcommands(
Set(), Add(), Rm(), Update(), Ls(), Fetch(), Link(), Import()
Init(), Import(), Set(), Add(), Rm(), Update(), Ls(), Fetch(), Link(), Version()
).main(args)

// Check Modrinth's rate limit
Modrinth.checkRateLimit()

println("Program arguments: ${args.joinToString()}")
println("Pakku version: $VERSION")

// Close client & exit program
// Close http client & exit program
client.close()
exitPakku(0)
}

2 changes: 1 addition & 1 deletion src/commonMain/kotlin/teksturepako/pakku/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package teksturepako.pakku

const val VERSION = "0.0.7"
const val VERSION = "0.0.9"
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ data class PakkuLock(
{
private const val FILE_NAME = "pakku-lock.json"

suspend fun exists(): Boolean = readFileOrNull(FILE_NAME) != null

/**
* Reads [PakkuLock's][PakkuLock] [file][FILE_NAME] and parses it,
* or returns a new [PakkuLock].
Expand Down
52 changes: 52 additions & 0 deletions src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Init.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package teksturepako.pakku.cli.cmd

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.terminal
import kotlinx.coroutines.runBlocking
import teksturepako.pakku.api.data.PakkuLock

class Init : CliktCommand("Initialize modpack")
{
override fun run() = runBlocking {
if (PakkuLock.exists())
{
terminal.danger("Modpack is already initialized")
terminal.info("To change already initialized properties, use the command: \"set\"")
echo()
return@runBlocking
}

val pakkuLock = PakkuLock.readOrNew()

val packName: String =
terminal.prompt("? Modpack name") ?: ""

pakkuLock.setPackName(packName)
terminal.success("'name' set to '$packName'")

val mcVersions: List<String> =
terminal.prompt("? Minecraft versions")?.split(" ") ?: return@runBlocking

pakkuLock.setMcVersions(mcVersions)
terminal.success("'mc_version' set to $mcVersions")

val loaders: List<String> =
terminal.prompt("? Loaders")?.split(" ") ?: return@runBlocking

pakkuLock.setModLoaders(loaders)
terminal.success("'loaders' set to $loaders")

val target: String =
terminal.prompt("? Target", choices = listOf("curseforge", "modrinth", "multiplatform"))
?: return@runBlocking

pakkuLock.setPlatformTarget(target)
terminal.success("'target' set to '$target'")

echo()

pakkuLock.write()
terminal.success("Modpack successfully initialized")
echo()
}
}
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Set.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Set : CliktCommand("Set various properties of your pack or projects")
/** Pack name */
packNameOpt?.let {
pakkuLock.setPackName(it)
terminal.success("'pack_name' set to '$it'")
terminal.success("'name' set to '$it'")
}

/** Target */
Expand Down
13 changes: 13 additions & 0 deletions src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Version.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package teksturepako.pakku.cli.cmd

import com.github.ajalt.clikt.core.CliktCommand
import teksturepako.pakku.VERSION

class Version : CliktCommand("Get pakku version")
{
override fun run()
{
echo("Pakku version $VERSION")
echo()
}
}

0 comments on commit f19dd6e

Please sign in to comment.