-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add requires #31
Add requires #31
Conversation
I think this is an interesting addition but I wonder about calling it "requires" since there is already a command method by that name. How about "dependsOn" or something like that? |
I'm good with that...happy to make that change. |
note that I am just a user of I was looking further at this and had a thought... yes, // option 'test' is required for $cmd
$cmd = new Command();
$cmd->option('test')
->require(true, NULL); // option 'test' is required for $cmd and option 'foo' is required with option 'test'
$cmd = new Command();
$cmd->option('test')
->require(true,'foo'); // option 'test' is optional for $cmd but option 'foo' is required *if* 'test' is present
$cmd = new Command();
$cmd->option('test')
->require(false,'foo'); // option 'test' is required for $cmd and options 'foo' + 'bar' are also required with option 'test'
$cmd = new Command();
$cmd->option('test')
->require(true,array('foo','bar')); // option 'test' is optional for $cmd but options 'foo' + 'bar' are required *if* option 'test' is present
$cmd = new Command();
$cmd->option('test')
->require(true,array('foo','bar')); Maybe this is too complex but I like it as many different dependency use cases can be covered by a single option. |
It's an interesting idea, but I wonder if it's missing too many "require" contexts into on place since it'd be both: "this option is required" and "If you use this, you're required to use these others". I don't know if the (subtle?) distinction between them is enough to warrant them being different though. |
I guess the way I was thinking about it was: The But you are right, it could be too subtle. Just a thought. |
It would't take much to use what I've already put in there and overload the requires, really...it could be done either way and have the same effect. |
Thanks for adding this! Sorry for not chiming in earlier. I generally tend to lean towards explicitness and readability. I think @enygma also has a point w.r.t. coupling general require behavior with dependency behavior. For these reasons, I like the idea of a new method. Agree $cmd = new Command();
$cmd->option('test')
->require()
->needs('foo','bar'); |
Works for me on the "needs"....I wonder about that syntax though. Personally, I think if there's more than one defined it should be given in an array to avoid the need for something like func_get_args to work with a variable number of parameters. |
Agree. The |
Give that a shot... |
Great! Merged. Will update docs, version, etc. shortly. |
Nice! Thanks for including this in the project :) |
* upstream/master: (33 commits) Add getOptions method for getting all options Update README.md add docs for needs version bump update the example to demostrate longer alias working Moving from "dependsOn" to "needs" on Option (Issue nategood#31) moving "dependsOn" over to "needs" as per Issue nategood#31 updating from "requires" to "dependsOn" for dependency handling adding tests for new "requires" handling in options Adding tests for new "required" handling to Command class Adding "requires" handling to Option for defining other options that must be set Adding functionality to Command for setting requirements on options Typho '-' on error message allow hyphen in option names Add a Bitdeli badge to README Version Bump 0.2.5 oops - used 5.4 syntax for arrays integrated my bool default to false logic to the new default feature, and made the inverse of the default specified when the value is determined fixed a typo in unit test, and made boolean options default to false instead of null. added bool unit test add support for default values for unspecified options ...
Adding the concept of "required options". Adds dependency between options such that:
$cmd = new Command();
$cmd->option('test')
->requires('other');
So that if "--test" is defined, "--other" must be also otherwise an exception is thrown. Options can also have multiple dependencies:
$cmd = new Command();
$cmd->option('test')
->requires(array('other','option'));
Where both "--other" and "--option" must be defined.
Unit tests are included.