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
36
37
38
39
40
41
42
43
44
45
|
package charm
import (
"errors"
"fmt"
"os"
)
// The Charm interface is implemented by any type that
// may be handled as a charm.
type Charm interface {
Meta() *Meta
Config() *Config
Revision() int
}
// Read reads a Charm from path, which can point to either a charm bundle or a
// charm directory.
func Read(path string) (Charm, error) {
info, err := os.Stat(path)
if err != nil {
return nil, err
}
if info.IsDir() {
return ReadDir(path)
}
return ReadBundle(path)
}
// InferRepository returns a charm repository inferred from
// the provided URL. Local URLs will use the provided path.
func InferRepository(curl *URL, localRepoPath string) (repo Repository, err error) {
switch curl.Schema {
case "cs":
repo = Store()
case "local":
if localRepoPath == "" {
return nil, errors.New("path to local repository not specified")
}
repo = &LocalRepository{localRepoPath}
default:
return nil, fmt.Errorf("unknown schema for charm URL %q", curl)
}
return
}
|