Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active October 8, 2015 05:18
Show Gist options
  • Save coderofsalvation/3283715 to your computer and use it in GitHub Desktop.
Save coderofsalvation/3283715 to your computer and use it in GitHub Desktop.

Revisions

  1. coderofsalvation revised this gist Sep 29, 2013. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions cli-skeleton-minimal.php
    Original file line number Diff line number Diff line change
    @@ -22,18 +22,21 @@ function main($argv) {
    function init(){
    global $args;
    $str = false;
    $reqs = array("arg1","foo","bar");
    $opts = getopt(null, array('min:', 'max:','manual::'));
    if( isset($opts['manual']) ) manual();
    foreach( $args as $arg ) $str = !strstr( $arg, '--' ) && !strstr( $arg, basename(__FILE__) ) ? $arg : $str;
    $args['parsed'] = array();
    if( isset($opts['manual']) ) manual();
    foreach( $args as $arg )
    if( is_string($arg) && !strstr( $arg, '--' ) && !strstr( $arg, basename(__FILE__) ) && $args['parsed'][ $reqs[0] ] = $arg )
    array_shift($reqs);
    $args['parsed']['str'] = $str;
    $args['parsed']['min'] = (int) isset($opts['min']) ? trim($opts['min']) : false;
    $args['parsed']['max'] = (int) isset($opts['max']) ? trim($opts['max']) : 100;
    }

    function usage(){
      global $argv;
      return "Usage: ./".basename($argv[0])." [--min=integer, --max=integer] <str>\n\n";
      return "Usage: ./".basename($argv[0])." [--min=integer, --max=integer] <arg1> <foo> <bar>\n\n";
    }

    if ('cli' === php_sapi_name() && basename(__FILE__) === basename($argv[0])) {
  2. coderofsalvation revised this gist Sep 29, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions cli-skeleton-minimal.php
    Original file line number Diff line number Diff line change
    @@ -31,9 +31,9 @@ function init(){
    $args['parsed']['max'] = (int) isset($opts['max']) ? trim($opts['max']) : 100;
    }


    function usage(){
    return "Usage: foo [--min=integer, --max=integer] <str>\n\n";
      global $argv;
      return "Usage: ./".basename($argv[0])." [--min=integer, --max=integer] <str>\n\n";
    }

    if ('cli' === php_sapi_name() && basename(__FILE__) === basename($argv[0])) {
  3. coderofsalvation created this gist Aug 7, 2012.
    43 changes: 43 additions & 0 deletions cli-skeleton-minimal.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/usr/bin/env php
    <?php

    /*
    * cli skeleton - starting point for cli-command
    * (needs chmod 755 for cli)
    * (MINIMAL VERSION)
    */

    $args = array();
    $require = array('gd','simplexml');

    function main($argv) {
    global $args,$require;
    if( count($argv) == 1 ) die(usage());
    $args = $argv;
    init($argv);
    print_r($args);
    printf("[x] done\n");
    }

    function init(){
    global $args;
    $str = false;
    $opts = getopt(null, array('min:', 'max:','manual::'));
    if( isset($opts['manual']) ) manual();
    foreach( $args as $arg ) $str = !strstr( $arg, '--' ) && !strstr( $arg, basename(__FILE__) ) ? $arg : $str;
    $args['parsed'] = array();
    $args['parsed']['str'] = $str;
    $args['parsed']['min'] = (int) isset($opts['min']) ? trim($opts['min']) : false;
    $args['parsed']['max'] = (int) isset($opts['max']) ? trim($opts['max']) : 100;
    }


    function usage(){
    return "Usage: foo [--min=integer, --max=integer] <str>\n\n";
    }

    if ('cli' === php_sapi_name() && basename(__FILE__) === basename($argv[0])) {
    main($argv);
    }

    ?>