Getting somewhere, using PEAR ConsoleGetopt for arguments

This commit is contained in:
2013-04-13 23:54:29 +02:00
parent 2dee6601f6
commit bd676d52e8
3 changed files with 41 additions and 3 deletions

BIN
.check_md5.php.swp Normal file

Binary file not shown.

View File

@@ -1,5 +1,9 @@
#!/usr/bin/php5 #!/usr/bin/php5
<?php <?php
//include class file
include ("Console/Getopt.php");
$VERSION="1.1"; $VERSION="1.1";
$AUTHOR="(c) 2012 Jack-Benny Persson (jack-benny@cyberinfo.se)"; $AUTHOR="(c) 2012 Jack-Benny Persson (jack-benny@cyberinfo.se)";
@@ -21,7 +25,7 @@ function print_version()
function print_help() function print_help()
{ {
global $AUTHOR; global $AUTHOR;
$HELP_TEXT = <<<'EOD' $HELP_TEXT = <<<'EOD'
Monitor the MD5 checksum of a single file Monitor the MD5 checksum of a single file
Options: Options:
@@ -40,13 +44,46 @@ Options:
--md5 md5checksum --md5 md5checksum
Set the MD5 checksum for the file set by --file Set the MD5 checksum for the file set by --file
EOD; EOD;
// Print the help // Print the help
print_version(); print_version();
echo "$AUTHOR\n"; echo "$AUTHOR\n";
echo "\n$HELP_TEXT\n"; echo "\n$HELP_TEXT\n";
} }
print_help(); $options = new Console_Getopt();
$shortoptions = "hV";
$longoptions = array("warning", "file", "md5");
$args = $options->readPHPArgv();
$ret = $options->getopt($args, $shortoptions, $longoptions);
if (PEAR::isError($ret)) {
fwrite(STDERR,$ret->getMessage() . "\n");
exit ($STATE_UNKNOWN);
}
$opts = $ret[0];
if(sizeof($opts) > 0)
{
foreach($opts as $o)
{
switch($o[0])
{
case 'h':
print_help();
break;
case 'V':
print_version();
break;
}
}
}
$file = 'fil';
echo md5_file($file);
?> ?>

1
fil Normal file
View File

@@ -0,0 +1 @@
Hejsan