MCPcopy Index your code
hub / github.com/callstack/agent-device / handleOpenCommand

Function handleOpenCommand

src/core/dispatch.ts:240–310  ·  view source on GitHub ↗
(
  device: DeviceInfo,
  interactor: Interactor,
  positionals: string[],
  context: DispatchContext | undefined,
)

Source from the content-addressed store, hash-verified

238
239// fallow-ignore-next-line complexity
240async function handleOpenCommand(
241 device: DeviceInfo,
242 interactor: Interactor,
243 positionals: string[],
244 context: DispatchContext | undefined,
245): Promise<Record<string, unknown>> {
246 const app = positionals[0];
247 const url = positionals[1];
248 const launchConsole = context?.launchConsole;
249 const launchArgs = context?.launchArgs;
250 if (positionals.length > 2) {
251 throw new AppError('INVALID_ARGS', 'open accepts at most two arguments: <app|url> [url]');
252 }
253 if (!app) {
254 if (launchConsole) {
255 throw new AppError('INVALID_ARGS', '--launch-console requires an app target');
256 }
257 if (launchArgs && launchArgs.length > 0) {
258 throw new AppError('INVALID_ARGS', '--launch-args requires an app target');
259 }
260 await interactor.openDevice();
261 return { app: null, ...successText('Opened device') };
262 }
263 if (launchConsole && (!isIosFamily(device) || device.kind !== 'simulator')) {
264 throw new AppError('UNSUPPORTED_OPERATION', LAUNCH_CONSOLE_IOS_SIMULATOR_ONLY_MESSAGE);
265 }
266 if (device.platform === 'linux' && launchArgs && launchArgs.length > 0) {
267 throw new AppError('UNSUPPORTED_OPERATION', '--launch-args is not supported on Linux.');
268 }
269 if (url !== undefined) {
270 if (isDeepLinkTarget(app)) {
271 throw new AppError(
272 'INVALID_ARGS',
273 'open <app> <url> requires an app target as the first argument',
274 );
275 }
276 if (!isDeepLinkTarget(url)) {
277 throw new AppError('INVALID_ARGS', 'open <app> <url> requires a valid URL target');
278 }
279 if (launchConsole) {
280 throw new AppError('INVALID_ARGS', LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE);
281 }
282 await interactor.open(app, {
283 activity: context?.activity,
284 appBundleId: context?.appBundleId,
285 launchArgs,
286 url,
287 });
288 return { app, url, ...successText(`Opened: ${app}`) };
289 }
290 if (launchConsole && isDeepLinkTarget(app)) {
291 throw new AppError('INVALID_ARGS', LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE);
292 }
293 if (context?.clearAppState) {
294 if (isDeepLinkTarget(app)) {
295 throw new AppError(
296 'INVALID_ARGS',
297 'Clearing app state requires an app target, not a deep link.',

Callers 1

dispatch.tsFile · 0.70

Calls 6

successTextFunction · 0.90
isIosFamilyFunction · 0.90
isDeepLinkTargetFunction · 0.90
openDeviceMethod · 0.80
openMethod · 0.80
setSettingMethod · 0.80

Tested by

no test coverage detected