Example #1
1
// Error ...
func (e TypeMismatchError) Error() string {
	if e.Got == "" {
		return ansi.Sprintf("@c{%s} @R{is not} @m{%s}", strings.Join(e.Path, "."), e.Wanted)
	}
	if e.Value != nil {
		return ansi.Sprintf("@c{$.%s} @R{[=%v] is %s (not} @m{%s}@R{)}", strings.Join(e.Path, "."), e.Value, e.Got, e.Wanted)
	}
	return ansi.Sprintf("@C{$.%s} @R{is %s (not} @m{%s}@R{)}", strings.Join(e.Path, "."), e.Got, e.Wanted)
}
Example #2
1
// Error ...
func (e MultiError) Error() string {
	s := []string{}
	for _, err := range e.Errors {
		s = append(s, fmt.Sprintf(" - %s\n", err))
	}

	sort.Strings(s)
	return ansi.Sprintf("@r{%d} error(s) detected:\n%s\n", len(e.Errors), strings.Join(s, ""))
}
Example #3
1
// Tree returns a tree that represents the hierarchy of paths contained
// below the given path, inside of the Vault.
func (v *Vault) Tree(path string, options TreeOptions) (tree.Node, error) {
	t, _, err := v.walktree(path, options)
	if err != nil {
		return t, err
	}
	if options.UseANSI {
		t.Name = ansi.Sprintf("@C{%s}", path)
	} else {
		t.Name = path
	}
	return t, nil
}
Example #4
1
func (v *Vault) walktree(path string, options TreeOptions) (tree.Node, int, error) {
	t := tree.New(path)
	l, err := v.List(path)
	if err != nil {
		return t, 0, err
	}

	for _, p := range l {
		if p[len(p)-1:len(p)] == "/" {
			kid, n, err := v.walktree(path+"/"+p[0:len(p)-1], options)
			if err != nil {
				return t, 0, err
			}
			if n == 0 {
				continue
			}
			if options.UseANSI {
				kid.Name = ansi.Sprintf("@B{%s}", p)
			} else {
				kid.Name = p[0 : len(p)-1]
			}
			t.Append(kid)

		} else if options.HideLeaves {
			continue

		} else {
			var name string
			if options.UseANSI {
				name = ansi.Sprintf("@G{%s}", p)
			} else {
				name = p
			}
			t.Append(tree.New(name))
		}
	}
	return t, len(l), nil
}
Example #5
1
// Error ...
func (e NotFoundError) Error() string {
	return ansi.Sprintf("@R{`}@c{$.%s}@R{` could not be found in the datastructure}", strings.Join(e.Path, "."))
}