Last active
October 8, 2015 05:18
-
-
Save coderofsalvation/3283715 to your computer and use it in GitHub Desktop.
Revisions
-
coderofsalvation revised this gist
Sep 29, 2013 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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::')); $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] <arg1> <foo> <bar>\n\n"; } if ('cli' === php_sapi_name() && basename(__FILE__) === basename($argv[0])) { -
coderofsalvation revised this gist
Sep 29, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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(){ global $argv; return "Usage: ./".basename($argv[0])." [--min=integer, --max=integer] <str>\n\n"; } if ('cli' === php_sapi_name() && basename(__FILE__) === basename($argv[0])) { -
coderofsalvation created this gist
Aug 7, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); } ?>