Skip to content

Commit

Permalink
Merge pull request #17 from ashur/feature/install
Browse files Browse the repository at this point in the history
added 'install' command (fixes #16)
  • Loading branch information
ashur authored Nov 14, 2016
2 parents 8df5bb1 + ed9f260 commit 87bd42c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/commands/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Huxtable\CLI\Command;
use Huxtable\Core\File;

/**
* @name install
* @description Symlink 'pug' to a convenient path
* @usage install <dir>
*/
$command = new Command( 'install', 'Symlink \'pug\' to a convenient path', function( $dir )
{
$pathSource = dirname( dirname( __DIR__ ) ) . '/bin/pug';

try
{
$destinationDirectory = new File\Directory( $dir );

if( !$destinationDirectory->exists() )
{
throw new \Exception( "Invalid location: '{$dir}' does not exist" );
}
}
catch( \Exception $e )
{
throw new Command\CommandInvokedException( $e->getMessage(), 1 );
}

if( !$destinationDirectory->isWritable() )
{
throw new Command\CommandInvokedException( "Invalid location: You do not have permission to write to '{$destinationDirectory}'" );
}

$target = $destinationDirectory->child( 'pug' );
$source = new File\File( $pathSource );

if( !$source->exists() )
{
throw new Command\CommandInvokedException( "Invalid source: '{$source}' not found", 1 );
}

if( $target->exists() || is_link( $target->getPathname() ) )
{
throw new Command\CommandInvokedException( "Invalid target: '{$target}' already exists", 1 );
}

symlink( $source, $target );
echo "Linked to '{$target}'" . PHP_EOL;
});

return $command;

0 comments on commit 87bd42c

Please sign in to comment.