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

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

Issue 13648044: api/uniter: ReadSettings to use params.Settings (Closed)
Patch Set: Created 11 years, 7 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/apiuniter/jujuc/relation-list_test.go ('k') | worker/apiuniter/jujuc/relation-set_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: worker/apiuniter/jujuc/relation-set.go
=== added file 'worker/apiuniter/jujuc/relation-set.go'
--- worker/apiuniter/jujuc/relation-set.go 1970-01-01 00:00:00 +0000
+++ worker/apiuniter/jujuc/relation-set.go 2013-09-10 12:21:02 +0000
@@ -0,0 +1,72 @@
+// Copyright 2012, 2013 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package jujuc
+
+import (
+ "fmt"
+ "strings"
+
+ "launchpad.net/gnuflag"
+
+ "launchpad.net/juju-core/cmd"
+)
+
+// RelationSetCommand implements the relation-set command.
+type RelationSetCommand struct {
+ cmd.CommandBase
+ ctx Context
+ RelationId int
+ Settings map[string]string
+ formatFlag string // deprecated
+}
+
+func NewRelationSetCommand(ctx Context) cmd.Command {
+ return &RelationSetCommand{ctx: ctx, Settings: map[string]string{}}
+}
+
+func (c *RelationSetCommand) Info() *cmd.Info {
+ return &cmd.Info{
+ Name: "relation-set",
+ Args: "key=value [key=value ...]",
+ Purpose: "set relation settings",
+ }
+}
+
+func (c *RelationSetCommand) SetFlags(f *gnuflag.FlagSet) {
+ f.Var(newRelationIdValue(c.ctx, &c.RelationId), "r", "specify a relation by id")
+ f.StringVar(&c.formatFlag, "format", "", "deprecated format flag")
+}
+
+func (c *RelationSetCommand) Init(args []string) error {
+ if c.RelationId == -1 {
+ return fmt.Errorf("no relation id specified")
+ }
+ for _, kv := range args {
+ parts := strings.SplitN(kv, "=", 2)
+ if len(parts) != 2 || len(parts[0]) == 0 {
+ return fmt.Errorf(`expected "key=value", got %q`, kv)
+ }
+ c.Settings[parts[0]] = parts[1]
+ }
+ return nil
+}
+
+func (c *RelationSetCommand) Run(ctx *cmd.Context) (err error) {
+ if c.formatFlag != "" {
+ fmt.Fprintf(ctx.Stderr, "--format flag deprecated for command %q", c.Info().Name)
+ }
+ 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 != "" {
+ settings.Set(k, v)
+ } else {
+ settings.Delete(k)
+ }
+ }
+ return nil
+}
« no previous file with comments | « worker/apiuniter/jujuc/relation-list_test.go ('k') | worker/apiuniter/jujuc/relation-set_test.go » ('j') | no next file with comments »

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