-
Notifications
You must be signed in to change notification settings - Fork 5
/
cssgrid
executable file
·1089 lines (946 loc) · 27.3 KB
/
cssgrid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env php
<?php
/**
* CLI script to generate a CSS grid
*
* @package CssGridGenerator
*/
namespace Grid;
// Prevents warnings when running in environments that don't have timezone set.
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
$argRules = array(
'h|help' => 'help',
'v|version' => 'version',
);
$args = new ArgV($argv, $argRules);
$grid = new Grid($args);
$grid->calculateColumns();
print $grid->renderCss();
/**
* Grid class
*
* Takes input from CLI arguments and calculates the widths of the grid columns
*
* @package CssGridGenerator
* @author Jansen Price <[email protected]>
* @version $Id$
*/
class Grid
{
/**
* Version constant
*
* @var string
*/
const VERSION = '0.8.2';
/**
* Constants for unit types
*
* @var string
*/
const UNIT_PIXELS = 'pixels';
const UNIT_PERCENT = 'percent';
/**
* Array of possible options for output units
*
* @var array
*/
protected $_outputUnitOptions = array(
self::UNIT_PIXELS,
self::UNIT_PERCENT,
);
/**
* Settings
*
* @var array
*/
protected $_settings = array(
'cols' => 12,
'col-width' => 64,
'gutter' => 10,
);
/**
* Storage for the calculated column widths
*
* @var array
*/
protected $_columns = array();
/**
* Output units
*
* @var string
*/
protected $_outputUnit = '';
/**
* Constructor
*
* @param ArgV $args Argument object
* @return void
*/
public function __construct(ArgV $args)
{
if ($args->version | $args->v) {
$this->displayVersion();
exit(0);
}
if ($args->help | $args->h | $args->{'?'}) {
$this->displayHelp();
exit(0);
}
$this->set('cols', $args->cols);
$this->set('col-width', $args->{'col-width'});
$this->set('gutter', $args->gutter);
$this->setOutputUnit($args->units);
}
/**
* Get version of script
*
* @return string
*/
public function getVersion()
{
return self::VERSION;
}
/**
* Display version information
*
* @return self
*/
public function displayVersion()
{
printf("cssgrid %s\n", $this->getVersion());
return $this;
}
/**
* Display help information
*
* @return self
*/
public function displayHelp()
{
$this->displayVersion();
print <<<EOS
Generate CSS for a grid based on specified columns, widths and gutter width
Usage: cssgrid [--cols=<number>] [--col-width=<number>] [--gutter=<number>]
[--outer-margin=<number>] [--units=<pixels|percent>]
Options:
--cols=<number> Number of columns (default: 12)
--col-width=<number> Width in pixels of the columns (default: 64)
--gutter=<number> Width of the gutters between the columns (default: 10)
--units=<pixels|percent> Output units (pixels or percent)
-v, --version Display version information and exit
-h, --help Display this help message and exit
Example:
cssgrid --cols=8 --col-width=180 --gutter=18 --outer-margin=0 --units=percent
Output:
The output is a CSS ruleset that can be added to a CSS file that defines
the .grid and .grid-col classes with columns, pushes, pulls, prefixes and
suffixes.
The output will include a CSS comment header that provides the date of
generation and parameters used to generate. It will also include a parameter of
--max-width that will indicate the grid's total calculated width.
EOS;
}
/**
* Calculate the column widths based on inputs
*
* @return self
*/
public function calculateColumns()
{
$cols = $this->get('cols');
$colWidth = $this->get('col-width');
$gutter = $this->get('gutter');
$maxWidth = ($colWidth * $cols + $gutter * ($cols - 1));
$this->set('max-width', $maxWidth);
$columnCalcs = array(
'widths' => array(),
'pushes' => array(),
'pulls' => array(),
'prefixes' => array(),
'suffixes' => array(),
);
for ($index = 1; $index <= $cols; $index++) {
$width = $colWidth * $index + $gutter * ($index - 1);
$columnCalcs['widths'][$index] = $width;
$columnCalcs['pushes'][$index] = ($width < $maxWidth) ? $width + $gutter : $width;
$columnCalcs['pulls'][$index] = ($width < $maxWidth) ? ($width + $gutter) * -1 : $width * -1;
}
$this->_columns = $columnCalcs;
return $this;
}
/**
* Render the CSS
*
* @return string Generated CSS
*/
public function renderCss()
{
$cssOutput = new GridOutputCss($this->_outputUnit);
return $cssOutput->render($this);
}
/**
* Get calculated column widths
*
* @return array
*/
public function getColumnWidths()
{
return $this->_columns;
}
/**
* Generate signature used to generate this CSS (input args)
*
* @return string
*/
public function getGenerateSignature()
{
// recreate the input args so the defaults are apparent
$args = array();
$args[] = '--units=' . $this->_outputUnit;
foreach ($this->_settings as $key => $value) {
$args[] = '--' . $key . '=' . $value;
}
// create the comments that show the math behind the calculations
$pixelConversionCommentBegin = $this->isOutputUnitsPercent() ? '(' : '';
$pixelConversionCommentEnd = $this->isOutputUnitsPercent() ? ' / max-width) * 100' : '';
$calculationComments = ' ============================================' . "\n"
. ' Formulas used for calculation of grid values' . "\n"
. ' ============================================' . "\n"
. ' gutter = ' . $pixelConversionCommentBegin . 'gutter' . $pixelConversionCommentEnd . "\n"
. ' col-width = ' . $pixelConversionCommentBegin . '((col-width * col-index) + (gutter * (col-index - 1))' . $pixelConversionCommentEnd . "\n"
. ' col-push = ' . $pixelConversionCommentBegin . '((col-width * col-index) + (gutter * col-index))' . $pixelConversionCommentEnd . "\n"
. ' col-pull = ' . $pixelConversionCommentBegin . '((col-width * col-index) + (gutter * col-index))' . $pixelConversionCommentEnd . " * -1\n"
. ' col-prefix = ' . $pixelConversionCommentBegin . '((col-width * col-index) + (gutter * col-index))' . $pixelConversionCommentEnd . "\n"
. ' col-suffix = ' . $pixelConversionCommentBegin . '((col-width * col-index) + (gutter * col-index))' . $pixelConversionCommentEnd . " * -1";
return 'Generated with cssgrid v' . $this->getVersion()
. ' at ' . date('Y-m-d H:i:s T') . "\n"
. ' https://github.com/sumpygump/css-grid-generator' . "\n"
. ' cssgrid ' . implode(' ', $args) . "\n\n"
. $calculationComments;
}
/**
* Set output unit
*
* @param string $units Output type
* @return self
*/
public function setOutputUnit($units)
{
if (null === $units
|| !in_array($units, $this->_outputUnitOptions)
) {
$units = self::UNIT_PIXELS;
}
$this->_outputUnit = $units;
return $this;
}
/**
* Set a value
*
* @param string $name Name of key
* @param int|string $value Value
* @return self
*/
public function set($name, $value)
{
if (null === $value) {
return $this;
}
$this->_settings[$name] = (int) $value;
return $this;
}
/**
* Return settings value by key name
*
* @param string $name Key name
* @param mixed $default Default value if key doesn't exist
* @return int
*/
public function get($name, $default = 0)
{
if (isset($this->_settings[$name])) {
return $this->_settings[$name];
}
return $default;
}
/**
* Whether the output units is set to percentage
*
* @return bool
*/
public function isOutputUnitsPercent()
{
return $this->_outputUnit == self::UNIT_PERCENT;
}
}
/**
* Output class for CSS grid generator
*
* @package CssGridGenerator
* @author Jansen Price <[email protected]>
* @version $Id$
*/
class GridOutputCss
{
/**
* Output type constants
*
* @var string
*/
const OUTPUTUNIT_PIXELS = 'pixels';
const OUTPUTUNIT_PERCENT = 'percent';
/**
* Template for printf format for grid column CSS rule
*
* @var string
*/
protected $_template = ".grid-col_%dof%d { width: %s; }\n";
/**
* Template for printf format for grid push CSS rule
*
* @var string
*/
protected $_pushTemplate = ".mix-grid-col_push%dof%d { left: %s; }\n";
/**
* Template for printf format for grid pull CSS rule
*
* @var string
*/
protected $_pullTemplate = ".mix-grid-col_pull%dof%d { left: %s; }\n";
/**
* Template for printf format for grid prefix CSS rule
*
* @var string
*/
protected $_prefixTemplate = ".mix-grid-col_prefix%dof%d { margin-left: %s; }\n";
/**
* Template for printf format for grid suffix CSS rule
*
* @var string
*/
protected $_suffixTemplate = ".mix-grid-col_suffix%dof%d { margin-right: %s; }\n";
/**
* Output unit (pixels or percent)
*
* @var string
*/
protected $_outputUnit = '';
/**
* Constructor
*
* @param string $outputUnit Output unit type
* @return void
*/
public function __construct($outputUnit = null)
{
if (null === $outputUnit) {
$this->_outputUnit = self::OUTPUTUNIT_PIXELS;
} else {
$this->_outputUnit = $outputUnit;
}
}
/**
* Render the CSS
*
* @param Grid $grid Grid object
* @return string
*/
public function render($grid)
{
$css = <<<CSS
/* ---------------------------------------------------------------------
Grid
%s
------------------------------------------------------------------------ */
.grid:after {
content: " ";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.grid-col {
position: relative;
float: left;
}
.grid-col + .grid-col {
margin-left: %s;
}
CSS;
// Format gutter css width (px or %)
$gutterCssWidth = $this->getCssWidth(
$grid->get('gutter'), $grid->get('max-width')
);
$css = sprintf($css, $grid->getGenerateSignature(), $gutterCssWidth);
$css .= "\n";
$columns = $grid->getColumnWidths();
$totalColumns = count($columns['widths']);
// Column widths CSS
foreach ($columns['widths'] as $index => $width) {
$cssWidth = $this->getCssWidth($width, $grid->get('max-width'));
$css .= sprintf($this->_template, $index, $totalColumns, $cssWidth);
}
$css .= "\n";
// Column pushes
foreach ($columns['pushes'] as $index => $push) {
$pushValue = $this->getCssWidth($push, $grid->get('max-width'));
$css .= sprintf($this->_pushTemplate, $index, $totalColumns, $pushValue);
}
$css .= "\n";
// Column pulls
foreach ($columns['pulls'] as $index => $pull) {
$pullValue = $this->getCssWidth($pull, $grid->get('max-width'));
$css .= sprintf($this->_pullTemplate, $index, $totalColumns, $pullValue);
}
$css .= "\n";
// Column prefixes
foreach ($columns['pushes'] as $index => $prefix) {
$prefixValue = $this->getCssWidth($prefix, $grid->get('max-width'));
$css .= sprintf($this->_prefixTemplate, $index, $totalColumns, $prefixValue);
}
$css .= "\n";
// Column suffixes
foreach ($columns['pushes'] as $index => $suffix) {
$suffixValue = $this->getCssWidth($suffix, $grid->get('max-width'));
$css .= sprintf($this->_suffixTemplate, $index, $totalColumns, $suffixValue);
}
$css .= "\n";
return $css;
}
/**
* Get the css value for a given column based on current output unit
*
* e.g. '24px' or '6.7%'
*
* @param int $pixels Width in pixels
* @param int $maxWidth Max width for entire grid
* @return string
*/
public function getCssWidth($pixels, $maxWidth = 1)
{
if ($this->isOutputUnitsPercent()) {
$percent = $pixels / $maxWidth * 100;
return $percent . '%';
}
return $pixels . 'px';
}
/**
* Whether the output units is set to percentage
*
* @return bool
*/
public function isOutputUnitsPercent()
{
return $this->_outputUnit == self::OUTPUTUNIT_PERCENT;
}
}
/**
* ArgV class file
*
* @package Qi
* @subpackage Console
*/
/**
* ArgV provides a way to assign and gather command line arguments
*
* It will parse and assign option flags and arguments passed
* in as command line arguments
*
* Examples of script arguments it can potentially parse:
* - short option (-f) : can be grouped (-fvz)
* - long option (--flag)
* - short parameter (-p value)
* - short parameter shunt (-pvalue)
* - long parameter (--param value)
* - long parameter shunt (--param=value)
* - standalone argument (filename)
*
* @package Qi
* @subpackage Console
* @author Jansen Price <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @version 1.3.4
*/
class ArgV
{
/**#@+
* Argument types
*
* @var string
*/
const TYPE_OPTION = 'option';
const TYPE_PARAMETER = 'parameter';
/**#@-*/
/**
* Store the argument data
*
* @var array
*/
protected $_data = array();
/**
* Storage for the argument rules (params starting with '-' or '--')
*
* @var array
*/
protected $_rules = array();
/**
* Map to link short and long argument names (e.g., "-p" and "--param")
*
* @var array
*/
protected $_ruleMap = array();
/**
* Storage for the standalone arguments
*
* @var array
*/
protected $_argumentStack = array();
/**
* Keep track of the current index of the argumentStack when setting them
*
* @var int
*/
private $_argumentIndex = 1;
/**
* Help messages for each argument
*
* @var array
*/
protected $_help = array();
/**
* Raw Arguments
*
* @var array
*/
protected $_rawArguments = array();
/**
* Rules for parsing parameters
*
* @var array
*/
protected $_rawRules = array();
/**
* Flag to indicate whether parsing has been done
*
* @var bool
*/
protected $_hasParsed = false;
/**
* Create a new instance of an object of this class.
*
* $rules is an array that will specify the short or long names
* of the option flags, parameters, help text
* and the names of the arguments.
*
* e.g., array(
* 'help|h' => 'Show help',
* 'delete|d' => 'Enter delete mode',
* 'f' => 'Flag with no long param name',
* 'long' => 'Flag with no short param name',
* 'name|n:' => 'Name to use', // colon means parameter required
* 'arg:file' => 'Filename to use'
* );
*
* So, after constructing the object,
* the following will be available:
* $obj->help and $obj->h
* $obj->delete and $obj->d
* $obj->f
* $obj->long
* $obj->name
* $obj->file
*
* @param array $argv A key=>value array of arguments from the command line
* @param array $rules A list of option flags and param names for arguments
* @return void
*/
public function __construct($argv, $rules = array())
{
$this->_rawRules = $rules;
$this->_parseRules($rules);
if (is_string($argv)) {
$argv = self::parseArgumentString($argv);
} else {
// assume the script name was the first param if
// a string was not given as input
$scriptName = array_shift($argv);
}
if (count($argv) <= 0) {
return;
}
$this->_rawArguments = $argv;
$this->parse($argv);
}
/**
* Get the raw arguments passed into this object
*
* @return array Raw arguments
*/
public function getRawArguments()
{
return $this->_rawArguments;
}
/**
* Parse arguments
*
* @param array $argv Arguments
* @return void
*/
public function parse($argv = null)
{
if (null === $argv) {
$argv = $this->_rawArguments;
}
// If already parsed, then re-parse the rules
// in order to reset the argument stack
if ($this->_hasParsed === true) {
$this->_argumentIndex = 1;
$this->_data = array(); // reset data
$this->_parseRules($this->_rawRules);
}
$this->_hasParsed = true;
// enforce numeric array
$argv = array_values($argv);
for ($i = 0; $i < count($argv); $i++) {
$val = $argv[$i];
$nextVal = null;
$shuntVal = '';
if (substr($val, 0, 2) == "--") {
$option = substr($val, 2);
$pos = false;
if (strpos($option, '=') !== false) {
// Detect long parameter shunt
$pos = strpos($option, '=');
$shuntVal = substr($option, $pos + 1);
$option = substr($option, 0, $pos);
}
$rule = $this->getRule($option);
if ($rule['type'] == self::TYPE_PARAMETER || $pos !== false) {
if ($shuntVal != '') {
$nextVal = $shuntVal;
} else {
$nextVal = $this->_getProperNextVal($argv, $i);
}
if (null === $nextVal) {
// If we didn't find anything, go back to the shuntval
if ($shuntVal != '') {
$nextVal = $shuntVal;
} else {
throw new ArgVException(
"Missing required parameter for arg $option"
);
}
}
} else {
$nextVal = true;
}
$this->_setSingleOption($option, $nextVal);
} elseif (substr($val, 0, 1) == "-") {
$optionString = substr($val, 1);
$optionStringLength = strlen($optionString);
for ($s = 0; $s < $optionStringLength; $s++) {
$option = $optionString[$s];
$rule = $this->getRule($option);
if ($rule['type'] == self::TYPE_PARAMETER) {
$nextVal = $this->_getProperNextVal($argv, $i);
if (null === $nextVal) {
// Detect short parameter shunt
if (substr($optionString, $s + 1) != '') {
$nextVal = substr($optionString, $s + 1);
$this->_setSingleOption($option, $nextVal);
break;
}
throw new ArgVException(
"Missing required parameter for arg $option"
);
}
} else {
$nextVal = true;
}
$this->_setSingleOption($option, $nextVal);
}
} else {
$this->_setArgument(array_shift($this->_argumentStack), $val);
}
}
}
/**
* Return whether this object has data
*
* @return bool
*/
public function hasData()
{
return (!empty($this->_data));
}
/**
* Retrieve the data as an array
*
* @return array
*/
public function toArray()
{
return (array) ($this->_data);
}
/**
* Parse rules for configuring this object
*
* @param array $rules The rules to parse
* @return void
*/
protected function _parseRules($rules)
{
$this->_argumentStack = array();
foreach ($rules as $name => $value) {
if (substr($name, 0, 4) == 'arg:') {
// "arg:<something>" is a way to name standalone arguments
$name = substr($name, 4);
$this->_argumentStack[] = $name;
$this->addHelp('<' . $name . '>', $value);
} else {
if (is_numeric($name)) {
$name = $value;
$value = '';
} else {
$this->addRule($name, $value);
}
}
}
}
/**
* Add a rule
*
* @param string $name Name of rule
* @param string $helpText Help text for this rule
* @return void
*/
public function addRule($name, $helpText = null)
{
if (substr($name, -1) == ':') {
// If the name ends in a colon, it requires a parameter
$type = 'parameter';
$name = substr($name, 0, -1);
} else {
$type = 'option';
}
if (strpos($name, '|') !== false) {
// If the name has a pipe, the first value is the long option
// name and the second is the short option name
$parts = explode('|', $name);
$name = $parts[0];
$shortName = substr($parts[1], 0, 1); // force to one char
$this->_addRule($shortName, $type);
$this->_addRule($name, $type);
$this->_mapRules($shortName, $name);
$helpName = $shortName . '|' . $name;
} else {
$this->_addRule($name, $type);
$helpName = $name;
if (strlen($name) == 1) {
// provide backwards compatibility
$longName = $helpText;
$helpText = '';
$this->_addRule($longName, $type);
$this->_mapRules($name, $longName);
$helpName = $name . '|' . $longName;
}
}
$this->addHelp($helpName, $helpText);
}
/**
* Add a rule (low level)
*
* @param string $name Name of argument
* @param string $type Argument type
* @return void
*/
protected function _addRule($name, $type)
{
$this->_rules[$name] = array(
'type' => $type,
);
}
/**
* Add a rule map between two argument names
*
* @param string $name Name
* @param string $alias Alias
* @return void
*/
protected function _mapRules($name, $alias)
{
$this->_ruleMap[$name] = $alias;
$this->_ruleMap[$alias] = $name;
}
/**
* Get a rule by it's name
*
* @param string $name Rule name
* @return mixed
*/
public function getRule($name)
{
if (!isset($this->_rules[$name])) {
return false;
}
return $this->_rules[$name];
}
/**
* Add a help message for an argument
*
* @param string $name Argument name
* @param string $helpText Help message
* @return mixed
*/
public function addHelp($name, $helpText)
{
if (!is_string($name)) {
return false;
}
$this->_help[$name] = $helpText;
}
/**
* Get help messages
*
* @return array
*/
public function getHelp()
{
return $this->_help;
}
/**
* Set a single option (one that starts with --)
*
* @param string $name Option name
* @param string $value Option value
* @return void
*/
protected function _setSingleOption($name, $value = true)
{
$this->_data[$name] = $value;
if (isset($this->_ruleMap[$name])) {
$this->_data[$this->_ruleMap[$name]] = $value;
}
}
/**
* Set an argument
*
* @param mixed $argument An argument name
* @param mixed $value A value
* @return void
*/
protected function _setArgument($argument, $value)
{
// This is in case the name of the argument
// was not set during construction
$this->_data['__arg' . $this->_argumentIndex++] = $value;
if ($argument) {
$this->_data[$argument] = $value;
}
}
/**
* Get a proper next val from the arg list
*
* Used to fetch a parameter for arguments that require one
*
* @param array $args List of arguments
* @param int &$i Current index
* @return mixed
*/
protected function _getProperNextVal($args, &$i)
{
if (!isset($args[$i + 1])) {
return null;
}
$value = $args[$i + 1];
if (substr($value, 0, 1) == '-') {
return null;
}
$i++; // increment counter so next argument doesn't count as standalone
return $value;