Skip to content

Commit 72cbd8d

Browse files
ryanluooryan.luogabebear
authored
Add --json support for list_bundle_id (#457)
* add --json support for list_bundle_id * only get result's keys when --json is not set Co-authored-by: ryan.luo <ryan.luo@bytedance.com> Co-authored-by: Gabe Giosia <giosia@google.com>
1 parent 575cd60 commit 72cbd8d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,18 +1580,28 @@ void list_bundle_id(AMDeviceRef device)
15801580
check_error(AMDeviceValidatePairing(device));
15811581
check_error(AMDeviceStartSession(device));
15821582

1583-
NSArray *a = [NSArray arrayWithObjects:@"CFBundleIdentifier", nil];
1583+
NSArray *a = [NSArray arrayWithObjects:
1584+
@"CFBundleIdentifier",
1585+
@"CFBundleName",
1586+
@"CFBundleDisplayName",
1587+
@"CFBundleVersion",
1588+
@"CFBundleShortVersionString", nil];
15841589
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:a forKey:@"ReturnAttributes"];
15851590
CFDictionaryRef options = (CFDictionaryRef)optionsDict;
15861591
CFDictionaryRef result = nil;
15871592
check_error(AMDeviceLookupApplications(device, options, &result));
15881593

1589-
CFIndex count;
1590-
count = CFDictionaryGetCount(result);
1591-
const void *keys[count];
1592-
CFDictionaryGetKeysAndValues(result, keys, NULL);
1593-
for(int i = 0; i < count; ++i) {
1594-
NSLogOut(@"%@", (CFStringRef)keys[i]);
1594+
if (_json_output) {
1595+
NSLogJSON(@{@"Event": @"ListBundleId",
1596+
@"Apps": (NSDictionary *)result});
1597+
} else {
1598+
CFIndex count;
1599+
count = CFDictionaryGetCount(result);
1600+
const void *keys[count];
1601+
CFDictionaryGetKeysAndValues(result, keys, NULL);
1602+
for(int i = 0; i < count; ++i) {
1603+
NSLogOut(@"%@", (CFStringRef)keys[i]);
1604+
}
15951605
}
15961606

15971607
check_error(AMDeviceStopSession(device));

0 commit comments

Comments
 (0)