-
Notifications
You must be signed in to change notification settings - Fork 221
/
show.go
52 lines (38 loc) · 1.08 KB
/
show.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
50
51
52
package volumes
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/render"
)
func newShow() (cmd *cobra.Command) {
const (
long = `Show details of an app's volume. Requires the volume's ID
number to operate. This can be found through the volumes list command`
short = "Show details of an app's volume"
)
cmd = command.New("show <id>", short, long, runShow,
command.RequireSession,
)
cmd.Args = cobra.ExactArgs(1)
return
}
func runShow(ctx context.Context) error {
cfg := config.FromContext(ctx)
client := client.FromContext(ctx).API()
volumeID := flag.FirstArg(ctx)
volume, err := client.GetVolume(ctx, volumeID)
if err != nil {
return fmt.Errorf("failed retrieving volume: %w", err)
}
out := iostreams.FromContext(ctx).Out
if cfg.JSONOutput {
return render.JSON(out, volume)
}
return printVolume(out, volume)
}