Skip to content

Commit

Permalink
CLI parsing for fields with comma delimiter supports escaping
Browse files Browse the repository at this point in the history
Example:
--extra-fields "MFG\,MFG#,VEND1\,VEND1#"
will yield fields with names
MFG,MFG#
VEND1,VEND1#

Fixes #103
  • Loading branch information
qu1ck committed Jun 27, 2019
1 parent d61bd56 commit 872cdf4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions InteractiveHtmlBom/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import os
import re

from wx import FileConfig

Expand All @@ -10,18 +11,18 @@

class Config:
FILE_NAME_FORMAT_HINT = (
'Output file name format supports substitutions:\n'
'\n'
' %f : original pcb file name without extension.\n'
' %p : pcb/project title from pcb metadata.\n'
' %c : company from pcb metadata.\n'
' %r : revision from pcb metadata.\n'
' %d : pcb date from metadata if available, '
'file modification date otherwise.\n'
' %D : bom generation date.\n'
' %T : bom generation time.\n'
'\n'
'Extension .html will be added automatically.'
'Output file name format supports substitutions:\n'
'\n'
' %f : original pcb file name without extension.\n'
' %p : pcb/project title from pcb metadata.\n'
' %c : company from pcb metadata.\n'
' %r : revision from pcb metadata.\n'
' %d : pcb date from metadata if available, '
'file modification date otherwise.\n'
' %D : bom generation date.\n'
' %T : bom generation time.\n'
'\n'
'Extension .html will be added automatically.'
) # type: str

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

def __init__(self):
"""Init from config file if it exists."""
Expand Down

0 comments on commit 872cdf4

Please sign in to comment.