-
Notifications
You must be signed in to change notification settings - Fork 74
/
list.ts
70 lines (62 loc) · 2.35 KB
/
list.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Flags } from '@oclif/core';
import assert from 'assert';
import EasCommand from '../../commandUtils/EasCommand';
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import { EasPaginatedQueryFlags, getPaginatedQueryOptions } from '../../commandUtils/pagination';
import {
listAndRenderAppleDevicesOnAppleTeamAsync,
selectAppleTeamOnAccountAsync,
} from '../../devices/queries';
import { getOwnerAccountForProjectIdAsync } from '../../project/projectUtils';
import { enableJsonOutput } from '../../utils/json';
export default class BuildList extends EasCommand {
static override description = 'list all registered devices for your account';
static override flags = {
'apple-team-id': Flags.string(),
...EasPaginatedQueryFlags,
...EasNonInteractiveAndJsonFlags,
};
static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.LoggedIn,
};
async runAsync(): Promise<void> {
const { flags } = await this.parse(BuildList);
const paginatedQueryOptions = getPaginatedQueryOptions(flags);
const {
privateProjectConfig: { projectId },
loggedIn: { graphqlClient },
} = await this.getContextAsync(BuildList, {
nonInteractive: paginatedQueryOptions.nonInteractive,
});
let appleTeamIdentifier = flags['apple-team-id'];
let appleTeamName;
if (paginatedQueryOptions.json) {
enableJsonOutput();
}
const account = await getOwnerAccountForProjectIdAsync(graphqlClient, projectId);
// if they don't provide a team id, fetch devices on their account
if (!appleTeamIdentifier) {
const selectedAppleTeam = await selectAppleTeamOnAccountAsync(graphqlClient, {
accountName: account.name,
paginatedQueryOptions: {
...paginatedQueryOptions,
offset: 0,
limit: undefined,
},
selectionPromptTitle: 'What Apple team would you like to list devices for?',
});
appleTeamIdentifier = selectedAppleTeam.appleTeamIdentifier;
appleTeamName = selectedAppleTeam.appleTeamName;
}
assert(appleTeamIdentifier, 'No team identifier is specified');
await listAndRenderAppleDevicesOnAppleTeamAsync(graphqlClient, {
accountName: account.name,
appleTeam: {
appleTeamIdentifier,
appleTeamName,
},
paginatedQueryOptions,
});
}
}