Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Clone this wiki locally
Pake includes various utilities for common operations. Here they are:
pake_mkdirs($path, $mode = 0777)
Checks if $path directory exists, and if it doesn’t, creates $path directory recursively. You don’t need to do additional file_exists() or is_dir() calls. Just call pake_mkdirs(“foo/bar/baz”) and everything will be done automatically
pake_copy($origin_file, $target_file, $options = array())
Again, Pake will do all required checks and will even create target directory for you, if it doesn’t exist. By default, pake will only copy file if $origin_file is newer than $target_file. You can override it by giving array(‘override’ => true) as the last parameter.
Renames file specified as the first parameter to the name specified by the second parameter.
pake_mirror($arg, $origin_dir, $target_dir, $options = array())
Copies all files and directories which correspond to the $arg rule from $origin_dir to $target_dir. Options parameter is forwarded to pake_copy(), which is used internally.
Deletes all files and directories which correspond to the $arg rule from $target_dir
Updates “modified time” of files, which correspond to the $arg rule in $target_dir
pake_replace_tokens_to_dir($arg, $src_dir, $target_dir, $begin_token, $end_token, $tokens)
pake_replace_tokens($arg, $target_dir, $begin_token, $end_token, $tokens)
pake_symlink($origin_dir, $target_dir, $copy_on_windows = false)
Creates symlink from $origin_dir to $target_dir. if $copy_on_windows is set to TRUE, then pake_mirror() will be used, in case when symlink functionality is not supported by OS.
pake_chmod($arg, $target_dir, $mode, $umask = 0000)
Applies new POSIX mode to files found by $arg rule in $target_dir. Notice: it is not safe to rely on umask in multithreaded environment.
pake_strip_php_comments($arg, $target_dir = ’’)
Parse all files found by $arg rule in $target_dir and, if those are php-files, removes comments from them.
pake_sh($cmd, $interactive = false)
Executes shell-command. If $interactive flag is not set STDOUT is not shown, but is returned instead. STDERR still goes straight to the screen, which allows to show password-request dialogs, for example.
On the other hand, if $interactive flag is set, then command is attached to standard stdin/stdout streams and user can interact with process. This is useful for running editors, for example.
pake_superuser_sh($cmd, $interactive = false)
Command if similar to pake_sh() but it tries to run command as superuser. If current user is “root”, already, then it just forwards call to pake_sh(). Otherwise, it will try to run command with sudo or su, depending on their availability.
pake_input($question, $default = null)
This function shows the question and then waits for input from the user. As soon as user presses Enter-key input is returned from this function. It works like this:
<?php $age = pake_input("How old are you?"); pake_echo_comment('Your age is: '.$age); ?>
How old are you? [>] 18 # Your age is: 18
pake_select_input($question, array $options, $default = null)
This function shows the question and provides several options, waiting for input from the user. As soon as user presses Enter-key input is returned from this function. $default, if specified, has to be numeric index of default option. It works like this:
<?php $options = array( '< 18', '18–25', '25–45', '> 45' ); $result = pake_select_input('How old are you?', $options, 1); pake_echo('Your age is: '.$result); ?>
How old are you? (1) < 18 (2) 18–25 (3) 25–45 (4) > 45 [> default="2"] 2 Your age is: 18–25
This is a standard mean for outputting progress information to the user. Resulting string is divided in 2 columns (each of those is left-aligned). It looks like this:
>> section action text goes here
Deliever commenting-message to the user (it will be yellow, if user’s terminal supports colors)
Deliever error-message to the user (it will be red and alarming, if user’s terminal supports colors)
This one just prints free-form message to the user (that is, if she want to see messages). No need to add “\n”
<?php pake_echo("Hello!"); pake_echo("World!"); ?>