~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/action/common.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package action
5
5
 
6
6
import (
7
 
        "github.com/juju/cmd"
8
7
        "github.com/juju/errors"
9
8
        "github.com/juju/loggo"
10
9
        "github.com/juju/names"
11
 
        "gopkg.in/yaml.v2"
12
10
 
13
11
        "github.com/juju/juju/apiserver/params"
14
12
)
15
13
 
16
14
var logger = loggo.GetLogger("juju.cmd.juju.action")
17
15
 
18
 
// displayActionResult returns any error from an ActionResult and displays
19
 
// its response values otherwise.
20
 
func displayActionResult(result params.ActionResult, ctx *cmd.Context, out cmd.Output) error {
21
 
        if result.Error != nil {
22
 
                return result.Error
23
 
        }
24
 
 
25
 
        if result.Action == nil {
26
 
                return errors.New("action for result was nil")
27
 
        }
28
 
 
29
 
        output, err := yaml.Marshal(result.Output)
30
 
        if err != nil {
31
 
                return err
32
 
        }
33
 
 
34
 
        response := struct {
35
 
                Action  string
36
 
                Target  string
37
 
                Status  string
38
 
                Message string
39
 
                Results string
40
 
        }{
41
 
                Action:  result.Action.Name,
42
 
                Target:  result.Action.Receiver,
43
 
                Status:  result.Status,
44
 
                Message: result.Message,
45
 
                Results: string(output),
46
 
        }
47
 
 
48
 
        err = out.Write(ctx, response)
49
 
        if err != nil {
50
 
                return err
51
 
        }
52
 
 
53
 
        return nil
54
 
}
55
 
 
56
16
// getActionTagByPrefix uses the APIClient to get all ActionTags matching a prefix.
57
17
func getActionTagsByPrefix(api APIClient, prefix string) ([]names.ActionTag, error) {
58
18
        results := []names.ActionTag{}