Development

Changeset 4354

You must first sign up to be able to contribute.

Changeset 4354

Show
Ignore:
Timestamp:
06/25/07 10:13:02 (1 year ago)
Author:
fabien
Message:

pake: added options for tasks

You can now add some options on the command line for your tasks. Let's take symfony as an example:

./symfony sync production
./symfony --dry-run sync production

./symfony i18n-extract --auto-save frontend en

Options can have a value:

./symfony load-data --dir=fixtures --append frontend dev

Unlike arguments, the order of options does not matter:

./symfony load-data frontend --dir=fixtures dev --append

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/pake/trunk/lib/pake/pakeApp.class.php

    r2574 r4354  
    124124      $task = array_shift($args); 
    125125 
     126      $options = array(); 
     127      for ($i = 0, $max = count($args); $i < $max; $i++) 
     128      { 
     129        if (0 === strpos($args[$i], '--')) 
     130        { 
     131          if (false !== $pos = strpos($args[$i], '=')) 
     132          { 
     133            $options[substr($args[$i], 2, $pos - 2)] = substr($args[$i], $pos + 1); 
     134          } 
     135          else 
     136          { 
     137            $options[substr($args[$i], 2)] = true; 
     138          } 
     139          unset($args[$i]); 
     140        } 
     141      } 
     142      $args = array_values($args); 
     143 
    126144      $abbrev_options = $this->abbrev(array_keys(pakeTask::get_tasks())); 
    127145      $task = pakeTask::get_full_task_name($task); 
     
    141159      else 
    142160      { 
    143         return pakeTask::get($abbrev_options[$task][0])->invoke($args); 
     161        return pakeTask::get($abbrev_options[$task][0])->invoke($args, $options); 
    144162      } 
    145163    } 
  • tools/pake/trunk/lib/pake/pakeTask.class.php

    r1794 r4354  
    150150  } 
    151151 
    152   public function invoke($args
     152  public function invoke($args, $options
    153153  { 
    154154    if ($this->trace) 
     
    179179    if ($this->is_needed()) 
    180180    { 
    181       return $this->execute($args); 
    182     } 
    183   } 
    184  
    185   public function execute($args
     181      return $this->execute($args, $options); 
     182    } 
     183  } 
     184 
     185  public function execute($args, $options
    186186  { 
    187187    if ($this->dryrun) 
     
    216216 
    217217    // execute action 
    218     return call_user_func_array($function, array($this, $args)); 
     218    return call_user_func_array($function, array($this, $args, $options)); 
    219219  } 
    220220