Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: store/charmload/main.go

Issue 5901058: cmd/juju: working bootstrap and destroy commands
Patch Set: cmd/juju: working bootstrap and destroy commands Created 12 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « store/charmload/config.yaml ('k') | store/server.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package main 1 package main
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "io/ioutil"
6 "launchpad.net/goyaml"
5 "launchpad.net/juju/go/log" 7 "launchpad.net/juju/go/log"
6 "launchpad.net/juju/go/store" 8 "launchpad.net/juju/go/store"
7 "launchpad.net/lpad" 9 "launchpad.net/lpad"
8 stdlog "log" 10 stdlog "log"
9 "os" 11 "os"
10 "path/filepath" 12 "path/filepath"
11 ) 13 )
12 14
13 func main() { 15 func main() {
14 log.Target = stdlog.New(os.Stdout, "", stdlog.LstdFlags) 16 log.Target = stdlog.New(os.Stdout, "", stdlog.LstdFlags)
15 err := load() 17 err := load()
16 if err != nil { 18 if err != nil {
17 fmt.Fprintf(os.Stderr, "%v\n", err) 19 fmt.Fprintf(os.Stderr, "%v\n", err)
18 os.Exit(1) 20 os.Exit(1)
19 } 21 }
20 } 22 }
21 23
24 type config struct {
25 MongoURL string `yaml:"mongo-url"`
26 }
27
28 func readConfig(path string, conf interface{}) error {
29 f, err := os.Open(path)
30 if err != nil {
31 return fmt.Errorf("opening config file: %v", err)
32 }
33 data, err := ioutil.ReadAll(f)
34 f.Close()
35 if err != nil {
36 return fmt.Errorf("reading config file: %v", err)
37 }
38 err = goyaml.Unmarshal(data, conf)
39 if err != nil {
40 return fmt.Errorf("processing config file: %v", err)
41 }
42 return nil
43 }
44
22 func load() error { 45 func load() error {
23 » if len(os.Args) != 2 || len(os.Args[1]) == 0 || os.Args[1][0] == '-' { 46 » var confPath string
24 » » return fmt.Errorf("usage: %s <mongo addr>", filepath.Base(os.Arg s[0])) 47 » if len(os.Args) == 2 {
48 » » if _, err := os.Stat(os.Args[1]); err == nil {
49 » » » confPath = os.Args[1]
50 » » }
25 } 51 }
26 » s, err := store.Open(os.Args[1]) 52 » if confPath == "" {
53 » » return fmt.Errorf("usage: %s <config path>", filepath.Base(os.Ar gs[0]))
54 » }
55 » var conf config
56 » err := readConfig(confPath, &conf)
27 if err != nil { 57 if err != nil {
28 return err 58 return err
29 } 59 }
60 if conf.MongoURL == "" {
61 return fmt.Errorf("missing mongo-url in config file")
62 }
63 s, err := store.Open(conf.MongoURL)
64 if err != nil {
65 return err
66 }
30 defer s.Close() 67 defer s.Close()
31 err = store.PublishCharmsDistro(s, lpad.Production) 68 err = store.PublishCharmsDistro(s, lpad.Production)
32 if _, ok := err.(store.PublishBranchErrors); ok { 69 if _, ok := err.(store.PublishBranchErrors); ok {
33 // Ignore branch errors since they're commonplace here. 70 // Ignore branch errors since they're commonplace here.
34 // They're logged, though. 71 // They're logged, though.
35 return nil 72 return nil
36 } 73 }
37 return err 74 return err
38 } 75 }
OLDNEW
« no previous file with comments | « store/charmload/config.yaml ('k') | store/server.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b