Skip to content

Commit

Permalink
Sort output of List and Evironment
Browse files Browse the repository at this point in the history
  • Loading branch information
James Stewart committed Apr 9, 2016
1 parent f8db7c1 commit 63f2aea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The following methods are available to use in a node.
created then the program will enter an infinite loop.
{{ list }}
Returns a slice of all nodes in the context except itself.
Returns a sorted slice of all nodes in the context except itself.
Example:
`{{ range list }}{{ . }}={{ const . }}; {{ end }}`
Expand Down
6 changes: 4 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"regexp"
"sort"
"strconv"
"sync"
)
Expand Down Expand Up @@ -221,12 +222,12 @@ func (n *Node) Delete(path ...string) error {
return nil
}

// Returns a slice of names relative to the node 'n' for itself and all child nodes in the node that have non nil default values.
// Returns a sorted slice of names relative to the node 'n' for itself and all child nodes in the node that have non nil default values.
func (n *Node) List() []string {
return n.environmentOffset(len(n.path()))
}

// Returns a slice of full names for itself and all child nodes in the node that have non nil default values.
// Returns a sorted slice of full names for itself and all child nodes in the node that have non nil default values.
func (n *Node) Environment() []string {
return n.environmentOffset(0)
}
Expand Down Expand Up @@ -271,5 +272,6 @@ func (n *Node) environmentOffset(offset int) []string {
env[i] = n.pathJoin(node.path()[offset:]...)
}

sort.StringSlice(env).Sort()
return env
}

0 comments on commit 63f2aea

Please sign in to comment.