1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package cmd
import (
"errors"
"io/ioutil"
)
// FileVar represents a path to a file.
type FileVar struct {
Path string
}
var ErrNoPath = errors.New("path not set")
// Set stores the chosen path name in f.Path.
func (f *FileVar) Set(v string) error {
f.Path = v
return nil
}
// Read returns the contents of the file.
func (f *FileVar) Read(ctx *Context) ([]byte, error) {
if f.Path == "" {
return nil, ErrNoPath
}
return ioutil.ReadFile(ctx.AbsPath(f.Path))
}
// String returns the path to the file.
func (f *FileVar) String() string {
return f.Path
}
|