mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 13:11:30 +00:00
Add support for more advanced ${xxx:...} syntax
Just ${xxx:+...} and ${xxx:-...} for now
Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
+34
-1
@@ -157,7 +157,40 @@ func (sw *shellWord) processDollar() (string, error) {
|
||||
sw.next()
|
||||
return sw.getEnv(name), nil
|
||||
}
|
||||
return "", fmt.Errorf("Unsupported ${} substitution: %s", sw.word)
|
||||
if ch == ':' {
|
||||
// Special ${xx:...} format processing
|
||||
// Yes it allows for recursive $'s in the ... spot
|
||||
|
||||
sw.next() // skip over :
|
||||
modifier := sw.next()
|
||||
|
||||
word, err := sw.processStopOn('}')
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Grab the current value of the variable in question so we
|
||||
// can use to to determine what to do based on the modifier
|
||||
newValue := sw.getEnv(name)
|
||||
|
||||
switch modifier {
|
||||
case '+':
|
||||
if newValue != "" {
|
||||
newValue = word
|
||||
}
|
||||
return newValue, nil
|
||||
|
||||
case '-':
|
||||
if newValue == "" {
|
||||
newValue = word
|
||||
}
|
||||
return newValue, nil
|
||||
|
||||
default:
|
||||
return "", fmt.Errorf("Unsupported modifier (%c) in substitution: %s", modifier, sw.word)
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("Missing ':' in substitution: %s", sw.word)
|
||||
}
|
||||
// $xxx case
|
||||
name := sw.processName()
|
||||
|
||||
Reference in New Issue
Block a user