github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/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 "github.com/juju/charmstore" 12 "launchpad.net/lpad" 13 ) 14 15 func main() { 16 err := load() 17 if err != nil { 18 fmt.Fprintf(os.Stderr, "%v\n", err) 19 os.Exit(1) 20 } 21 } 22 23 func load() error { 24 var confPath string 25 if len(os.Args) == 2 { 26 if _, err := os.Stat(os.Args[1]); err == nil { 27 confPath = os.Args[1] 28 } 29 } 30 if confPath == "" { 31 return fmt.Errorf("usage: %s <config path>", filepath.Base(os.Args[0])) 32 } 33 conf, err := charmstore.ReadConfig(confPath) 34 if err != nil { 35 return err 36 } 37 if conf.MongoURL == "" { 38 return fmt.Errorf("missing mongo-url in config file") 39 } 40 s, err := charmstore.Open(conf.MongoURL) 41 if err != nil { 42 return err 43 } 44 defer s.Close() 45 err = charmstore.PublishCharmsDistro(s, lpad.Production) 46 if _, ok := err.(charmstore.PublishBranchErrors); ok { 47 // Ignore branch errors since they're commonplace here. 48 // They're logged, though. 49 return nil 50 } 51 return err 52 }