colibri/Executable/Sources/Commands/CreateCommand.swift
Javier Cicchelli 212ca52279 Template support for input parameters (#4)
This PR contains the work done to support input parameters for the `create` command of the executable target, and to render content dynamically for the newly-generated project.

Reviewed-on: #4
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2025-02-17 22:11:05 +00:00

44 lines
1.6 KiB
Swift

import ArgumentParser
import ColibriLibrary
extension Colibri {
struct Create: AsyncParsableCommand {
// MARK: Properties
static let configuration = CommandConfiguration(
commandName: "create-project",
abstract: "Create a new, tailored Hummingbird app",
helpNames: .shortAndLong,
aliases: ["create"]
)
@OptionGroup var options: Options
// MARK: Functions
mutating func run() async throws {
let fileService = FileService()
let templateService = try await TemplateService(templateFolder: "Files/Templates")
let terminalService = TerminalService()
let copyFiles = CopyFilesTask(fileService: fileService)
let createFolders = CreateFoldersTask(fileService: fileService)
let createRootFolder = CreateRootFolderTask(fileService: fileService)
let initGitInFolder = InitGitInFolderTask(terminalService: terminalService)
let renderFiles = RenderFilesTask(fileService: fileService,
templateService: templateService)
let rootFolder = try await createRootFolder(name: options.name,
at: options.locationURL)
try await createFolders(at: rootFolder)
try await copyFiles(to: rootFolder)
try await renderFiles(at: rootFolder,
with: Project(name: options.name))
try await initGitInFolder(at: rootFolder)
}
}
}