1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
"github.com/juju/utils"
14
// Renderer provides methods for the different functions in
15
// the stdlib path/filepath package that don't relate to a concrete
16
// filesystem. So Abs, EvalSymlinks, Glob, Rel, and Walk are not
17
// included. Also, while the functions in path/filepath relate to the
18
// current host, the PathRenderer methods relate to the renderer's
19
// target platform. So for example, a windows-oriented implementation
20
// will give windows-specific results even when used on linux.
21
type Renderer interface {
22
// Base mimics path/filepath.
23
Base(path string) string
25
// Clean mimics path/filepath.
26
Clean(path string) string
28
// Dir mimics path/filepath.
29
Dir(path string) string
31
// Ext mimics path/filepath.
32
Ext(path string) string
34
// FromSlash mimics path/filepath.
35
FromSlash(path string) string
37
// IsAbs mimics path/filepath.
38
IsAbs(path string) bool
40
// Join mimics path/filepath.
41
Join(path ...string) string
43
// Match mimics path/filepath.
44
Match(pattern, name string) (matched bool, err error)
46
// NormCase normalizes the case of a pathname. On Unix and Mac OS X,
47
// this returns the path unchanged; on case-insensitive filesystems,
48
// it converts the path to lowercase.
49
NormCase(path string) string
51
// Split mimics path/filepath.
52
Split(path string) (dir, file string)
54
// SplitList mimics path/filepath.
55
SplitList(path string) []string
57
// SplitSuffix splits the pathname into a pair (root, suffix) such
58
// that root + suffix == path, and ext is empty or begins with a
59
// period and contains at most one period. Leading periods on the
60
// basename are ignored; SplitSuffix('.cshrc') returns ('.cshrc', '').
61
SplitSuffix(path string) (string, string)
63
// ToSlash mimics path/filepath.
64
ToSlash(path string) string
66
// VolumeName mimics path/filepath.
67
VolumeName(path string) string
70
// NewRenderer returns a Renderer for the given os.
71
func NewRenderer(os string) (Renderer, error) {
76
os = strings.ToLower(os)
78
case os == utils.OSWindows:
79
return &WindowsRenderer{}, nil
80
case utils.OSIsUnix(os):
81
return &UnixRenderer{}, nil
83
return &UnixRenderer{}, nil
85
return nil, errors.NotFoundf("renderer for %q", os)