LEFT | RIGHT |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package main | 4 package main |
5 | 5 |
6 import ( | 6 import ( |
7 "launchpad.net/gnuflag" | 7 "launchpad.net/gnuflag" |
| 8 "launchpad.net/loggo" |
| 9 |
8 "launchpad.net/juju-core/cmd" | 10 "launchpad.net/juju-core/cmd" |
9 "launchpad.net/juju-core/environs/sync" | 11 "launchpad.net/juju-core/environs/sync" |
10 ) | 12 ) |
11 | 13 |
12 var syncTools = sync.SyncTools | 14 var syncTools = sync.SyncTools |
13 | 15 |
14 // SyncToolsCommand copies all the tools from the us-east-1 bucket to the local | 16 // SyncToolsCommand copies all the tools from the us-east-1 bucket to the local |
15 // bucket. | 17 // bucket. |
16 type SyncToolsCommand struct { | 18 type SyncToolsCommand struct { |
17 EnvCommandBase | 19 EnvCommandBase |
18 allVersions bool | 20 allVersions bool |
19 dryRun bool | 21 dryRun bool |
20 publicBucket bool | 22 publicBucket bool |
21 dev bool | 23 dev bool |
22 source string | 24 source string |
23 } | 25 } |
24 | 26 |
25 var _ cmd.Command = (*SyncToolsCommand)(nil) | 27 var _ cmd.Command = (*SyncToolsCommand)(nil) |
26 | 28 |
27 func (c *SyncToolsCommand) Info() *cmd.Info { | 29 func (c *SyncToolsCommand) Info() *cmd.Info { |
28 return &cmd.Info{ | 30 return &cmd.Info{ |
29 Name: "sync-tools", | 31 Name: "sync-tools", |
30 Purpose: "copy tools from the official bucket into a local envir
onment", | 32 Purpose: "copy tools from the official bucket into a local envir
onment", |
31 Doc: ` | 33 Doc: ` |
32 This copies the Juju tools tarball from the official bucket into | 34 This copies the Juju tools tarball from the official bucket into |
33 your environment. This is generally done when you want Juju to be able | 35 your environment. This is generally done when you want Juju to be able |
34 to run without having to access Amazon. Alternatively you can specify | 36 to run without having to access Amazon. Alternatively you can specify |
35 a local directory as source. | 37 a local directory as source. |
36 | 38 |
37 Sometimes this is because the environment does not have public access, | 39 Sometimes this is because the environment does not have public access, |
38 and sometimes you just want to avoid having to access data outside of | 40 and sometimes you just want to avoid having to access data outside of |
39 the local cloud. | 41 the local cloud. |
40 `, | 42 `, |
41 } | 43 } |
42 } | 44 } |
43 | 45 |
44 func (c *SyncToolsCommand) SetFlags(f *gnuflag.FlagSet) { | 46 func (c *SyncToolsCommand) SetFlags(f *gnuflag.FlagSet) { |
45 c.EnvCommandBase.SetFlags(f) | 47 c.EnvCommandBase.SetFlags(f) |
46 f.BoolVar(&c.allVersions, "all", false, "copy all versions, not just the
latest") | 48 f.BoolVar(&c.allVersions, "all", false, "copy all versions, not just the
latest") |
47 f.BoolVar(&c.dryRun, "dry-run", false, "don't copy, just print what woul
d be copied") | 49 f.BoolVar(&c.dryRun, "dry-run", false, "don't copy, just print what woul
d be copied") |
48 f.BoolVar(&c.dev, "dev", false, "consider development versions as well a
s released ones") | 50 f.BoolVar(&c.dev, "dev", false, "consider development versions as well a
s released ones") |
49 f.BoolVar(&c.publicBucket, "public", false, "write to the public-bucket
of the account, instead of the bucket private to the environment.") | 51 f.BoolVar(&c.publicBucket, "public", false, "write to the public-bucket
of the account, instead of the bucket private to the environment.") |
50 f.StringVar(&c.source, "source", "", "chose a location on the file syste
m as source") | 52 f.StringVar(&c.source, "source", "", "chose a location on the file syste
m as source") |
51 | 53 |
52 // BUG(lp:1163164) jam 2013-04-2 we would like to add a "source" | 54 // BUG(lp:1163164) jam 2013-04-2 we would like to add a "source" |
53 // location, rather than only copying from us-east-1 | 55 // location, rather than only copying from us-east-1 |
54 } | 56 } |
55 | 57 |
56 func (c *SyncToolsCommand) Init(args []string) error { | 58 func (c *SyncToolsCommand) Init(args []string) error { |
57 return cmd.CheckEmpty(args) | 59 return cmd.CheckEmpty(args) |
58 } | 60 } |
59 | 61 |
60 func (c *SyncToolsCommand) Run(ctx *cmd.Context) error { | 62 func (c *SyncToolsCommand) Run(ctx *cmd.Context) error { |
| 63 // Register writer for output on screen. |
| 64 loggo.RegisterWriter("synctools", sync.NewSyncLogWriter(ctx.Stdout, ctx.
Stderr), loggo.INFO) |
| 65 defer loggo.RemoveWriter("synctools") |
| 66 // Prepare syncing. |
61 sctx := &sync.SyncContext{ | 67 sctx := &sync.SyncContext{ |
62 EnvName: c.EnvName, | 68 EnvName: c.EnvName, |
63 AllVersions: c.allVersions, | 69 AllVersions: c.allVersions, |
64 DryRun: c.dryRun, | 70 DryRun: c.dryRun, |
65 PublicBucket: c.publicBucket, | 71 PublicBucket: c.publicBucket, |
66 Dev: c.dev, | 72 Dev: c.dev, |
67 Source: c.source, | 73 Source: c.source, |
68 Stdout: ctx.Stdout, | |
69 Stderr: ctx.Stderr, | |
70 } | 74 } |
71 return syncTools(sctx) | 75 return syncTools(sctx) |
72 } | 76 } |
LEFT | RIGHT |