From afc377e316a63bb4e4af601d7a32ab82e1cdd62b Mon Sep 17 00:00:00 2001 From: Ashur Cabrera Date: Fri, 23 Dec 2016 12:34:22 -0700 Subject: [PATCH 1/2] pulled up huxtable/cli --- vendor/huxtable/cli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/huxtable/cli b/vendor/huxtable/cli index 2e9a5a6..696ac49 160000 --- a/vendor/huxtable/cli +++ b/vendor/huxtable/cli @@ -1 +1 @@ -Subproject commit 2e9a5a6d362e7276bff2cc2cac81f5880861b0d4 +Subproject commit 696ac49c174623056e4850b0ed82fa264d3dd7a7 From f256ec07260eb5a0ab08f0415a72b8057ecf9898 Mon Sep 17 00:00:00 2001 From: Ashur Cabrera Date: Fri, 23 Dec 2016 12:35:18 -0700 Subject: [PATCH 2/2] added support for cloning projects (fixes #27) --- CHANGELOG.md | 4 ++++ lib/commands/add.php | 47 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5685fb8..ac06a7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to Pug will be documented in this file (beginning with v0.5 😅). +## [Unreleased] +### Added +- Support for cloning new projects + ## [0.7.1] - 2017-11-14 ### Fixed - Iterate through post-update submodule inventory during state restoration diff --git a/lib/commands/add.php b/lib/commands/add.php index 8529fcc..ae04daf 100644 --- a/lib/commands/add.php +++ b/lib/commands/add.php @@ -11,7 +11,7 @@ /** * @command add * @desc Start tracking a new project - * @usage add [/] + * @usage add [/] [--url=] * @alias track */ $commandAdd = new CLI\Command( 'add', 'Start tracking a new project', function( $name, $path ) @@ -25,6 +25,34 @@ throw new CLI\Command\CommandInvokedException( "Couldn't track project. {$e->getMessage()}", 1 ); } + /* Clone new project to track */ + $repoURL = $this->getOptionValue( 'url' ); + if( !is_null( $repoURL ) ) + { + if( $dirProject->exists() ) + { + if( count( $dirProject->children() ) > 0 ) + { + throw new CLI\Command\CommandInvokedException( "Couldn't clone repository: '{$path}' already exists and is not an empty directory.", 1 ); + } + } + + echo "Cloning into '{$dirProject}'... " ; + $result = CLI\Shell::exec( "git clone --recursive {$repoURL} {$dirProject}", true, ' > ' ); + + if( $result['exitCode'] === 0 ) + { + echo 'done.' . PHP_EOL; + } + else + { + echo 'failed:' . PHP_EOL . PHP_EOL; + echo $result['output']['formatted'] . PHP_EOL; + + exit( 1 ); + } + } + if( !$dirProject->exists() ) { throw new CLI\Command\CommandInvokedException( "Couldn't track project. Path '{$path}' not found.", 1 ); @@ -45,7 +73,22 @@ return listProjects( $pug->getProjects() ); }); +/* Options */ +$commandAdd->registerOption( 'url' ); + +/* Aliases */ $commandAdd->addAlias( 'track' ); -$commandAdd->setUsage( 'add [/] ' ); + +/* Usage */ +$commandAddUsage = <</] [--url=] + +OPTIONS + --url= + Clone the Git repository at to . + +USAGE; + +$commandAdd->setUsage( $commandAddUsage ); return $commandAdd;