EliziumNet/RexFs

Add Else parameter

Opened this issue · 0 comments

When a format parameter contains a reference to an named capture, but this capture is not resolved, currently, there is a rule which prevents the remaining placeholder to be removed. Before applying this rule, we should be able to replace these unresolved captures as per user request. The user should be able to provide an else parameter, which is a compound string of the form:

"<named-capture-a>,<else-value-a>;<named-capture-b>,<else-value-b>;...<named-capture-n>,<else-value-n>"

where named-capture-n is the name of the capture group and else-value-n is the else value that should be used for that capture if it is unresolved.

Eg:

for regular expression (git commit message check-in format, not a good example for renaming files/directories, but the point is still being made):

"^(?(?fix|feat|build|chore|ci|docs|doc|style|ref|perf|test)\s+(?:#(?\d{1,6}))?)?(?!)?:\s(?[\w\W\s]+)"

the named groups are:

  • type
  • issue
  • break
  • body

so the user should be able to provide else specifiers for any of these groups

Rename-Many ... -Paste "COMMIT: ${type}, ISSUE: ${issue}" -Else 'type,none;issue,-'

⚠️ Do not use comma as a separator, since it can be used in the file system and therefore would require some kind of escaping. The semi-colon to separate multiple fields is not ok either, so use a colon to separate a key from a value and | to separate fields:

"<named-capture-a>:<else-value-a>|<named-capture-b>:<else-value-b>|...|<named-capture-n>:<else-value-n>"