Skip to content

Commit 176a3f9

Browse files
committed
Fix optionalIntentArguments
1 parent 1f7ae88 commit 176a3f9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/helpers.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,28 @@ function buildStartCmd (startAppOptions, apiLevel) {
147147
cmd.push('-f', startAppOptions.flags);
148148
}
149149
if (startAppOptions.optionalIntentArguments) {
150-
cmd.push(startAppOptions.optionalIntentArguments);
150+
// expect optionalIntentArguments to be something like '-x options',
151+
// '-y option argument' or a combination of the two
152+
let argRe = /(-[^\s]+) ([^-]+)/g;
153+
while (true) {
154+
let optionalIntentArguments = argRe.exec(startAppOptions.optionalIntentArguments);
155+
if (!optionalIntentArguments) {
156+
break;
157+
}
158+
let flag = optionalIntentArguments[1];
159+
let space = optionalIntentArguments[2].indexOf(' ');
160+
let arg, value;
161+
if (space === -1) {
162+
arg = optionalIntentArguments[2];
163+
} else {
164+
arg = optionalIntentArguments[2].substring(0, space).trim();
165+
value = optionalIntentArguments[2].substring(space + 1).trim();
166+
}
167+
cmd.push(flag, arg);
168+
if (value) {
169+
cmd.push(value);
170+
}
171+
}
151172
}
152173
return cmd;
153174
}

test/unit/apk-utils-specs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ const should = chai.should(),
1111
act = '.ContactManager',
1212
startAppOptions = {stopApp: true, action: 'action', category: 'cat',
1313
flags: 'flags', pkg: 'pkg', activity: 'act',
14-
optionalIntentArguments: '-x options'},
14+
optionalIntentArguments: '-x options -y option argument -z option arg with spaces'},
1515
cmd = ['am', 'start', '-n', 'pkg/act', '-S', '-a', 'action', '-c', 'cat',
16-
'-f', 'flags', '-x options'],
16+
'-f', 'flags', '-x', 'options', '-y', 'option', 'argument',
17+
'-z', 'option', 'arg with spaces'],
1718
language = 'en',
1819
country = 'US',
1920
locale = 'en-US';

0 commit comments

Comments
 (0)