Skip to content

Commit f30be70

Browse files
feat: add ostype filter for device create command
1 parent 223b0e0 commit f30be70

File tree

3 files changed

+89
-8
lines changed

3 files changed

+89
-8
lines changed

messages/device-list.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
List the available virtual mobile devices for Lightning Web Component development.
44

5+
# flags.ostype.description
6+
7+
Filter Android devices by operating system type. Use 'default' to show only default OS type devices, or 'all' to show all devices. This flag applies only to Android devices.
8+
59
# device.list.action
610

711
Device List
@@ -14,3 +18,4 @@ generating list of supported devices
1418

1519
- <%= config.bin %> <%= command.id %> -p ios
1620
- <%= config.bin %> <%= command.id %> -p android
21+
- <%= config.bin %> <%= command.id %> -p android --ostype default

src/cli/commands/force/lightning/local/device/list.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import chalk from 'chalk';
99
import archy from 'archy';
10+
import { Flags } from '@salesforce/sf-plugins-core';
1011
import { Messages } from '@salesforce/core';
1112
import { z } from 'zod';
1213

@@ -19,7 +20,9 @@ import {
1920
CommandLineUtils,
2021
CommonUtils,
2122
FlagsConfigType,
22-
PerformanceMarkers
23+
PerformanceMarkers,
24+
PlatformConfig,
25+
Version
2326
} from '@salesforce/lwc-dev-mobile-core';
2427
import { DeviceListSchema } from '../../../../../schema/device.js';
2528

@@ -35,7 +38,13 @@ export class List extends BaseCommand {
3538
...CommandLineUtils.createFlag(FlagsConfigType.JsonFlag, false),
3639
...CommandLineUtils.createFlag(FlagsConfigType.OutputFormatFlag, false),
3740
...CommandLineUtils.createFlag(FlagsConfigType.LogLevelFlag, false),
38-
...CommandLineUtils.createFlag(FlagsConfigType.PlatformFlag, true)
41+
...CommandLineUtils.createFlag(FlagsConfigType.PlatformFlag, true),
42+
ostype: Flags.string({
43+
description: messages.getMessage('flags.ostype.description'),
44+
required: false,
45+
options: ['default', 'all'],
46+
helpValue: 'default|all'
47+
})
3948
};
4049

4150
protected _commandName = 'force:lightning:local:device:list';
@@ -47,6 +56,11 @@ export class List extends BaseCommand {
4756
return this.flagValues.platform as string;
4857
}
4958

59+
private get ostype(): string | undefined {
60+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
61+
return this.flagValues.ostype as string | undefined;
62+
}
63+
5064
protected static getOutputSchema(): z.ZodTypeAny {
5165
return DeviceListSchema;
5266
}
@@ -62,9 +76,24 @@ export class List extends BaseCommand {
6276
}
6377
performance.mark(this.perfMarker.startMarkName);
6478

65-
const devices = CommandLineUtils.platformFlagIsAndroid(this.platform)
66-
? await new AndroidDeviceManager().enumerateDevices()
67-
: await new AppleDeviceManager().enumerateDevices();
79+
let devices: AndroidDevice[] | AppleDevice[] = [];
80+
81+
if (CommandLineUtils.platformFlagIsAndroid(this.platform)) {
82+
if (this.ostype === undefined) {
83+
devices = await new AndroidDeviceManager().enumerateDevices();
84+
} else if (this.ostype === 'all') {
85+
devices = await new AndroidDeviceManager().enumerateDevices(null);
86+
} else if (this.ostype === 'default') {
87+
devices = await new AndroidDeviceManager().enumerateDevices([
88+
{
89+
osType: 'default',
90+
minOSVersion: Version.from(PlatformConfig.androidConfig().minSupportedRuntime)!
91+
}
92+
]);
93+
}
94+
} else {
95+
devices = await new AppleDeviceManager().enumerateDevices();
96+
}
6897

