Implement basic argumentparser in mac crafter
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 20 Jun 2024 06:16:58 +0000 (14:16 +0800)
committerClaudio Cambra <developer@claudiocambra.com>
Mon, 8 Jul 2024 07:41:45 +0000 (15:41 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
admin/osx/mac-crafter/Package.swift
admin/osx/mac-crafter/Sources/main.swift

index 33c776c5cadd96bfdb318942c317599b6244a178..06ba25ca45b26e125fe0b26e62f1ca105ee229b7 100644 (file)
@@ -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"),
     ]
 )
index 1c3239d1cc999f8a2bd61535128fb52d3bc02062..a0f1f58d43be5e4ff2e476383a0759fb0b30a269 100644 (file)
  * 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()