Re: variable in option (Console_CommandLine)

From: Date: Wed, 26 Nov 2008 09:34:38 +0000
Subject: Re: variable in option (Console_CommandLine)
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-29448@lists.php.net to get a copy of this message
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>

« previous php.pear.general (#29448) next »