context.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <h1>Drush Contexts</h1>
  2. <p>
  3. The drush contexts API acts as a storage mechanism for all options,
  4. arguments and configuration settings that are loaded into drush.
  5. <p>
  6. This API also acts as an IPC mechanism between the different drush commands,
  7. and provides protection from accidentally overriding settings that are
  8. needed by other parts of the system.
  9. <p>
  10. It also avoids the necessity to pass references through the command chain
  11. and allows the scripts to keep track of whether any settings have changed
  12. since the previous execution.
  13. <p>
  14. This API defines several contexts that are used by default.
  15. <h2>Argument contexts</h2>
  16. <p>
  17. These contexts are used by Drush to store information on the command.
  18. They have their own access functions in the forms of
  19. drush_set_arguments(), drush_get_arguments(), drush_set_command(),
  20. drush_get_command().
  21. <ul>
  22. <li>command : The drush command being executed.</li>
  23. <li>arguments : Any additional arguments that were specified.</li>
  24. </ul>
  25. <h2>Setting contexts</h2>
  26. <p>
  27. These contexts store options that have been passed to the drush.php
  28. script, either through the use of any of the config files, directly from
  29. the command line through --option='value' or through a JSON encoded string
  30. passed through the STDIN pipe.
  31. <p>
  32. These contexts are accessible through the drush_get_option() and
  33. drush_set_option() functions. See drush_context_names() for a description
  34. of all of the contexts.
  35. <p>
  36. Drush commands may also choose to save settings for a specific context to
  37. the matching configuration file through the drush_save_config() function.
  38. <h2>Available Setting contexts</h2>
  39. <p>
  40. These contexts are evaluated in a certain order, and the highest priority value
  41. is returned by default from drush_get_option. This allows scripts to check whether
  42. an option was different before the current execution.
  43. <p>
  44. Specified by the script itself :
  45. <ul>
  46. <li>process : Generated in the current process.
  47. <li>cli : Passed as --option=value to the command line.
  48. <li>stdin : Passed as a JSON encoded string through stdin.
  49. <li>alias : Defined in an alias record, and set in the
  50. alias context whenever that alias is used.
  51. <li>specific : Defined in a command-specific option record, and
  52. set in the command context whenever that command is used.
  53. </ul>
  54. <p>
  55. Specified by config files :
  56. <ul>
  57. <li>custom : Loaded from the config file specified by --config or -c
  58. <li>site : Loaded from the drushrc.php file in the Drupal site directory.
  59. <li>drupal : Loaded from the drushrc.php file in the Drupal root directory.
  60. <li>user : Loaded from the drushrc.php file in the user's home directory.
  61. <li>drush : Loaded from the drushrc.php file in the $HOME/.drush directory.
  62. <li>system : Loaded from the drushrc.php file in the system's $PREFIX/etc/drush directory.
  63. <li>drush : Loaded from the drushrc.php file in the same directory as drush.php.
  64. </ul>
  65. <p>
  66. Specified by the script, but has the lowest priority :
  67. <ul>
  68. <li>default : The script might provide some sensible defaults during init.
  69. </ul>