launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/cmd/charmload/main.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"path/filepath"
    10  
    11  	"launchpad.net/lpad"
    12  
    13  	"launchpad.net/juju-core/store"
    14  )
    15  
    16  func main() {
    17  	err := load()
    18  	if err != nil {
    19  		fmt.Fprintf(os.Stderr, "%v\n", err)
    20  		os.Exit(1)
    21  	}
    22  }
    23  
    24  func load() error {
    25  	var confPath string
    26  	if len(os.Args) == 2 {
    27  		if _, err := os.Stat(os.Args[1]); err == nil {
    28  			confPath = os.Args[1]
    29  		}
    30  	}
    31  	if confPath == "" {
    32  		return fmt.Errorf("usage: %s <config path>", filepath.Base(os.Args[0]))
    33  	}
    34  	conf, err := store.ReadConfig(confPath)
    35  	if err != nil {
    36  		return err
    37  	}
    38  	if conf.MongoURL == "" {
    39  		return fmt.Errorf("missing mongo-url in config file")
    40  	}
    41  	s, err := store.Open(conf.MongoURL)
    42  	if err != nil {
    43  		return err
    44  	}
    45  	defer s.Close()
    46  	err = store.PublishCharmsDistro(s, lpad.Production)
    47  	if _, ok := err.(store.PublishBranchErrors); ok {
    48  		// Ignore branch errors since they're commonplace here.
    49  		// They're logged, though.
    50  		return nil
    51  	}
    52  	return err
    53  }