Skip to content

Commit 872cdf4

Browse files
committed
CLI parsing for fields with comma delimiter supports escaping
Example: --extra-fields "MFG\,MFG#,VEND1\,VEND1#" will yield fields with names MFG,MFG# VEND1,VEND1# Fixes #103
1 parent d61bd56 commit 872cdf4

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

InteractiveHtmlBom/core/config.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import os
5+
import re
56

67
from wx import FileConfig
78

@@ -10,18 +11,18 @@
1011

1112
class Config:
1213
FILE_NAME_FORMAT_HINT = (
13-
'Output file name format supports substitutions:\n'
14-
'\n'
15-
' %f : original pcb file name without extension.\n'
16-
' %p : pcb/project title from pcb metadata.\n'
17-
' %c : company from pcb metadata.\n'
18-
' %r : revision from pcb metadata.\n'
19-
' %d : pcb date from metadata if available, '
20-
'file modification date otherwise.\n'
21-
' %D : bom generation date.\n'
22-
' %T : bom generation time.\n'
23-
'\n'
24-
'Extension .html will be added automatically.'
14+
'Output file name format supports substitutions:\n'
15+
'\n'
16+
' %f : original pcb file name without extension.\n'
17+
' %p : pcb/project title from pcb metadata.\n'
18+
' %c : company from pcb metadata.\n'
19+
' %r : revision from pcb metadata.\n'
20+
' %d : pcb date from metadata if available, '
21+
'file modification date otherwise.\n'
22+
' %D : bom generation date.\n'
23+
' %T : bom generation time.\n'
24+
'\n'
25+
'Extension .html will be added automatically.'
2526
) # type: str
2627

2728
# Helper constants
@@ -76,7 +77,7 @@ class Config:
7677
@staticmethod
7778
def _split(s):
7879
"""Splits string by ',' and drops empty strings from resulting array."""
79-
return [a for a in s.split(',') if a]
80+
return [a.replace('\\,', ',') for a in re.split(r'(?<!\\),', s) if a]
8081

8182
def __init__(self):
8283
"""Init from config file if it exists."""

0 commit comments

Comments
 (0)