github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/payload/context/utils.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package context
     5  
     6  import (
     7  	"os"
     8  	"path/filepath"
     9  
    10  	"github.com/juju/cmd"
    11  	"github.com/juju/errors"
    12  	"gopkg.in/juju/charm.v6-unstable"
    13  )
    14  
    15  func readMetadata(ctx *cmd.Context) (*charm.Meta, error) {
    16  	filename := filepath.Join(ctx.Dir, "metadata.yaml")
    17  	file, err := os.Open(filename)
    18  	if err != nil {
    19  		return nil, errors.Trace(err)
    20  	}
    21  	defer file.Close()
    22  	meta, err := charm.ReadMeta(file)
    23  	if err != nil {
    24  		return nil, errors.Trace(err)
    25  	}
    26  
    27  	return meta, nil
    28  }