close

前言

以下的文章是從pear官方網站所擷取下來的(應該是沒有版權問題吧 ^^")

是大爺的學習筆記

所以如果翻譯有什麼地方有錯誤,請告知大爺,感恩哩 ^^


Overview (概論)

Custom commands have changed substantially in Pyrus. PEAR commands draw their information from Xml files located in the directory PEAR/Command and require all commands to be implemented in a single file. Pyrus is much more flexible on this account, and extends the custom XML format used to define commands. Because of this difference, it is theoretically possible to create custom commands that will work in both the PEAR Installer and in Pyrus, although the internal implementation of these commands will necessarily be quite different.

(自定命令在pyrus大致上已經改變。pear 命令描述他們的資訊從Xml檔案位址在目錄pear/command和要求所有的命令被實作在一個單一的檔案中。pyrus 在這個描述比較靈活而且使用延伸自定的XML格式來定義命令。因為這個不同,理論上可能建立能夠執行在pear安裝程式和pyrus的自定命令,雖然這些命令的內部實行將會無可避免的十分不同。)

 

The biggest difference between how a custom command is implemented in Pyrus has to do with the new plugin system (documented here). Before reading any further, it may be a good idea to familiarize yourself with the way that plugins work in Pyrus by reading the documentation on plugins, then return back to finish reading about custom commands.

(最大的不同是一個自定的命令如何在pyrus實作和新的外掛系統必須做之間 {這段大爺翻不出來哩 @@}{參考文件在這裡}。在更進一步閱讀之前,一個比較好的點子是讓你自已熟悉外掛在pyrus執行的方式透過閱讀在外掛的文件,然後再回來完成閱讀關於自定命令)。

 

Here is PEAR's version of the xml for the install command:

(這裡是pear的xml的版本為了安裝的命令)

 

<commands version="1.0">
<install>
<summary>Install Package</summary>
<function>doInstall</function>
<shortcut>i</shortcut>
<options>
<force>
<shortopt>f</shortopt>
<doc>will overwrite newer installed packages</doc>
</force>
<loose>
<shortopt>l</shortopt>
<doc>do not check for recommended dependency version</doc>
</loose>
<nodeps>
<shortopt>n</shortopt>
<doc>ignore dependencies, install anyway</doc>
</nodeps>
<register-only>
<shortopt>r</shortopt>
<doc>do not install files, only register the package as installed</doc>
</register-only>
<soft>
<shortopt>s</shortopt>
<doc>soft install, fail silently, or upgrade if already installed</doc>
</soft>
<nobuild>
<shortopt>B</shortopt>
<doc>don&#039;t build C extensions</doc>
</nobuild>
<nocompress>
<shortopt>Z</shortopt>
<doc>request uncompressed files when downloading</doc>
</nocompress>
<installroot>
<shortopt>R</shortopt>
<doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT), use packagingroot for RPM</doc>
<arg>DIR</arg>
</installroot>
<packagingroot>
<shortopt>P</shortopt>
<doc>root directory used when packaging files, like RPM packaging</doc>
<arg>DIR</arg>
</packagingroot>
<ignore-errors>
<shortopt></shortopt>
<doc>force install even if there were errors</doc>
</ignore-errors>
<alldeps>
<shortopt>a</shortopt>
<doc>install all required and optional dependencies</doc>
</alldeps>
<onlyreqdeps>
<shortopt>o</shortopt>
<doc>install all required dependencies</doc>
</onlyreqdeps>
<offline>
<shortopt>O</shortopt>
<doc>do not attempt to download any urls or contact channels</doc>
</offline>
<pretend>
<shortopt>p</shortopt>
<doc>Only list the packages that would be downloaded</doc>
</pretend>
</options>
<doc>[channel/]&lt;package&gt; ...
Installs one or more PEAR packages. You can specify a package to
install in four ways:

&quot;Package-1.0.tgz&quot; : installs from a local file

&quot;http://example.com/Package-1.0.tgz&quot; : installs from
anywhere on the net.

&quot;package.xml&quot; : installs the package described in
package.xml. Useful for testing, or for wrapping a PEAR package in
another package manager such as RPM.

