Skip to content

Commit

Permalink
regex-fix - Deal with Windows munging command line regex
Browse files Browse the repository at this point in the history
  • Loading branch information
EJMFarrow committed Jun 6, 2024
1 parent 4c4e5bd commit b20dbca
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions classes/cli_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public function validate_and_clean_args(): void {
}
}
if (isset($cliargs['ignorecat'])) {
// Allow escaping of forward slash at start in Windows.
if (strlen($cliargs['ignorecat']) > 1 && substr($cliargs['ignorecat'], 0, 2) === '//') {
$cliargs['ignorecat'] = substr($cliargs['ignorecat'], 1);
}
echo $cliargs['ignorecat'];
if (@preg_match($cliargs['ignorecat'], 'zzzzzzzz') === false) {
echo "\nThere is a problem with your regular expression for ignoring categories:\n";
echo error_get_last()["message"] . "\n";
Expand Down
2 changes: 1 addition & 1 deletion cli/createrepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion cli/deletefrommoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion cli/exportrepofrommoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion cli/importrepotomoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion doc/createrepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
|n|instanceid|Numerical id of the course, module of course category.
|t|token|Security token for webservice.
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

### Example 1:

Expand Down
2 changes: 1 addition & 1 deletion doc/deletefrommoodle.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|n|instanceid|Numerical id of the course, module of course category.
|t|token|Security token for webservice.
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion doc/exportrepofrommoodle.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
|q|questioncategoryid|Numerical id of subcategory to actually export.
|t|token|Security token for webservice.|
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion doc/importrepotomoodle.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Commit this update.
|n|instanceid|Numerical id of the course, module of course category.
|t|token|Security token for webservice.
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion doc/usinggit.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can use context instance id and subcategory id instead:
* `-n` the context instance id, which is the course id in this case.
* `-q` the question category id

You can also ignore certain categories (and their descendants) using `-x` and a regex expression to match the category name(s) within Moodle.
You can also ignore certain categories (and their descendants) using `-x` and a regex expression to match the category name(s) within Moodle. (Add an extra leading / in Windows e.g. "//^.*DO_NOT_SHARE$/".)

`php createrepo.php -l course -n 2 -d "master" -q 80 -x "/^.*DO_NOT_SHARE$/"`

Expand Down

0 comments on commit b20dbca

Please sign in to comment.