grim/convey

Add more docs.
auto-split
2017-09-21, Eric Fritz
bd7a742de64a
Parents 98eb1323e154
Children 093477a2c281
Add more docs.
--- a/state/state.go Thu Sep 21 19:25:24 2017 -0500
+++ b/state/state.go Thu Sep 21 19:28:42 2017 -0500
@@ -69,12 +69,15 @@
// see if the variable could be expanded into a list.
func (st *State) MapSlice(env, fullEnv []string) ([]string, error) {
if len(env) == 1 {
+ // If we only have one thing and it looks like $VAR or ${VAR}, then
+ // see if we have it in the list of things we can expand on the stack.
if delimiter, ok := st.getDelimiter(getName(env[0])); ok {
mapped, err := environment.Mapper(env[0], fullEnv)
if err != nil {
return nil, err
}
+ // Split it!
return strings.SplitN(mapped, delimiter, -1), nil
}
}
@@ -82,6 +85,8 @@
return environment.SliceMapper(env, fullEnv)
}
+// GetDelimiter returns the highest (outermost extend task) delimiter registered
+// when a given expandable environment variable. Returns true if found by name.
func (st *State) getDelimiter(name string) (string, bool) {
for i := len(st.ExtendFrames) - 1; i >= 0; i-- {
frame := st.ExtendFrames[i]