Permalink
Browse files

Change - to _ in one place, to simplify options/flags.

  • Loading branch information...
Andy Chu
Andy Chu committed Dec 25, 2017
1 parent 6841a09 commit 6a45bd998e0fc10e8a4aac394c7cdedbabcc4972
Showing with 12 additions and 13 deletions.
  1. +9 −7 core/args.py
  2. +1 −1 core/builtin.py
  3. +2 −5 core/state.py
View
@@ -70,9 +70,11 @@ def __init__(self, defaults):
self.opt_changes = [] # special name
self.saw_double_dash = False # for set --
for name, v in defaults.iteritems():
setattr(self, name, v)
self.Set(name, v)
# TODO: Instead of setattr(), use Set(name, val), and change '-' to '_'?
def Set(self, name, value):
# debug-completion -> debug_completion
setattr(self, name.replace('-', '_'), value)
def __repr__(self):
return '<_Attributes %s>' % self.__dict__
@@ -152,7 +154,7 @@ def OnMatch(self, prefix, suffix, state, out):
else:
raise AssertionError
setattr(out, self.name, value)
out.Set(self.name, value)
return self.quit_parsing_flags
@@ -163,7 +165,7 @@ def __init__(self, name):
def OnMatch(self, prefix, suffix, state, out):
"""Called when the flag matches."""
setattr(out, self.name, True)
out.Set(self.name, True)
class SetOption(_Action):
@@ -197,7 +199,7 @@ def OnMatch(self, prefix, suffix, state, out):
except IndexError:
raise UsageError('Expected argument for option')
attr_name = arg.replace('-', '_')
attr_name = arg
# Validate the option name against a list of valid names.
if attr_name not in self.names:
raise UsageError('Invalid option name %r' % arg)
@@ -252,7 +254,7 @@ def LongFlag(self, long_name, arg_type=None, default=None):
""" --rcfile """
assert long_name.startswith('--'), long_name
name = long_name[2:].replace('-', '_')
name = long_name[2:]
if arg_type is None:
self.actions_long[long_name] = SetToTrue(name)
else:
@@ -266,7 +268,7 @@ def Option(self, short_flag, name):
short_flag: 'e'
name: errexit
"""
attr_name = name.replace('-', '_') # debug-completion -> debug_completion
attr_name = name
if short_flag:
assert not short_flag.startswith('-'), short_flag
self.actions_short[short_flag] = SetOption(attr_name)
View
@@ -614,7 +614,7 @@ def AddOptionsToArgSpec(spec):
def SetExecOpts(exec_opts, opt_changes):
"""Used by bin/oil.py too."""
for opt_name, b in opt_changes:
exec_opts.SetOption(opt_name.replace('-', '_'), b)
exec_opts.SetOption(opt_name, b)
def Set(argv, exec_opts, mem):
View
@@ -78,10 +78,7 @@ def Set(self, b):
(None, 'strict-control-flow'),
]
# NOTE: We have to change - to _ here, because we need to match _Attributes in
# core/args.py.
_SET_OPTION_NAMES = set(name.replace('-', '_') for _, name in SET_OPTIONS)
_SET_OPTION_NAMES = set(name for _, name in SET_OPTIONS)
class ExecOpts(object):
@@ -137,7 +134,7 @@ def GetDollarHyphen(self):
def SetOption(self, opt_name, b):
""" For set -o, set +o, or shopt -s/-u -o. """
assert '-' not in opt_name, 'Option names should have _, not -'
assert '_' not in opt_name
if opt_name not in _SET_OPTION_NAMES:
raise args.UsageError('Invalid option %r' % opt_name)
if opt_name == 'errexit':

0 comments on commit 6a45bd9

Please sign in to comment.