diff --git a/.gitignore b/.gitignore index 0023a53..47bd4c1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ DerivedData/ .swiftpm/configuration/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc +Package.resolved diff --git a/Package.swift b/Package.swift index f8d154b..8c083aa 100644 --- a/Package.swift +++ b/Package.swift @@ -2,9 +2,17 @@ import PackageDescription let package = Package( - name: "darwin-apk", - targets: [ - .executableTarget( - name: "darwin-apk"), - ] + name: "darwin-apk", + dependencies: [ + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + ], + targets: [ + .executableTarget( + name: "dpk", + dependencies: [ + .product(name: "ArgumentParser", package: "swift-argument-parser"), + ], + path: "Sources/dpk-cli" + ), + ] ) diff --git a/Sources/dpk-cli/CommandLine.swift b/Sources/dpk-cli/CommandLine.swift new file mode 100644 index 0000000..f508b80 --- /dev/null +++ b/Sources/dpk-cli/CommandLine.swift @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: Apache-2.0 + +import ArgumentParser + +@main +struct DarwinApkCLI: ParsableCommand { + static let configuration = CommandConfiguration( + commandName: "dpk", + abstract: "Command-line interface for managing packages installed via darwin-apk.", + subcommands: [ + Install.self, + Remove.self, + Update.self, + Upgrade.self + ]) +} + +extension DarwinApkCLI { + struct Install: ParsableCommand { + static let configuration = CommandConfiguration( + commandName: "add", + abstract: "Install package(s) to the system.", + aliases: [ "install", "i", "a" ]) + + @Argument(help: "One or more package names to install to the system.") + var packages: [String] + + func run() throws { + print("installing \"\(packages.joined(separator: "\", \""))\"") + } + } + + struct Remove: ParsableCommand { + static let configuration = CommandConfiguration( + commandName: "remove", + abstract: "Remove specified package(s) from the system.", + aliases: [ "uninstall", "del", "rem", "r" ]) + + @Argument(help: "One or more package names to uninstall from the system.") + var packages: [String] + + func run() throws { + print("uninstalling \"\(packages.joined(separator: "\", \""))\"") + } + } + + struct Update: ParsableCommand { + static let configuration = CommandConfiguration( + commandName: "update", + abstract: "Update the system package repositories.", + aliases: [ "u" ]) + + func run() throws { + print("updating package repositories") + } + } + + struct Upgrade: ParsableCommand { + static let configuration = CommandConfiguration( + commandName: "upgrade", + abstract: "Upgrade installed packages.", + aliases: [ "U" ]) + + @Argument(help: "Optionally specify packages to upgrade. Otherwise upgrade all packages installed on the system.") + var packages: [String] = [] + + func run() throws { + if packages.isEmpty { + print("upgrading system") + } else { + print("upgrading invidual packages: \"\(packages.joined(separator: "\", \""))\"") + } + } + } +} diff --git a/Sources/main.swift b/Sources/main.swift deleted file mode 100644 index 44e20d5..0000000 --- a/Sources/main.swift +++ /dev/null @@ -1,4 +0,0 @@ -// The Swift Programming Language -// https://docs.swift.org/swift-book - -print("Hello, world!")