Skip to content

Commit

Permalink
Does not handle 'iPad Pro (9.7 inch)' and 'iPad Pro (12.9 inch)' in l…
Browse files Browse the repository at this point in the history
…isting devices. This closes #11
  • Loading branch information
shazron committed Oct 20, 2016
1 parent ffa1289 commit 2c9d4be
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions lib/simctl-list-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,47 @@ function parseLine(line) {
}
}

function isUUID(text) {
var regExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
return regExp.test(text);
}

function parseDevice(line) {
if (line.indexOf('--') === 0) {
changeDeviceRuntime.apply(this, [line]);
return;
}

// example: iPhone 4s (3717C817-6AD7-42B8-ACF3-405CB9E96375) (Shutdown) (unavailable)
// example: iPad Pro (9.7 inch) (1C5590C8-8AE7-4C27-AD06-84C801702945) (Shutdown) (unavailable)
// the last capture group might not be there if available
// the first parenthesized group might be part of the name

var available = false;

var regExp = /(.*)\(([^)]+)\)\s\(([^)]+)\)\s\(([^)]+)\)/;
var matches = regExp.exec(line);
if (!matches) {
regExp = /(.*)\(([^)]+)\)\s\(([^)]+)\)/;
matches = regExp.exec(line);
available = true;
var regExp = /([^)]*)\s\(([^)]+)\)/g;
var items = [];
var matches;

while ((matches = regExp.exec(line)) !== null) {
if (matches[1].length > 0) {
if (isUUID(matches[2])) { // next is uuid, so push both name and id
items.push(matches[1]);
items.push(matches[2]);
} else { // name is in the next paren. group (not UUID), use whole match
items.push(matches[0]);
}
} else { // no match for name, just push second match
items.push(matches[2]);
}
}

if (matches) {
if (items.length) {
var obj = {
'name': matches[1].trim(),
'id': matches[2].trim(),
'state': matches[3].trim(),
'available': available
'name': items[0].trim(),
'id': items[1].trim(),
'state': items[2].trim(),
'available': items[3] === undefined
};

this._deviceRuntime.devices.push(obj);
Expand Down

0 comments on commit 2c9d4be

Please sign in to comment.