xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XToolSupport / DSCommands / DSTeamsCommand.swift
DSTeamsCommand.swift37 lines · 1.2 KiBRaw
| 1 | import Foundation |
| 2 | import ArgumentParser |
| 3 | import XKit |
| 4 | |
| 5 | struct DSTeamsCommand: ParsableCommand { |
| 6 | static let configuration = CommandConfiguration( |
| 7 | commandName: "teams", |
| 8 | abstract: "Interact with development teams", |
| 9 | subcommands: [ |
| 10 | DSTeamsListCommand.self |
| 11 | ], |
| 12 | defaultSubcommand: DSTeamsListCommand.self |
| 13 | ) |
| 14 | } |
| 15 | |
| 16 | struct DSTeamsListCommand: AsyncParsableCommand { |
| 17 | static let configuration = CommandConfiguration( |
| 18 | commandName: "list", |
| 19 | abstract: "List teams" |
| 20 | ) |
| 21 | |
| 22 | func run() async throws { |
| 23 | let token = try AuthToken.saved() |
| 24 | |
| 25 | guard case let .xcode(authData) = token.authData() else { |
| 26 | throw Console.Error("This command requires password-based authentication") |
| 27 | } |
| 28 | let client = DeveloperServicesClient(authData: authData) |
| 29 | let teams: [DeveloperServicesTeam] = try await client.send(DeveloperServicesListTeamsRequest()) |
| 30 | print( |
| 31 | teams.map { |
| 32 | "\($0.name) [\($0.status)]: \($0.id.rawValue)" + |
| 33 | $0.memberships.map { "\n- \($0.name) (\($0.platform))" }.joined() |
| 34 | }.joined(separator: "\n") |
| 35 | ) |
| 36 | } |
| 37 | } |