0

My module will be run from the command line. The Drush command would be something like this:

drush create-denver-type --name="some title" --title="some title" --options="apple" --userid="myid"

--options can have one option or five. I'm using a switch statement and only passing one value through --options. What do I need to do to pass two or three values to --options, for example --options="apple, pear, orange"?

Basing on the values passed in --options, different functions will be called.

When gathering multiple values, how do I pass them to my function, and call the correct functions based on the value passed in --options?

1 Answer 1

1
$options = drush_get_option_list('options');

This will return something like array('apple') or array('apple','pear','orange').

Yeah, Drush does everything.

3
  • I don't know how to incorporate a foreach into the code so that it will determine what values are in the array and then run the needed function(s). I made an edit above to show show where I am stuck in my switch. Nov 20, 2013 at 5:44
  • 1
    Now THAT question is out of scope for Drupal Stack Exchange. You could use a foreach / switch, or perhaps call_user_func to do what you'd like, but basic php questions should be asked elsewhere. Nov 20, 2013 at 5:50
  • Where is drush_get_option_list implemented ? Is it a certain drush version ? I think that does not answer how to implement a drush command with a dynamic amount of options. Eg think of a command to check for access for a certain route and you want to give the route paramters which depends on how much parameters the route accepts. Oct 12, 2022 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.