diff --git a/README b/README index 3ab5176..934ee1f 100644 --- a/README +++ b/README @@ -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. @@ -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. diff --git a/config.php b/config.php index ba110b3..8495a34 100644 --- a/config.php +++ b/config.php @@ -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, +); diff --git a/functions.php b/functions.php index 236388b..d1aafed 100644 --- a/functions.php +++ b/functions.php @@ -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) @@ -37,7 +35,7 @@ function parse_args($argv) case '-v': case '--verbose': - $args['verbose'] = true; + $args['verbose'] = ($args['verbose']) ? false : true; break; case '-h': @@ -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': @@ -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++) @@ -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. diff --git a/modx_gen.php b/modx_gen.php index 24cf6da..6900960 100644 --- a/modx_gen.php +++ b/modx_gen.php @@ -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; } @@ -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; } @@ -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); @@ -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) { @@ -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); @@ -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