Example #1
0
 public static function parse($argv, $jenkins_server, $default_jenkins_job, $default_jenkins_job_prefix = null, $default_wc_path = null, $default_remote_branch = "master")
 {
     $default_jenkins_job_prefix = $default_jenkins_job_prefix ?: $default_jenkins_job;
     $default_wc_path = $default_wc_path ?: ".";
     $formattedUsageSpec = self::USAGE_SPEC;
     $formattedUsageSpec = str_replace("\$default_jenkins_job_prefix", $default_jenkins_job_prefix, $formattedUsageSpec);
     $formattedUsageSpec = str_replace("\$default_jenkins_job", $default_jenkins_job, $formattedUsageSpec);
     $formattedUsageSpec = str_replace("\$jenkins_server", $jenkins_server, $formattedUsageSpec);
     $formattedUsageSpec = str_replace("\$default_wc_path", $default_wc_path, $formattedUsageSpec);
     // In the case of $default_remote_branch, we want to optionally remove the default
     // altogether.
     if (is_null($default_remote_branch)) {
         $formattedUsageSpec = str_replace(" [\$default_remote_branch]", "", $formattedUsageSpec);
     } else {
         $formattedUsageSpec = str_replace("\$default_remote_branch", $default_remote_branch, $formattedUsageSpec);
     }
     $parser = new TryLib_Util_PHPOptions_Options($formattedUsageSpec);
     return $parser->parse($argv);
 }
Example #2
0
<?php

include 'Options.php';
// First line is the summary
// one separator '--'
// one line per argument, list short and corresponding long arguments, describe
// it and optionally give its default value between square brackets.
// an empty line outputs an empty line in the usage(), so helps to group
// options.
//
// this option spec was shamelessly taken from the bup project, from which the
// options.py Python module originated. it was modified to be able to show off
// all of the options module's capabilities.
$s = "\nbup save [options...] [-tc] [-n name] <filenames...>\n--\nt,tree     output a tree id\nc,commit   output a commit id\n\nr,remote=  hostname:/path/to/repo of remote repository\nn,name=    name of backup set to update (if any)\nd,date=    date for the commit (seconds since the epoch)\nv,verbose  increase log output (can be used more than once)\nq,quiet,no-progress    don't show progress meter\nsmaller=   only back up files smaller than n bytes\nbwlimit=   maximum bytes/sec to transmit to server\nf,indexfile=  the name of the index file (normally BUP_DIR/bupindex)\nstrip      strips the path to every filename given\nstrip-path= path-prefix to be stripped when saving\ngraft=     a graft point *old_path*=*new_path* (can be used more than once)\n#,compress=  set compression level to # (0-9, 9 is highest) [1]\n";
$o = new TryLib_Util_PHPOptions_Options($s);
// give it any arbitrary list of arguments, the first one will be ignored
// (program name).
list($opt, $flags, $extra) = $o->parse($argv);
// Arguments with no trailing '=' give a boolean value (almost.. see below)
if ($opt->c) {
    print "Committing!\n";
}
// Arguments that are specified in the option spec above with a prefix of 'no-'
// or 'no_' get their boolean value inversed.
// Try using -q to reverse the value of this argument
if ($opt->progress) {
    print "Showing progress meter\n";
} else {
    print "NOT showing progress meter\n";
}
// well ... actually, arguments with no trailing '=' can be used multiple times