4 $root = dirname(dirname(dirname(__FILE__
)));
5 require_once $root.'/scripts/__init_script__.php';
7 $args = new PhutilArgumentParser($argv);
8 $args->setTagline(pht('load files as image macros'));
9 $args->setSynopsis(<<<EOHELP
10 **add_macro.php** __image__ [--as __name__]
11 Add an image macro. This can be useful for importing a large number
15 $args->parseStandardArguments();
23 'Use a specific name instead of the first part of the image name.'),
31 $more = $args->getArg('more');
32 if (count($more) !== 1) {
33 $args->printHelpAndExit();
37 $data = Filesystem
::readFile($path);
39 $name = $args->getArg('as');
41 $name = head(explode('.', basename($path)));
44 $existing = id(new PhabricatorFileImageMacro())->loadOneWhere(
48 throw new Exception(pht("A macro already exists with the name '%s'!", $name));
51 $file = PhabricatorFile
::newFromFileData(
54 'name' => basename($path),
58 $macro = id(new PhabricatorFileImageMacro())
59 ->setFilePHID($file->getPHID())
65 echo pht("Added macro '%s' (%s).", $name, "F{$id}")."\n";