Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
appstore-distribution ▾

xtool.git / Sources / XToolSupport / DSCommands / DSIdentifiersCommand.swift

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