Zend_Console_Getopt-Introduction.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.console.getopt.introduction">
  4. <title>Introduction</title>
  5. <para>
  6. The <classname>Zend_Console_Getopt</classname> class helps command-line
  7. applications to parse their options and arguments.
  8. </para>
  9. <para>
  10. Users may specify command-line arguments when
  11. they execute your application. These arguments have meaning to the
  12. application, to change the behavior in some way, or choose resources,
  13. or specify parameters. Many options have developed customary meaning,
  14. for example <command>--verbose</command> enables extra output from many
  15. applications. Other options may have a meaning that is different for
  16. each application. For example, <command>-c</command> enables different
  17. features in <command>grep</command>, <command>ls</command>, and
  18. <command>tar</command>.
  19. </para>
  20. <para>
  21. Below are a few definitions of terms. Common usage of the terms
  22. varies, but this documentation will use the definitions below.
  23. </para>
  24. <itemizedlist>
  25. <listitem>
  26. <para>
  27. "argument": a string that occurs on the command-line
  28. following the name of the command. Arguments may be
  29. options or else may appear without an option, to name
  30. resources on which the command operates.
  31. </para>
  32. </listitem>
  33. <listitem>
  34. <para>
  35. "option": an argument that signifies that the command
  36. should change its default behavior in some way.
  37. </para>
  38. </listitem>
  39. <listitem>
  40. <para>
  41. "flag": the first part of an option, identifies
  42. the purpose of the option. A flag is preceded
  43. conventionally by one or two dashes
  44. (<command>-</command> or <command>--</command>).
  45. A single dash precedes a single-character flag
  46. or a cluster of single-character flags.
  47. A double-dash precedes a multi-character flag.
  48. Long flags cannot be clustered.
  49. </para>
  50. </listitem>
  51. <listitem>
  52. <para>
  53. "parameter": the secondary part of an option; a data value
  54. that may accompany a flag, if it is applicable to the
  55. given option. For example, many commands accept a
  56. <command>--verbose</command> option, but typically
  57. this option has no parameter. However, an option like
  58. <command>--user</command> almost always requires
  59. a following parameter.
  60. </para>
  61. <para>
  62. A parameter may be given as a separate argument following a
  63. flag argument, or as part of the same argument string,
  64. separated from the flag by an equals symbol (<command>=</command>).
  65. The latter form is supported only by long flags.
  66. For example,
  67. <command>-u username</command>, <command>--user username</command>,
  68. and <command>--user=username</command> are forms supported
  69. by <classname>Zend_Console_Getopt</classname>.
  70. </para>
  71. </listitem>
  72. <listitem>
  73. <para>
  74. "cluster": multiple single-character flags combined
  75. in a single string argument and preceded by a single
  76. dash. For example, "<command>ls -1str</command>"
  77. uses a cluster of four short flags. This command is
  78. equivalent to "<command>ls -1 -s -t -r</command>".
  79. Only single-character flags can be clustered.
  80. You cannot make a cluster of long flags.
  81. </para>
  82. </listitem>
  83. </itemizedlist>
  84. <para>
  85. For example, in <command>mysql --user=root mydatabase</command>,
  86. <command>mysql</command> is a <emphasis>command</emphasis>,
  87. <command>--user=root</command> is an <emphasis>option</emphasis>,
  88. <command>--user</command> is a <emphasis>flag</emphasis>,
  89. <command>root</command> is a <emphasis>parameter</emphasis> to the option,
  90. and <command>mydatabase</command> is an argument but not an option
  91. by our definition.
  92. </para>
  93. <para>
  94. <classname>Zend_Console_Getopt</classname> provides an interface to declare
  95. which flags are valid for your application, output an error and usage
  96. message if they use an invalid flag, and report to your application
  97. code which flags the user specified.
  98. </para>
  99. <note>
  100. <title>Getopt is not an Application Framework</title>
  101. <para>
  102. <classname>Zend_Console_Getopt</classname> does <emphasis>not</emphasis>
  103. interpret the meaning of flags and parameters, nor does this class
  104. implement application workflow or invoke application code.
  105. You must implement those actions in your own application code.
  106. You can use the <classname>Zend_Console_Getopt</classname> class to parse
  107. the command-line and provide object-oriented methods for querying
  108. which options were given by a user, but code to use this
  109. information to invoke parts of your application should be in
  110. another <acronym>PHP</acronym> class.
  111. </para>
  112. </note>
  113. <para>
  114. The following sections describe usage of <classname>Zend_Console_Getopt</classname>.
  115. </para>
  116. </sect1>