Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required params non-setted, not present #23

Closed
Grummfy opened this issue Dec 1, 2013 · 5 comments
Closed

Required params non-setted, not present #23

Grummfy opened this issue Dec 1, 2013 · 5 comments

Comments

@Grummfy
Copy link

Grummfy commented Dec 1, 2013

Hello,
when we have required parameters that where not setted, the systems don't make any error. It should provide any error on hasError ...

Example :

$options = array(
    'action,a:',
    'module,m:'
);
$getOpt = $context->getopt($options);

// check errors
if ($getOpt->hasErrors())
{
    foreach ($getOpt->getErrors() as $error)
    {
        $stdio->errln($error->getMessage());
    }
    exit(Status::USAGE);
}

when I try this with php cli.php -a test I have no error ....

tested on php 5.3

@pmjones
Copy link
Member

pmjones commented Dec 1, 2013

I think the correct behavior is already in place; let me explain why.

Getopt is for options. They may or may not be present. So if an option is "missing", that's allowed, and not an error condition.

The "required" descriptor on the option does not mean "this option is required to be present." It means "when present, this option must have a value."

If there is something that must be passed, I suggest making it an argument, not an option.

Hope that helps; please let me know if it does not.

@pmjones pmjones closed this as completed Dec 1, 2013
@Grummfy
Copy link
Author

Grummfy commented Dec 1, 2013

ok, but this precisions should be written, because it add some confusion.

thanks for you answer.

@pmjones
Copy link
Member

pmjones commented Dec 1, 2013

That's a fair point; I'll add to the docs. Thanks for pointing it out.

@pmjones pmjones reopened this Dec 1, 2013
@pmjones pmjones closed this as completed Dec 1, 2013
@harikt
Copy link
Member

harikt commented Dec 2, 2013

@pmjones I have also faced this problem about required and was confused.

Also using positional arguments means you need to make sure the argument order is same. Or is there another way to resolve this ?

I feel to anyone the require is going to get confused. I have seen the commit , still in favour of having required in options to be required and pass exception.

@Grummfy
Copy link
Author

Grummfy commented Dec 2, 2013

Perhaps we can add a new metthod that check "force required" args?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants