Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
main ▾

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

DSIdentifiersCommand.swift54 lines · 1.6 KiBRaw
1import XUtils
2import Foundation
3import ArgumentParser
4import XKit
5import DeveloperAPI
6
7struct 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
18struct 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}