Skip to content

Commit

Permalink
Strip invalid options before run. #39
Browse files Browse the repository at this point in the history
  • Loading branch information
timonwong committed Mar 2, 2015
1 parent 6ce9b09 commit da0b187
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion AStyleFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def _read_astylerc(self, path):

@staticmethod
def _join_options(options_list):
return ' '.join(o for o in options_list if o)
return Options.strip_invalid_options_string(
' '.join(o for o in options_list if o))

def _get_options(self, syntax, formatting_mode):
syntax_settings = self._get_syntax_settings(syntax, formatting_mode)
Expand Down
39 changes: 39 additions & 0 deletions AStyleFormatterLib/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import shlex


class ImproperlyConfigured(Exception):
Expand Down Expand Up @@ -243,3 +244,41 @@ def build_astyle_options(settings, indent_options, convert_tabs=False):
value = settings[option_name]
options = function(options, option_name, value)
return options


_BLACK_LIST_MATCH = set([
'-n',
'--recursive', '-r', '-R',
'--dry-run', '--exclude',
'--ignore-exclude-errors', '-i',
'--ignore-exclude-errors-x', '-xi',
'--errors-to-stdout', '-X',
'--preserve-date', '-Z',
'--verbose', '-v',
'--formatted', '-Q',
'--quiet', '-q',
'--lineend', '-z1', '-z2', '-z3',
'--ascii', '-I'
'--version', '-V',
'--help', '-h', '-?',
'--html', '-!',
])

_BLACK_LIST_STARTS_WITH = set([
'--suffix=',
'--exclude=',
])


def strip_invalid_options_string(options_string):
options = shlex.split(options_string)
result = []
for option in options:
if option in _BLACK_LIST_MATCH:
continue
if '=' in option:
for item in _BLACK_LIST_STARTS_WITH:
if option.startswith(item):
continue
result.append(option)
return ' '.join(result)

0 comments on commit da0b187

Please sign in to comment.