/
logs.go
48 lines (43 loc) · 1.1 KB
/
logs.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
package plural
import (
"github.com/pluralsh/plural-cli/pkg/config"
"github.com/pluralsh/plural-cli/pkg/logs"
"github.com/urfave/cli"
)
func (p *Plural) logsCommands() []cli.Command {
return []cli.Command{
{
Name: "list",
Usage: "lists log tails for a repo",
ArgsUsage: "REPO",
Action: latestVersion(initKubeconfig(requireArgs(p.handleLogsList, []string{"REPO"}))),
},
{
Name: "tail",
Usage: "execs the specific logtail",
ArgsUsage: "REPO NAME",
Action: latestVersion(initKubeconfig(requireArgs(p.handleLogTail, []string{"REPO", "NAME"}))),
},
}
}
func (p *Plural) handleLogsList(c *cli.Context) error {
repo := c.Args().Get(0)
conf := config.Read()
if err := p.InitKube(); err != nil {
return err
}
tails, err := logs.List(p.Kube, conf.Namespace(repo))
if err != nil {
return err
}
return logs.Print(tails)
}
func (p *Plural) handleLogTail(c *cli.Context) error {
repo := c.Args().Get(0)
name := c.Args().Get(1)
conf := config.Read()
if err := p.InitKube(); err != nil {
return err
}
return logs.Tail(p.Kube, conf.Namespace(repo), name)
}