Skip to content

Commit 54dc87f

Browse files
committed
v1.0.4 Fix bad format and bad encoding cli opt parsing
1 parent aa4e179 commit 54dc87f

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

barcode.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
require_once 'vendor/autoload.php';
1616

17-
define("_BC_VERSION", "1.0.3");
17+
define("_BC_VERSION", "1.0.4");
1818

1919
# permission to set to barcode files
2020
define("_BC_PERMISSION", 0644);
@@ -80,6 +80,16 @@
8080
sort($formats_list);
8181

8282

83+
function isEncoding($enc=null) {
84+
global $encodings_list;
85+
return in_array(strtoupper($enc), $encodings_list);
86+
}
87+
88+
function isFormat($format=null) {
89+
global $formats_list;
90+
return in_array(strtoupper($format), $formats_list);
91+
}
92+
8393
/////////////////// GETOPT STARTS
8494

8595
use Ulrichsg\Getopt\Getopt;
@@ -90,18 +100,10 @@
90100
$getopt = new Getopt(array(
91101
(new Option('e', 'encoding', Getopt::REQUIRED_ARGUMENT))
92102
->setDescription('Barcode encoding type selection')
93-
->setValidation(function($value) {
94-
global $encodings_list;
95-
return in_array(strtoupper($value), $encodings_list);
96-
})
97-
->setArgument(new Argument(null, null, 'bar-type')),
103+
->setArgument(new Argument(null, 'isEncoding', 'bar-type')),
98104
(new Option('f', 'format', Getopt::REQUIRED_ARGUMENT))
99105
->setDescription('Output format for the barcode')
100-
->setValidation(function($value, $formats_list) {
101-
global $formats_list;
102-
return in_array(strtoupper($value), $formats_list);
103-
})
104-
->setArgument(new Argument(null, null, 'file-type')),
106+
->setArgument(new Argument(null, 'isFormat', 'file-type')),
105107
(new Option('w', 'width', Getopt::REQUIRED_ARGUMENT))
106108
->setDescription('Width factor for bars to make wider, defaults to 2')
107109
->setArgument(new Argument(2, 'is_numeric', 'points')),

0 commit comments

Comments
 (0)