diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e88c78..204494a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ All notable changes to Pug will be documented in this file (beginning with v0.5 😅). -## [0.6.0] - 2015-08-10 +## [0.7.0] - 2017-11-14 +### Added +- `pug install` + +## [0.6.0] - 2016-08-10 ### Added - Namespaces - Command support for namespaces (aka groups): enable, disable, remove, update diff --git a/README.md b/README.md index afa8282..70627be 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,30 @@ One command is all you need to update local repositories and their submodules. I ## Installation +First, clone this repository: + ``` +$ cd ~/tools $ git clone --recursive https://github.com/ashur/pug.git ``` +> 🎉 **New in v0.7** + +Next, run the `install` command and include a directory that's already on your `$PATH`: + +``` +$ pug/bin/pug install /usr/local/bin +Linked to '/usr/local/bin/pug' +``` + +This will symlink the `pug` executable, letting you run `pug` from anywhere on the command line: + +``` +$ cd ~/Desktop/ +$ pug --version +pug version 0.7.0 +``` + ### Requirements Pug requires PHP 5.4 or greater @@ -42,34 +62,11 @@ $ pug up > > ``` > $ pug --version -> pug version 0.5.0 +> pug version 0.7.0 > ``` > > Nice. 😁 -### Extra Credit - -Let's say you cloned Pug to a local directory `~/tools`: - -``` -$ cd ~/tools -$ git clone --recursive https://github.com/ashur/pug.git -``` - -You'll probably want to symlink the Pug executable to a directory already on your `$PATH`: - -``` -$ ln -s ~/tools/pug/bin/pug /usr/local/bin/pug -``` - -This lets you run `pug` commands from anywhere on the command line, not just from inside the Pug repository folder. - -Alternatively, you can add the repository's `bin` folder to your environment `$PATH`. For example: - -``` -export PATH=$PATH:$HOME/tools/pug/bin -``` - ## Basics diff --git a/lib/commands/install.php b/lib/commands/install.php new file mode 100644 index 0000000..782171a --- /dev/null +++ b/lib/commands/install.php @@ -0,0 +1,51 @@ + + */ +$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; diff --git a/lib/config.php b/lib/config.php index 6a5756b..ac796f3 100644 --- a/lib/config.php +++ b/lib/config.php @@ -9,7 +9,7 @@ /* * Application version */ - 'version' => '0.6.0', + 'version' => '0.7.0', /* * PHP minimum version