forked from juju/juju
/
k8s-spec-get.go
49 lines (41 loc) · 1.01 KB
/
k8s-spec-get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2019 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuc
import (
"fmt"
"github.com/juju/cmd/v3"
"github.com/juju/errors"
jujucmd "github.com/DavinZhang/juju/cmd"
)
// K8sSpecGetCommand implements the k8s-spec-get command.
type K8sSpecGetCommand struct {
cmd.CommandBase
name string
ctx Context
}
// NewK8sSpecGetCommand makes a k8s-spec-get command.
func NewK8sSpecGetCommand(ctx Context, name string) (cmd.Command, error) {
return &K8sSpecGetCommand{ctx: ctx, name: name}, nil
}
func (c *K8sSpecGetCommand) Info() *cmd.Info {
doc := `
Gets configuration data used to set up k8s resources.
`
purpose := "get k8s spec information"
if c.name == "pod-spec-get" {
purpose += " (deprecated)"
}
return jujucmd.Info(&cmd.Info{
Name: c.name,
Purpose: purpose,
Doc: doc,
})
}
func (c *K8sSpecGetCommand) Run(ctx *cmd.Context) error {
spec, err := c.ctx.GetPodSpec()
if err != nil {
return errors.Trace(err)
}
fmt.Fprint(ctx.Stdout, spec)
return nil
}