This PR contains the work done to create the root folder of a new project when executing the _colibri_ executable. In addition, some other work has been done: * added the `ArgumentParser` package dependency to the package; * implemented the `FileService` service in the _library_ target; * implemented the `CreateRootFolderTask` task in the _library_ target; * removed some unnecessary comments and boilerplate code; Reviewed-on: #2 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
57 lines
1.3 KiB
Swift
57 lines
1.3 KiB
Swift
import ArgumentParser
|
|
import ColibriLibrary
|
|
import Foundation
|
|
|
|
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 createRootFolder = CreateRootFolderTask(fileService: fileService)
|
|
|
|
let rootFolder = try await createRootFolder(
|
|
name: options.name,
|
|
at: options.locationURL
|
|
)
|
|
|
|
print(rootFolder)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// MARK: - Options
|
|
|
|
extension Colibri.Create {
|
|
struct Options: ParsableArguments {
|
|
|
|
// MARK: Properties
|
|
|
|
@Option(name: .shortAndLong)
|
|
var name: String
|
|
|
|
@Option(name: .shortAndLong)
|
|
var location: String?
|
|
|
|
// MARK: Computed
|
|
|
|
var locationURL: URL? {
|
|
location.flatMap { URL(fileURLWithPath: $0) }
|
|
}
|
|
|
|
}
|
|
}
|