Re: variable in option (Console_CommandLine)
| From: | Reuben Cummings | Date: | Wed, 26 Nov 2008 19:49:17 +0000 |
| Subject: | Re: variable in option (Console_CommandLine) | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-29449@lists.php.net to get a copy of this message | ||
Thanks! Exactly what I needed. I have another question as well but
will send it as a sep email.
On Wed, Nov 26, 2008 at 4:34 AM, David Jean Louis <izimobil@gmail.com> wrote:
> Reuben Cummings a écrit :
>>
>> [This message has been brought to you via pear.php.net.]
>>
>> hi, can you please tell me how I can specify the default value of an
>> option to be the value of a previously entered argument? For ex. I want
>> to do something like the following:
>>
>> <option name="myoption">
>> <short_name>-t</short_name>
>> <action>StoreString</action>
>> <default>$result->args['myarg'</default>
>> </option>
>>
>> Thanks
>>
>> Reuben
>
> Hello Reuben,
>
> (Please use PEAR public mailing lists instead of private messages when
> asking for help, as it may be useful for other users)
>
> You cannot do this in the xml file, you'll have to do it in your commandline
> handling code, for ex:
>
> <?php
>
> require_once 'Console/CommandLine.php';
>
> $xml = '<?xml version="1.0" encoding="utf-8"
> standalone="yes"?>
> <command>
> <description>Some program...</description>
> <version>1.0.0</version>
> <argument name="foo">
> <description>foo argument</description>
> </argument>
> <option name="bar">
> <short_name>-b</short_name>
> <long_name>--bar</long_name>
> <description>bar option</description>
> <action>StoreString</action>
> </option>
> </command>';
>
>
> try {
> $parser = Console_CommandLine::fromXmlString($xml);
> $result = $parser->parse();
>
> // here's the magic
> if (!$result->options['bar']) {
> $result->options['bar'] = $result->args['foo'];
> }
> // etc...
> } catch (Exception $exc) {
> $parser->displayError($exc->getMessage());
> }
>
> ?>
>
> HTH,
>
> --
> David JEAN LOUIS <izi@php.net>
>
>