Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistLiberateWorkflow.php
| Show All 31 Lines | |||||
| EOTEXT | EOTEXT | ||||
| ); | ); | ||||
| } | } | ||||
| public function getArguments() { | public function getArguments() { | ||||
| return array( | return array( | ||||
| 'all' => array( | 'all' => array( | ||||
| 'help' => | 'help' => | ||||
| "Drop the module cache before liberating. This will completely ". | 'Drop the module cache before liberating. This will completely '. | ||||
| "reanalyze the entire library. Thorough, but slow!", | 'reanalyze the entire library. Thorough, but slow!', | ||||
| ), | ), | ||||
| 'force-update' => array( | 'force-update' => array( | ||||
| 'help' => | 'help' => | ||||
| "Force the library map to be updated, even in the presence of ". | 'Force the library map to be updated, even in the presence of '. | ||||
| "lint errors.", | 'lint errors.', | ||||
| ), | ), | ||||
| 'library-name' => array( | 'library-name' => array( | ||||
| 'param' => 'name', | 'param' => 'name', | ||||
| 'help' => | 'help' => | ||||
| "Use a flag for library name rather than awaiting user input.", | 'Use a flag for library name rather than awaiting user input.', | ||||
| ), | ), | ||||
| 'remap' => array( | 'remap' => array( | ||||
| 'hide' => true, | 'hide' => true, | ||||
| 'help' => | 'help' => | ||||
| "Internal. Run the remap step of liberation. You do not need to ". | 'Internal. Run the remap step of liberation. You do not need to '. | ||||
| "run this unless you are debugging the workflow.", | 'run this unless you are debugging the workflow.', | ||||
| ), | ), | ||||
| 'verify' => array( | 'verify' => array( | ||||
| 'hide' => true, | 'hide' => true, | ||||
| 'help' => | 'help' => | ||||
| "Internal. Run the verify step of liberation. You do not need to ". | 'Internal. Run the verify step of liberation. You do not need to '. | ||||
| "run this unless you are debugging the workflow.", | 'run this unless you are debugging the workflow.', | ||||
| ), | ), | ||||
| 'upgrade' => array( | 'upgrade' => array( | ||||
| 'hide' => true, | 'hide' => true, | ||||
| 'help' => "Experimental. Upgrade library to v2.", | 'help' => 'Experimental. Upgrade library to v2.', | ||||
| ), | ), | ||||
| '*' => 'argv', | '*' => 'argv', | ||||
| ); | ); | ||||
| } | } | ||||
| public function run() { | public function run() { | ||||
| $argv = $this->getArgument('argv'); | $argv = $this->getArgument('argv'); | ||||
| if (count($argv) > 1) { | if (count($argv) > 1) { | ||||
| Show All 17 Lines | if (Filesystem::pathExists($path) && is_dir($path)) { | ||||
| ->find(); | ->find(); | ||||
| } else { | } else { | ||||
| $init = null; | $init = null; | ||||
| } | } | ||||
| if ($init) { | if ($init) { | ||||
| if (count($init) > 1) { | if (count($init) > 1) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Specified directory contains more than one libphutil library. Use ". | 'Specified directory contains more than one libphutil library. Use '. | ||||
| "a more specific path."); | 'a more specific path.'); | ||||
| } | } | ||||
| $path = Filesystem::resolvePath(dirname(reset($init)), $path); | $path = Filesystem::resolvePath(dirname(reset($init)), $path); | ||||
| } else { | } else { | ||||
| $found = false; | $found = false; | ||||
| foreach (Filesystem::walkToRoot($path) as $dir) { | foreach (Filesystem::walkToRoot($path) as $dir) { | ||||
| if (Filesystem::pathExists($dir.'/__phutil_library_init__.php')) { | if (Filesystem::pathExists($dir.'/__phutil_library_init__.php')) { | ||||
| $path = $dir; | $path = $dir; | ||||
| $found = true; | $found = true; | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | private function upgradeLibrary($path) { | ||||
| echo "Upgrading library to v2...\n"; | echo "Upgrading library to v2...\n"; | ||||
| $this->liberateVersion2($path); | $this->liberateVersion2($path); | ||||
| } | } | ||||
| private function liberateCreateDirectory($path) { | private function liberateCreateDirectory($path) { | ||||
| if (Filesystem::pathExists($path)) { | if (Filesystem::pathExists($path)) { | ||||
| if (!is_dir($path)) { | if (!is_dir($path)) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Provide a directory to create or update a libphutil library in."); | 'Provide a directory to create or update a libphutil library in.'); | ||||
| } | } | ||||
| return; | return; | ||||
| } | } | ||||
| echo "The directory '{$path}' does not exist."; | echo "The directory '{$path}' does not exist."; | ||||
| if (!phutil_console_confirm('Do you want to create it?')) { | if (!phutil_console_confirm('Do you want to create it?')) { | ||||
| throw new ArcanistUsageException("Cancelled."); | throw new ArcanistUsageException('Cancelled.'); | ||||
| } | } | ||||
| execx('mkdir -p %s', $path); | execx('mkdir -p %s', $path); | ||||
| } | } | ||||
| private function liberateCreateLibrary($path) { | private function liberateCreateLibrary($path) { | ||||
| $init_path = $path.'/__phutil_library_init__.php'; | $init_path = $path.'/__phutil_library_init__.php'; | ||||
| if (Filesystem::pathExists($init_path)) { | if (Filesystem::pathExists($init_path)) { | ||||
| return; | return; | ||||
| } | } | ||||
| echo "Creating new libphutil library in '{$path}'.\n"; | echo "Creating new libphutil library in '{$path}'.\n"; | ||||
| do { | do { | ||||
| $name = $this->getArgument("library-name"); | $name = $this->getArgument('library-name'); | ||||
| if ($name === null) { | if ($name === null) { | ||||
| echo "Choose a name for the new library.\n"; | echo "Choose a name for the new library.\n"; | ||||
| $name = phutil_console_prompt('What do you want to name this library?'); | $name = phutil_console_prompt('What do you want to name this library?'); | ||||
| } else { | } else { | ||||
| echo "Using library name {$name}.\n"; | echo "Using library name {$name}.\n"; | ||||
| } | } | ||||
| if (preg_match('/^[a-z-]+$/', $name)) { | if (preg_match('/^[a-z-]+$/', $name)) { | ||||
| break; | break; | ||||
| Show All 22 Lines | |||||