forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
41 lines (34 loc) · 871 Bytes
/
utils.go
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
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package context
import (
"os"
"path/filepath"
"github.com/juju/cmd"
"github.com/juju/errors"
"gopkg.in/juju/charm.v6"
)
type componentHookFunction func() (Component, error)
func componentHookContext(ctx HookContext) componentHookFunction {
return func() (Component, error) {
compCtx, err := ContextComponent(ctx)
if err != nil {
// The component wasn't tracked properly.
return nil, errors.Trace(err)
}
return compCtx, nil
}
}
func readMetadata(ctx *cmd.Context) (*charm.Meta, error) {
filename := filepath.Join(ctx.Dir, "metadata.yaml")
file, err := os.Open(filename)
if err != nil {
return nil, errors.Trace(err)
}
defer file.Close()
meta, err := charm.ReadMeta(file)
if err != nil {
return nil, errors.Trace(err)
}
return meta, nil
}