Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 package charm | 1 package charm |
2 | 2 |
3 import ( | 3 import ( |
4 "errors" | |
4 "fmt" | 5 "fmt" |
5 "os" | 6 "os" |
6 ) | 7 ) |
7 | 8 |
8 // The Charm interface is implemented by any type that | 9 // The Charm interface is implemented by any type that |
9 // may be handled as a charm. | 10 // may be handled as a charm. |
10 type Charm interface { | 11 type Charm interface { |
11 Meta() *Meta | 12 Meta() *Meta |
12 Config() *Config | 13 Config() *Config |
13 Revision() int | 14 Revision() int |
14 } | 15 } |
15 | 16 |
16 // Read reads a Charm from path, which can point to either a charm bundle or a | 17 // Read reads a Charm from path, which can point to either a charm bundle or a |
17 // charm directory. | 18 // charm directory. |
18 func Read(path string) (Charm, error) { | 19 func Read(path string) (Charm, error) { |
19 info, err := os.Stat(path) | 20 info, err := os.Stat(path) |
20 if err != nil { | 21 if err != nil { |
21 return nil, err | 22 return nil, err |
22 } | 23 } |
23 if info.IsDir() { | 24 if info.IsDir() { |
24 return ReadDir(path) | 25 return ReadDir(path) |
25 } | 26 } |
26 return ReadBundle(path) | 27 return ReadBundle(path) |
27 } | 28 } |
28 | 29 |
29 // Resolve takes a (potentially vaguely-specified) charm name, the path to the | 30 // InferRepository returns a charm repository and URL inferred from the provided |
30 // local charm repository, and the environment's default Ubuntu series, and | 31 // parameters. charmAlias may hold an exact charm URL, or an alias in a |
31 // assembles them into a charm URL and a repository which is likely to contain | 32 // format supported by InferURL. |
32 // a charm matching that URL. | 33 func InferRepository(charmAlias, defaultSeries, localRepoPath string) (repo Repo sitory, curl *URL, err error) { |
niemeyer
2012/06/01 13:32:34
// InferRepository returns a charm repository and
fwereade
2012/06/01 14:32:34
Done.
| |
33 func Resolve(name, repoPath, defaultSeries string) (repo Repository, curl *URL, err error) { | 34 » if curl, err = InferURL(charmAlias, defaultSeries); err != nil { |
niemeyer
2012/06/01 13:32:34
This is InferURL + repository. I suggest this sign
fwereade
2012/06/01 14:32:34
Done.
| |
34 » if curl, err = InferURL(name, defaultSeries); err != nil { | |
35 return | 35 return |
36 } | 36 } |
37 switch curl.Schema { | 37 switch curl.Schema { |
38 case "cs": | 38 case "cs": |
39 repo = Store() | 39 repo = Store() |
40 case "local": | 40 case "local": |
41 » » repo = &LocalRepository{repoPath} | 41 » » if localRepoPath == "" { |
niemeyer
2012/06/01 13:32:34
Should we support the case where localRepoPath is
fwereade
2012/06/01 14:32:34
I think an explicit error here is a good idea. Don
| |
42 » » » return nil, nil, errors.New("path to local repository no t specified") | |
43 » » } | |
44 » » repo = &LocalRepository{localRepoPath} | |
42 default: | 45 default: |
43 panic(fmt.Errorf("unknown schema for charm URL %q", curl)) | 46 panic(fmt.Errorf("unknown schema for charm URL %q", curl)) |
44 } | 47 } |
45 return | 48 return |
46 } | 49 } |
LEFT | RIGHT |