Skip to content

Error with multiple required operands.

Created by: calguy1000

Creating a single command with multiple required operands fails with error: PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Operand var is multiple - no more operands allowed' in /var/www/html/cmscli/vendor/ulrichsg/get

<?php
require_once('vendor/autoload.php');

use \GetOpt\GetOpt;
use \GetOpt\Command;
use \GetOpt\Option;
use \GetOpt\Operand;

class testCommand extends Command
{
    public function __construct()
    {
        parent::__construct( 'test', [ $this, 'handle'] );
        $this->addOperand( new Operand( 'var', Operand::REQUIRED ) );
        $this->addOperand( new Operand( 'vaL', Operand::REQUIRED ) );
    }

    public function handle()
    {
        die(__METHOD__);
    }
} // class

$getopt = new GetOpt;
$getopt->addCommand( new testCommand );
$getopt->process();

if( $cmd = $getopt->getCommand() ) {
    die('command is '.$cmdd);
}