Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

1.6 KB
Raw Blame
import XUtils
import Foundation
import ArgumentParser
import XKit
import DeveloperAPI

struct DSIdentifiersCommand: AsyncParsableCommand {
    static let configuration = CommandConfiguration(
        commandName: "identifiers",
        abstract: "Interact with bundle identifiers",
        subcommands: [
            DSIdentifiersListCommand.self,
        ],
        defaultSubcommand: DSIdentifiersListCommand.self
    )
}

struct DSIdentifiersListCommand: AsyncParsableCommand {
    static let configuration = CommandConfiguration(
        commandName: "list",
        abstract: "List bundle identifiers"
    )

    func run() async throws {
        let client = DeveloperAPIClient(auth: try AuthToken.saved().authData())

        let bundleIDs = try await DeveloperAPIPages(\.links.next) {
            try await client.bundleIdsGetCollection().ok.body.json
        }
        .map(\.data)
        .reduce(into: [], +=)

        for bundleID in bundleIDs {
            d.out.print("- id: \(bundleID.id)")
            guard let attributes = bundleID.attributes else {
                continue
            }
            if let name = attributes.name {
                d.out.print("  name: \(name)")
            }
            if let identifier = attributes.identifier {
                d.out.print("  identifier: \(identifier)")
            }
            if let platform = attributes.platform {
                d.out.print("  platform: \(platform.rawValue)")
            }
            if let seedId = attributes.seedId {
                d.out.print("  seedId: \(seedId)")
            }
        }
    }
}