|
2 | 2 | <?php
|
3 | 3 |
|
4 | 4 | /*
|
5 |
| - * Copyright 2011 Facebook, Inc. |
| 5 | + * Copyright 2012 Facebook, Inc. |
6 | 6 | *
|
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
8 | 8 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | $root = dirname(dirname(dirname(__FILE__)));
|
21 | 21 | require_once $root.'/scripts/__init_script__.php';
|
22 | 22 |
|
23 |
| -phutil_require_module('phutil', 'console'); |
| 23 | +$args = new PhutilArgumentParser($argv); |
| 24 | +$args->setSynopsis(<<<EOSYNOPSIS |
| 25 | +**import_project_symbols.php** [__options__] __project_name__ < symbols |
24 | 26 |
|
25 |
| -if ($argc !== 2) { |
26 |
| - echo phutil_console_format( |
27 |
| - "usage: import_project_symbols.php __project_name__ < __symbol_file__\n"); |
28 |
| - exit(1); |
| 27 | + Import project symbols (symbols are read from stdin). |
| 28 | +EOSYNOPSIS |
| 29 | + ); |
| 30 | +$args->parseStandardArguments(); |
| 31 | +$args->parse( |
| 32 | + array( |
| 33 | + array( |
| 34 | + 'name' => 'ignore-duplicates', |
| 35 | + 'help' => 'Ignore duplicate symbols, choosing one at random. By '. |
| 36 | + 'default, this script throws if given duplicate '. |
| 37 | + 'symbols.', |
| 38 | + ), |
| 39 | + array( |
| 40 | + 'name' => 'more', |
| 41 | + 'wildcard' => true, |
| 42 | + ), |
| 43 | + )); |
| 44 | + |
| 45 | +$ignore_duplicates = $args->getArg('ignore-duplicates'); |
| 46 | +$more = $args->getArg('more'); |
| 47 | +if (count($more) !== 1) { |
| 48 | + $args->printHelpAndExit(); |
29 | 49 | }
|
30 | 50 |
|
31 |
| -$project_name = $argv[1]; |
| 51 | +$project_name = head($more); |
32 | 52 | $project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
|
33 | 53 | 'name = %s',
|
34 | 54 | $project_name);
|
|
64 | 84 | list($all, $name, $type, $lang, $line_number, $path) = $matches;
|
65 | 85 |
|
66 | 86 | if (isset($map[$name][$type][$lang])) {
|
67 |
| - $previous = $map[$name][$type][$lang] + 1; |
68 |
| - throw new Exception( |
69 |
| - "Line #{$line_no} of input is invalid. It specifies a duplicate symbol ". |
70 |
| - "(same name, language, and type) which has already been defined ". |
71 |
| - "elsewhere. You must preprocess the symbol list to remove duplicates ". |
72 |
| - "and choose exactly one master definition for each symbol. This symbol ". |
73 |
| - "was previously defined on line #{$previous}.\n\n". |
74 |
| - "Line #{$line_no}:\n". |
75 |
| - $line."\n\n". |
76 |
| - "Line #{$previous}:\n". |
77 |
| - $input[$previous - 1]); |
| 87 | + if ($ignore_duplicates) { |
| 88 | + echo "Ignoring duplicate definition of '{$name}' on line {$line_no}.\n"; |
| 89 | + } else { |
| 90 | + $previous = $map[$name][$type][$lang] + 1; |
| 91 | + throw new Exception( |
| 92 | + "Line #{$line_no} of input is invalid. It specifies a duplicate ". |
| 93 | + "symbol (same name, language, and type) which has already been ". |
| 94 | + "defined elsewhere. You must preprocess the symbol list to remove ". |
| 95 | + "duplicates and choose exactly one master definition for each ". |
| 96 | + "symbol, or specify --ignore-duplicates. This symbol was previously ". |
| 97 | + "defined on line #{$previous}.\n\n". |
| 98 | + "Line #{$line_no}:\n". |
| 99 | + $line."\n\n". |
| 100 | + "Line #{$previous}:\n". |
| 101 | + $input[$previous - 1]); |
| 102 | + } |
78 | 103 | } else {
|
79 | 104 | $map[$name][$type][$lang] = $key;
|
80 | 105 | }
|
|
0 commit comments