Skip to content

How to Create a New Pestle Command

astorm edited this page Dec 24, 2016 · 1 revision

Creating a new pestle command or changing an existing one is relatively simple. First, clone the GitHub repository.

$ git clone git@github.com:astorm/pestle.git
Cloning into 'pestle'...
remote: Counting objects: 1476, done.
remote: Total 1476 (delta 0), reused 0 (delta 0), pack-reused 1476
Receiving objects: 100% (1476/1476), 293.30 KiB | 0 bytes/s, done.
Resolving deltas: 100% (625/625), done.
Checking connectivity... done.

Then, change directories so you're inside the just cloned repository

$ cd pestle/

Then, install the project's composer dependencies with a

$ composer.phar install

Composer will (per standard composer behavior) download the project's dependencies to the vendor/ folder. If you're new to composer, "dependencies" means "other PHP code".

One this is done, you're ready to run the development version of pestle — pestle_dev. This command is located in the project root. In most unix systems you'll need to give it executable permissions

$ chmod +x ./pestle_dev

Once you've done that, you can run the dev version of the command like you would any other unix program.

$ ./pestle_dev 

                  _   _      
                 | | | |     
  _ __   ___  ___| |_| | ___ 
 | '_ \ / _ \/ __| __| |/ _ \
 | |_) |  __/\__ \ |_| |  __/
 | .__/ \___||___/\__|_|\___|
 | |                         
 |_|    
pestle by Pulse Storm LLC

Usage:
  pestle command_name [options] [arguments]

Available commands:
  build_command_list                        Converts a markdown files to a
  help                                      Alias for list @command help
  list_commands                             Lists help Read the doc blocks    

The development version of pestle loads and runs all the commands in the /modules folder.

If you want to create a new command, pestle has a build in command for that! Try running the following

$ ./pestle_dev generate_pestle_command
New Command Name? (foo_bar)] my_command_name
Create in PHP Namespace? (Pulsestorm\Magento2\Cli)] 
Creating the following module
<?php
namespace Pulsestorm\Magento2\Cli\My_Command_Name;
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\Pestle\Library\output');

/**
* One Line Description
*
* @command my_command_name
*/
function pestle_cli($argv)
{
    output("Hello Sailor");
}

bbedit modules/pulsestorm/magento2/cli/my_command_name/module.php
sublime modules/pulsestorm/magento2/cli/my_command_name/module.php
vi modules/pulsestorm/magento2/cli/my_command_name/module.php

Pestle will generate the command, and give you a few editor commands to directly edit the just created file. You can then run the command with

$ ./pestle_dev my_command_name 
Hello Sailor

Building a new Phar

While we encourage you to submit you commands via a pull request, we know not all commands are suitable for sharing. Pestle includes a phing build script that can generate a new, private, pestle.phar just for you. All you need to do is run the build.sh script

$ chmod +x build.sh
$ ./build.sh 
Buildfile: /private/tmp/workin/pestle/build.xml

MyProject > build:

   [delete] Directory /tmp/pestle_cache does not exist or is not a directory.
   [delete] Directory /private/tmp/workin/pestle/build does not exist or is not a directory.
    [mkdir] Created dir: /private/tmp/workin/pestle/build
     [copy] Created 86 empty directories in /private/tmp/workin/pestle/build
     [copy] Copying 73 files to /private/tmp/workin/pestle/build
     [copy] Created 1 empty directory in /private/tmp/workin/pestle/build
     [copy] Copying 2 files to /private/tmp/workin/pestle/build
     [copy] Created 9 empty directories in /private/tmp/workin/pestle/build/vendor
     [copy] Copying 32 files to /private/tmp/workin/pestle/build/vendor

MyProject > package_phar:

   [delete] Deleting: /private/tmp/workin/pestle/pestle.phar
[pharpackage] Building package: /private/tmp/workin/pestle/pestle.phar
   [delete] Deleting directory /private/tmp/workin/pestle/build

BUILD FINISHED

Total time: 0.6275 seconds               
Clone this wiki locally