1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
"launchpad.net/gnuflag"
11
// OpenedPortsCommand implements the opened-ports command.
12
type OpenedPortsCommand struct {
18
func NewOpenedPortsCommand(ctx Context) (cmd.Command, error) {
19
return &OpenedPortsCommand{ctx: ctx}, nil
22
func (c *OpenedPortsCommand) Info() *cmd.Info {
23
doc := `Each list entry has format <port>/<protocol> (e.g. "80/tcp") or
24
<from>-<to>/<protocol> (e.g. "8080-8088/udp").`
27
Purpose: "lists all ports or ranges opened by the unit",
32
func (c *OpenedPortsCommand) SetFlags(f *gnuflag.FlagSet) {
33
c.out.AddFlags(f, "smart", cmd.DefaultFormatters)
36
func (c *OpenedPortsCommand) Init(args []string) error {
37
return cmd.CheckEmpty(args)
40
func (c *OpenedPortsCommand) Run(ctx *cmd.Context) error {
41
unitPorts := c.ctx.OpenedPorts()
42
results := make([]string, len(unitPorts))
43
for i, portRange := range unitPorts {
44
results[i] = portRange.String()
46
return c.out.Write(ctx, results)