Skip to content

Commit

Permalink
Merge branch 'issues/27' into release/0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ashur committed Dec 23, 2016
2 parents 91f9e21 + f256ec0 commit c140c1d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to Pug will be documented in this file (beginning with v0.5
## [Unreleased]
### Added
- Support for displaying project metadata
- Support for cloning new projects

## [0.7.1] - 2017-11-14
### Fixed
Expand Down
47 changes: 45 additions & 2 deletions lib/commands/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @command add
* @desc Start tracking a new project
* @usage add [<group>/]<name> <path>
* @usage add [<group>/]<name> <path> [--url=<url>]
* @alias track
*/
$commandAdd = new CLI\Command( 'add', 'Start tracking a new project', function( $name, $path )
Expand All @@ -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 );
Expand All @@ -46,7 +74,22 @@
return $output->flush();
});

/* Options */
$commandAdd->registerOption( 'url' );

/* Aliases */
$commandAdd->addAlias( 'track' );
$commandAdd->setUsage( 'add [<group>/]<name> <path>' );

/* Usage */
$commandAddUsage = <<<USAGE
add [<group>/]<name> <path> [--url=<url>]
OPTIONS
--url=<url>
Clone the Git repository at <url> to <path>.
USAGE;

$commandAdd->setUsage( $commandAddUsage );

return $commandAdd;
2 changes: 1 addition & 1 deletion vendor/huxtable/cli

0 comments on commit c140c1d

Please sign in to comment.