6998
performance.mark(this.perfMarker.endMarkName);
7099
if (!this.jsonEnabled()) {

test/unit/cli/commands/force/lightning/local/device/list.test.ts

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
CommonUtils,
1919
DeviceType,
2020
IOSUtils,
21+
PlatformConfig,
2122
Version
2223
} from '@salesforce/lwc-dev-mobile-core';
2324
import { expect } from 'chai';
@@ -26,7 +27,7 @@ import { List } from '../../../../../../../../src/cli/commands/force/lightning/l
2627
describe('Device List Tests', () => {
2728
const $$ = new TestContext();
2829

29-
const androidDevice = new AndroidDevice(
30+
const androidDeviceGoogleApi = new AndroidDevice(
3031
'Pixel_5_API_35',
3132
'Pixel 5 API 35',
3233
DeviceType.mobile,
@@ -35,6 +36,15 @@ describe('Device List Tests', () => {
3536
false
3637
);
3738

39+
const androidDeviceDefault = new AndroidDevice(
40+
'Pixel_Default',
41+
'Pixel Default',
42+
DeviceType.mobile,
43+
'default',
44+
new Version(35, 0, 0),
45+
false
46+
);
47+
3848
const appleDevice = new AppleDevice(
3949
'3627EBD5-E9EC-4EC4-8E89-C6A0232C920D',
4050
'iPhone 16',
@@ -59,18 +69,55 @@ describe('Device List Tests', () => {
5969

6070
it('Lists Android emulators for cli mode', async () => {
6171
const enumerateMock = stubMethod($$.SANDBOX, AndroidDeviceManager.prototype, 'enumerateDevices').resolves([
62-
androidDevice
72+
androidDeviceGoogleApi
6373
]);
6474
await List.run(['-p', 'android']);
6575

6676
expect(enumerateMock.called).to.be.true;
6777
expect(startCliActionMock.called).to.be.true;
6878
expect(stopCliActionMock.called).to.be.true;
79+
80+
expect(enumerateMock.calledWith()).to.be.true;
81+
});
82+
83+
it('Lists Android emulators with ostype flag set to default for cli mode', async () => {
84+
const enumerateMock = stubMethod($$.SANDBOX, AndroidDeviceManager.prototype, 'enumerateDevices').resolves([
85+
androidDeviceDefault,
86+
androidDeviceGoogleApi
87+
]);
88+
await List.run(['-p', 'android', '--ostype', 'default']);
89+
90+
expect(enumerateMock.called).to.be.true;
91+
expect(startCliActionMock.called).to.be.true;
92+
expect(stopCliActionMock.called).to.be.true;
93+
94+
expect(
95+
enumerateMock.calledWith([
96+
{
97+
osType: 'default',
98+
minOSVersion: Version.from(PlatformConfig.androidConfig().minSupportedRuntime)!
99+
}
100+
])
101+
).to.be.true;
102+
});
103+
104+
it('Lists Android emulators with ostype flag set to all for cli mode', async () => {
105+
const enumerateMock = stubMethod($$.SANDBOX, AndroidDeviceManager.prototype, 'enumerateDevices').resolves([
106+
androidDeviceDefault,
107+
androidDeviceGoogleApi
108+
]);
109+
await List.run(['-p', 'android', '--ostype', 'all']);
110+
111+
expect(enumerateMock.called).to.be.true;
112+
expect(startCliActionMock.called).to.be.true;
113+
expect(stopCliActionMock.called).to.be.true;
114+
115+
expect(enumerateMock.calledWith(null)).to.be.true;
69116
});
70117

71118
it('Lists Android emulators for json mode', async () => {
72119
const enumerateMock = stubMethod($$.SANDBOX, AndroidDeviceManager.prototype, 'enumerateDevices').resolves([
73-
androidDevice
120+
androidDeviceGoogleApi
74121
]);
75122
await List.run(['-p', 'android', '--json']);
76123

0 commit comments

Comments
 (0)