Skip to content

Commit

Permalink
Added default settings in config.php for the script parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jari Kanerva committed Dec 24, 2009
1 parent ae84813 commit 66604dd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README
Expand Up @@ -25,7 +25,9 @@ The parameters to modx_gen.php needs to be after "php modx_gen.php".
-h, --help = print this text.
-f, --outfile = path and name of file to generate. Defautls to stdout
-v, --verbose = Tell what happens.
-i, --ignore-version = ignore the version info at the top of files.
-i, --ignore-version = ignore SVN version info at the top of files.

Note that most of the parameters have a default value that can be set in config.php

CONFIGURATION
config.php contains two lists.
Expand All @@ -34,3 +36,5 @@ Files in this array are not added to the copy list if they are missing and not c

$ignore_ext contains file extensions to not compare.
Files with these extensions are added to copy and (if selected) copied to root. But they are not compared.

It also contains the $defaults array. Look in config.php for more informaion on this array.
24 changes: 24 additions & 0 deletions config.php
Expand Up @@ -40,3 +40,27 @@
'tar',
'rar',
);

/**
* Default settings for the script parameters.
* They can be overridden at runtime by using the parameters in the command line.
*/
$defaults = array(
// You need to specify a path for the first three if you use them.
// 'old' for -o, --old = Original files, path can be absolute or relative.
'old' => '',
// 'new' for -n, --new = Modified files, path can be absolute or relative.
'new' => '',
// 'root' for -r, --root = Creates a root directory containing the files missing in old.
'root' => '',
//'outfile' for -f, --outfile = path and name of file to generate. Defautls to stdout.
// You need to specify path and file name if you want to use this.
'outfile' => '',
// The following are just on or off (true or false).
// 'verbose' for -v, --verbose = Tell what happens.
'verbose' => false,
// 'custom' for -c, --custom = This is an install file for a addition style or language.
'custom' => false,
// 'ignore_version' for -i, --ignore-version = ignore SVN version info at the top of files.
'ignore_version' => true,
);
16 changes: 7 additions & 9 deletions functions.php
Expand Up @@ -11,11 +11,9 @@
/**
* parses the args sent to the script
*/
function parse_args($argv)
function parse_args($argv, $defaults)
{
$args = array();
$args['diff_opt'] = DIFF_BASIC;
$args['verbose'] =false;
$args = $defaults;
foreach ($argv as $key => $value)
{
switch($value)
Expand All @@ -37,7 +35,7 @@ function parse_args($argv)

case '-v':
case '--verbose':
$args['verbose'] = true;
$args['verbose'] = ($args['verbose']) ? false : true;
break;

case '-h':
Expand All @@ -47,12 +45,12 @@ function parse_args($argv)

case '-c':
case '--custom':
$args['diff_opt'] = DIFF_CUSTOM;
$args['custom'] = ($args['custom']) ? false : true;
break;

case '-i':
case '--ignore-version':
$args['ignore'] = true;
$args['ignore_version'] = ($args['ignore_version']) ? false : true;
break;

case '-r':
Expand All @@ -73,7 +71,7 @@ function parse_args($argv)
*/
function rem_ignore(&$old_file, &$new_file)
{
// The version string is usually at line 5, but it can be anywhere in the beginning.
// The SVN version string is usually at line 5, but it can be anywhere in the beginning.
// Let's check the 20 first lines only. And assume it's in the same place in both files.
// Otherwise let's diff that to.
for ($i = 0; $i < 20; $i++)
Expand Down Expand Up @@ -192,7 +190,7 @@ function get_dir_contents($dir, &$dir_arr, $base = '')
if (!in_array($file, $ignore))
{
$path = $dir . $dir_separator . $file;
if ($args['diff_opt'] == DIFF_BASIC && is_dir($path))
if (!$args['custom'] && is_dir($path))
{
// Only diff Prosilver and English
// Other styles and languages require their own install files.
Expand Down
14 changes: 7 additions & 7 deletions modx_gen.php
Expand Up @@ -31,10 +31,10 @@
require($script_path . 'config.' . $phpEx);
require($script_path . 'functions.' . $phpEx);

$args = parse_args($argv);
$args = parse_args($argv, $defaults);

$slap = $diff_files = $diff_dirs = $where_changes = false;
if (empty($args['old']) || empty($args['new']) || isset($args['help']) || (isset($args['root']) && !is_dir($args['root'])))
if (empty($args['old']) || empty($args['new']) || !empty($args['help']) || (!empty($args['root']) && !is_dir($args['root'])))
{
$slap = true;
}
Expand Down Expand Up @@ -67,7 +67,7 @@
echo '-h, --help = print this text.' . "\n";
echo '-f, --outfile = path and name of file to generate. Defautls to stdout.' . "\n";
echo '-v, --verbose = tell what happens.' . "\n";
echo '-i, --ignore-version = ignore the version info at the top of files.' . "\n";
echo '-i, --ignore-version = ignore SVN version info at the top of files.' . "\n";
exit;
}

Expand All @@ -78,7 +78,7 @@
$old_file = file($args['old']);
$new_file = file($args['new']);

if (isset($args['ignore']))
if (!empty($args['ignore_version']))
{
// Ignore the version strings.
rem_ignore($old_file, $new_file);
Expand Down Expand Up @@ -137,7 +137,7 @@
{
echo 'Checking for missing files' . "\n";
}
$where_changes = check_missing($old_arr, $new_arr, ((isset($args['root'])) ? $args['root'] : false));
$where_changes = check_missing($old_arr, $new_arr, ((!empty($args['root'])) ? $args['root'] : false));

foreach ($old_arr as $file)
{
Expand All @@ -155,7 +155,7 @@
$old_file = file($args['old'] . $file);
$new_file = file($args['new'] . $file);

if (isset($args['ignore']))
if (!empty($args['ignore_version']))
{
// Ignore the version strings.
rem_ignore($old_file, $new_file);
Expand Down Expand Up @@ -198,7 +198,7 @@

if (isset($xml) && $where_changes)
{
$out_file = (isset($args['outfile'])) ? $args['outfile'] : '';
$out_file = (!empty($args['outfile'])) ? $args['outfile'] : '';
$xml->modx_close($out_file);
}
else
Expand Down

0 comments on commit 66604dd

Please sign in to comment.