2026-08-06 09f01778d5a034e2af50ae05da8908f7b6a871c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class TargetArgError extends Error {
  constructor(message, code) {
    super(message);
    this.name = 'TargetArgError';
    this.code = code;
  }
}
 
export function parseTargetPath(args = [], { strict = false } = {}) {
  let targetPath = null;
  for (let i = 0; i < args.length; i++) {
    const arg = String(args[i]);
    if (arg === '--target' || arg === '-t') {
      const next = args[i + 1];
      if (next && !String(next).startsWith('-')) {
        targetPath = String(next);
        i++;
        continue;
      }
      if (strict) {
        throw new TargetArgError('--target requires a path value.', 'TARGET_VALUE_MISSING');
      }
      continue;
    }
    if (arg.startsWith('--target=')) {
      const value = arg.slice('--target='.length);
      if (value) {
        targetPath = value;
        continue;
      }
      if (strict) {
        throw new TargetArgError('--target requires a path value.', 'TARGET_VALUE_MISSING');
      }
    }
  }
  return targetPath;
}
 
export function parseTargetOptions(args = [], options = {}) {
  const targetPath = parseTargetPath(args, options);
  return targetPath ? { targetPath } : {};
}