xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XToolSupport / DSCommands / DSIdentifiersCommand.swift
DSIdentifiersCommand.swift54 lines · 1.6 KiBRaw
| 1 | import XUtils |
| 2 | import Foundation |
| 3 | import ArgumentParser |
| 4 | import XKit |
| 5 | import DeveloperAPI |
| 6 | |
| 7 | struct DSIdentifiersCommand: AsyncParsableCommand { |
| 8 | static let configuration = CommandConfiguration( |
| 9 | commandName: "identifiers", |
| 10 | abstract: "Interact with bundle identifiers", |
| 11 | subcommands: [ |
| 12 | DSIdentifiersListCommand.self, |
| 13 | ], |
| 14 | defaultSubcommand: DSIdentifiersListCommand.self |
| 15 | ) |
| 16 | } |
| 17 | |
| 18 | struct DSIdentifiersListCommand: AsyncParsableCommand { |
| 19 | static let configuration = CommandConfiguration( |
| 20 | commandName: "list", |
| 21 | abstract: "List bundle identifiers" |
| 22 | ) |
| 23 | |
| 24 | func run() async throws { |
| 25 | let client = DeveloperAPIClient(auth: try AuthToken.saved().authData()) |
| 26 | |
| 27 | let bundleIDs = try await DeveloperAPIPages { |
| 28 | try await client.bundleIdsGetCollection().ok.body.json |
| 29 | } next: { |
| 30 | $0.links.next |
| 31 | } |
| 32 | .map(\.data) |
| 33 | .reduce(into: [], +=) |
| 34 | |
| 35 | for bundleID in bundleIDs { |
| 36 | d.out.print("- id: \(bundleID.id)") |
| 37 | guard let attributes = bundleID.attributes else { |
| 38 | continue |
| 39 | } |
| 40 | if let name = attributes.name { |
| 41 | d.out.print(" name: \(name)") |
| 42 | } |
| 43 | if let identifier = attributes.identifier { |
| 44 | d.out.print(" identifier: \(identifier)") |
| 45 | } |
| 46 | if let platform = attributes.platform { |
| 47 | d.out.print(" platform: \(platform.rawValue)") |
| 48 | } |
| 49 | if let seedId = attributes.seedId { |
| 50 | d.out.print(" seedId: \(seedId)") |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |