Expand references in non-shell variables too

This commit is contained in:
Ben Jackson 2020-01-09 14:14:15 +00:00
commit 8a57104a0e

View file

@ -323,11 +323,20 @@ def SetBufferContents( buf, lines, modified=False ):
def IsCurrent( window, buf ):
return vim.current.window == window and vim.current.window.buffer == buf
def ExpandReferencesInObject( obj, mapping, user_choices ):
if isinstance( obj, dict ):
ExpandReferencesInDict( obj, mapping, user_choices )
elif isinstance( obj, list ):
for i, _ in enumerate( obj ):
# FIXME: We are assuming that it is a list of string, but could be a
# list of list of a list of dict, etc.
obj[ i ] = ExpandReferencesInObject( obj[ i ], mapping, user_choices )
elif isinstance( obj, str ):
obj = ExpandReferencesInString( obj, mapping, user_choices )
# TODO: Should we just run the substitution on the whole JSON string instead?
# That woul dallow expansion in bool and number values, such as ports etc. ?
def ExpandReferencesInDict( obj, mapping, user_choices ):
def expand_refs_in_string( orig_s ):
return obj
def ExpandReferencesInString( orig_s, mapping, user_choices):
s = os.path.expanduser( orig_s )
s = os.path.expandvars( s )
@ -360,21 +369,11 @@ def ExpandReferencesInDict( obj, mapping, user_choices ):
return s
def expand_refs_in_object( obj ):
if isinstance( obj, dict ):
ExpandReferencesInDict( obj, mapping, user_choices )
elif isinstance( obj, list ):
for i, _ in enumerate( obj ):
# FIXME: We are assuming that it is a list of string, but could be a
# list of list of a list of dict, etc.
obj[ i ] = expand_refs_in_object( obj[ i ] )
elif isinstance( obj, str ):
obj = expand_refs_in_string( obj )
return obj
# TODO: Should we just run the substitution on the whole JSON string instead?
# That woul dallow expansion in bool and number values, such as ports etc. ?
def ExpandReferencesInDict( obj, mapping, user_choices ):
for k in obj.keys():
obj[ k ] = expand_refs_in_object( obj[ k ] )
obj[ k ] = ExpandReferencesInObject( obj[ k ], mapping, user_choices )
def ParseVariables( variables_list, mapping, user_choices ):
@ -416,7 +415,9 @@ def ParseVariables( variables_list, mapping, user_choices ):
raise ValueError(
"Unsupported variable defn {}: Missing 'shell'".format( n ) )
else:
new_variables[ n ] = v
new_variables[ n ] = ExpandReferencesInObject( v,
mapping,
user_choices )
return new_variables