&quot;Package[-version/state][.tar]&quot; : queries your default channel&#039;s server
({config master_server}) and downloads the newest package with
the preferred quality/state ({config preferred_state}).

To retrieve Package version 1.1, use &quot;Package-1.1,&quot; to retrieve
Package state beta, use &quot;Package-beta.&quot; To retrieve an uncompressed
file, append .tar (make sure there is no file by the same name first)

To download a package from another channel, prefix with the channel name like
&quot;channel/Package&quot;

More than one package may be specified at once. It is ok to mix these
four ways of specifying packages.
</doc>
</install>
</commands>

 

And the same command as implemented in Pyrus:

(而相同的命令一樣執行在pyrus:)

 

<?xml version="1.0" encoding="UTF-8"?>
<commands version="2.0" xmlns="http://pear2.php.net/dtd/customcommand-2.0">
<command>
<name>install</name>
<class>pear2\Pyrus\ScriptFrontend\Commands</class>
<function>install</function>
<summary>Install a package. Use install --plugin to install plugins</summary>
<shortcut>i</shortcut>
<options>
<option>
<name>plugin</name>
<shortopt>p</shortopt>
<type><bool/></type>
<doc>Manage plugin installation only</doc>
</option>
<option>
<name>packagingroot</name>
<shortopt>r</shortopt>
<type><string/></type>
<doc>Install the package in a directory in preparation for packaging with tools like RPM</doc>
</option>
<option>
<name>optionaldeps</name>
<shortopt>o</shortopt>
<type><bool/></type>
<doc>Automatically download and install all optional dependencies</doc>
</option>
<option>
<name>force</name>
<shortopt>f</shortopt>
<type><bool/></type>
<doc>Force the installation to proceed independent of errors. USE SPARINGLY.</doc>
</option>
</options>
<arguments>
<argument>
<name>package</name>
<multiple>1</multiple>
<optional>0</optional>
<doc>package.xml, local package archive, remove package archive, or abstract package.</doc>
</argument>
</arguments>
<doc>Installs listed packages.

local package.xml example:
php pyrus.phar install package.xml

local package archive example:
php pyrus.phar install PackageName-1.2.0.tar

remote package archive example:
php pyrus.phar install http://www.example.com/PackageName-1.2.0.tgz

Examples of an abstract package:
php pyrus.phar install PackageName
installs PackageName from the default channel with stability preferred_state
php pyrus.phar pear/PackageName
installs PackageName from the pear.php.net channel with stability preferred_state
php pyrus.phar install channel://doc.php.net/PackageName
installs PackageName from the doc.php.net channel with stability preferred_state
php pyrus.phar install PackageName-beta
installs PackageName from the default channel, beta or stable stability
php pyrus.phar install PackageName-1.2.0
installs PackageName from the default channel, version 1.2.0</doc>
</command>
</commands>

 

The format for commands in Pyrus is much more fine-grained, and provides both better validation and better presentation of options and arguments as passed in from the user. In addition, Pyrus allows fine-grained specification of where a command is located, and automatically registers an autoloader to load the class implementing the command, and any dependent classes in the same location.

(在pyrus命令的格式是比較細密的,而且提供較好的檢驗和較好的選擇的顯示和從使用者傳遞的參數。此外,pyrus允許較細密的說明一個命令是位於那裡,並且自動地登記一個自動載入裝置去載入類別的實作命令,和任何相依的類別在相同的目錄中。)

 

The details of new tags like <classprefix> and <autoloadpath> are documented in the full documentation of custom roles here.

(新的標籤的細節像<classprefix>和<autoloadpath>是證明在全部自定規則的文件 這裡)

 

This XML metadata file is identified by Pyrus through the use of the file role customcommand, which is used in the custom command's package.xml. Here is an example from the <contents> of a package.xml:

(這個XML資料檔是由pyrus定義經由檔案規則自定命令的使用,是使用在自定命令的package.xml。這裡是一個範例來自一個package.xm的<contents>:)

 

...
<contents>
<dir name="data">
<file name="commands.xml" role="customcommand"/>
<file name="someotherdata.csv" role="data"/>
</dir>
</contents>
...
arrow
arrow
    全站熱搜

    大爺 發表在 痞客邦 留言(0) 人氣()