From fc9c5650e088ca0509d2e940948b703fe50324c2 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 20 Jun 2024 14:16:58 +0800 Subject: [PATCH] Implement basic argumentparser in mac crafter Signed-off-by: Claudio Cambra --- admin/osx/mac-crafter/Package.swift | 7 +- admin/osx/mac-crafter/Sources/main.swift | 91 ++++++++++++++---------- 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/admin/osx/mac-crafter/Package.swift b/admin/osx/mac-crafter/Package.swift index 33c776c5c..06ba25ca4 100644 --- a/admin/osx/mac-crafter/Package.swift +++ b/admin/osx/mac-crafter/Package.swift @@ -4,13 +4,16 @@ import PackageDescription let package = Package( - name: "builder", + name: "mac-crafter", platforms: [ .macOS(.v11), ], + dependencies: [ + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.4.0") + ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. - .executableTarget(name: "builder"), + .executableTarget(name: "mac-crafter"), ] ) diff --git a/admin/osx/mac-crafter/Sources/main.swift b/admin/osx/mac-crafter/Sources/main.swift index 1c3239d1c..a0f1f58d4 100644 --- a/admin/osx/mac-crafter/Sources/main.swift +++ b/admin/osx/mac-crafter/Sources/main.swift @@ -12,48 +12,63 @@ * for more details. */ +import ArgumentParser import Foundation -print("Configuring build tooling.") - -installIfMissing("git", "xcode-select --install") -installIfMissing( - "brew", - "curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | /bin/bash", - installCommandEnv: ["NONINTERACTIVE": "1"] -) -installIfMissing("inkscape", "brew install inkscape") -installIfMissing("python3", "brew install pyenv && pyenv install 3.12.4") - -print("Build tooling configured.") -print("Configuring KDE Craft.") - -let fm = FileManager.default -let currentDir = fm.currentDirectoryPath -let craftMasterDir = "\(currentDir)/craftmaster" - -if fm.fileExists(atPath: craftMasterDir) { - print("KDE Craft is already cloned.") -} else { - print("Cloning KDE Craft...") - shell("git clone --depth=1 https://invent.kde.org/packaging/craftmaster.git \(craftMasterDir)") -} +struct MacCrafter: ParsableCommand { + static let configuration = CommandConfiguration( + abstract: "A Swift command-line tool to manage blog post banners" + ) + + enum MacCrafterError: Error { + case failedEnumeration(String) + } + + mutating func run() throws { + print("Configuring build tooling.") + + installIfMissing("git", "xcode-select --install") + installIfMissing( + "brew", + "curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | /bin/bash", + installCommandEnv: ["NONINTERACTIVE": "1"] + ) + installIfMissing("inkscape", "brew install inkscape") + installIfMissing("python3", "brew install pyenv && pyenv install 3.12.4") + + print("Build tooling configured.") + print("Configuring KDE Craft.") -print("Configuring Nextcloud Desktop Client blueprints for KDE Craft...") + let fm = FileManager.default + let currentDir = fm.currentDirectoryPath + let craftMasterDir = "\(currentDir)/craftmaster" -let repoRootDir = "\(currentDir)/../.." -let craftMasterIni = "\(repoRootDir)/craftmaster.ini" -let craftMasterPy = "\(craftMasterDir)/CraftMaster.py" -let craftTarget = "macos-clang-arm64" -let craftCommand = "python3 \(craftMasterPy) --config \(craftMasterIni) --target \(craftTarget) -c" -let clientBlueprintsGitUrl = "https://github.com/nextcloud/desktop-client-blueprints.git" -shell("\(craftCommand) --add-blueprint-repository \(clientBlueprintsGitUrl)") + if fm.fileExists(atPath: craftMasterDir) { + print("KDE Craft is already cloned.") + } else { + print("Cloning KDE Craft...") + shell("git clone --depth=1 https://invent.kde.org/packaging/craftmaster.git \(craftMasterDir)") + } -print("Crafting KDE Craft...") -shell("\(craftCommand) craft") + print("Configuring Nextcloud Desktop Client blueprints for KDE Craft...") -print("Crafting Nextcloud Desktop Client dependencies...") -shell("\(craftCommand) --install-deps nextcloud-client") + let repoRootDir = "\(currentDir)/../.." + let craftMasterIni = "\(repoRootDir)/craftmaster.ini" + let craftMasterPy = "\(craftMasterDir)/CraftMaster.py" + let craftTarget = "macos-clang-arm64" + let craftCommand = "python3 \(craftMasterPy) --config \(craftMasterIni) --target \(craftTarget) -c" + let clientBlueprintsGitUrl = "https://github.com/nextcloud/desktop-client-blueprints.git" + shell("\(craftCommand) --add-blueprint-repository \(clientBlueprintsGitUrl)") + + print("Crafting KDE Craft...") + shell("\(craftCommand) craft") + + print("Crafting Nextcloud Desktop Client dependencies...") + shell("\(craftCommand) --install-deps nextcloud-client") + + print("Crafting Nextcloud Desktop Client...") + shell("\(craftCommand) --src-dir \(repoRootDir) nextcloud-client") + } +} -print("Crafting Nextcloud Desktop Client...") -shell("\(craftCommand) --src-dir \(repoRootDir) nextcloud-client") +MacCrafter.main() -- 2.30.2