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

Unified Diff: worker/uniter/jujuc/relation-set.go

Issue 6633043: jujuc: switch commands to use Context
Patch Set: jujuc: switch commands to use Context Created 12 years, 5 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « worker/uniter/jujuc/relation-list.go ('k') | worker/uniter/jujuc/unit-get.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: worker/uniter/jujuc/relation-set.go
=== modified file 'worker/uniter/jujuc/relation-set.go'
--- worker/uniter/jujuc/relation-set.go 2012-10-04 14:51:32 +0000
+++ worker/uniter/jujuc/relation-set.go 2012-10-09 20:41:26 +0000
@@ -9,13 +9,13 @@
// RelationSetCommand implements the relation-set command.
type RelationSetCommand struct {
- *HookContext
+ ctx Context
RelationId int
Settings map[string]string
}
-func NewRelationSetCommand(ctx *HookContext) (cmd.Command, error) {
- return &RelationSetCommand{HookContext: ctx, Settings: map[string]string{}}, nil
+func NewRelationSetCommand(ctx Context) cmd.Command {
+ return &RelationSetCommand{ctx: ctx, Settings: map[string]string{}}
}
func (c *RelationSetCommand) Info() *cmd.Info {
@@ -25,7 +25,7 @@
}
func (c *RelationSetCommand) Init(f *gnuflag.FlagSet, args []string) error {
- f.Var(c.relationIdValue(&c.RelationId), "r", "specify a relation by id")
+ f.Var(newRelationIdValue(c.ctx, &c.RelationId), "r", "specify a relation by id")
if err := f.Parse(true, args); err != nil {
return err
}
@@ -47,12 +47,16 @@
}
func (c *RelationSetCommand) Run(ctx *cmd.Context) (err error) {
- node, err := c.Relations[c.RelationId].Settings()
+ r, found := c.ctx.Relation(c.RelationId)
+ if !found {
+ return fmt.Errorf("unknown relation id")
+ }
+ settings, err := r.Settings()
for k, v := range c.Settings {
if v != "" {
- node.Set(k, v)
+ settings.Set(k, v)
} else {
- node.Delete(k)
+ settings.Delete(k)
}
}
return nil
« no previous file with comments | « worker/uniter/jujuc/relation-list.go ('k') | worker/uniter/jujuc/unit-get.go » ('j') | no next file with comments »

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