48 lines
1.3 KiB
Kotlin
48 lines
1.3 KiB
Kotlin
package scaffold.commands
|
|
|
|
import com.github.ajalt.clikt.core.CliktCommand
|
|
import com.github.ajalt.clikt.core.ProgramResult
|
|
import com.github.ajalt.clikt.parameters.arguments.argument
|
|
import scaffold.Generators
|
|
import java.nio.file.Files
|
|
|
|
class NewCommand(private val generators: Generators) : CliktCommand("new") {
|
|
private val name by argument()
|
|
|
|
override fun run() {
|
|
val root = generators.configDirectory.resolve(name)
|
|
|
|
if (Files.exists(root)) {
|
|
echo("Generator already exists")
|
|
throw ProgramResult(1)
|
|
}
|
|
|
|
Files.createDirectories(root)
|
|
|
|
val configFile = """
|
|
templates = [
|
|
"README.md"
|
|
]
|
|
|
|
files = [
|
|
".gitignore"
|
|
]
|
|
|
|
[prompt]
|
|
|
|
[[prompt.project]]
|
|
type = "String"
|
|
name = "name"
|
|
info = "Project name"
|
|
""".trimIndent()
|
|
|
|
Files.writeString(root.resolve("config.toml"), configFile)
|
|
val tree = root.resolve("tree")
|
|
Files.createDirectory(tree)
|
|
|
|
Files.writeString(tree.resolve("README.md"), "# {{ project.name }}")
|
|
Files.writeString(tree.resolve(".gitignore"), "# https://git-scm.com/docs/gitignore")
|
|
|
|
echo("Generator created in $root")
|
|
}
|
|
} |