v3.3.1 31f1eec

status.go RawHistoryFolder

1package cli
2
3import (
4	"context"
5	"fmt"
6	"io"
7	"sort"
8
9	"github.com/spf13/cobra"
10
11	"github.com/bnema/gordon/internal/adapters/in/cli/ui/components"
12	"github.com/bnema/gordon/internal/adapters/in/cli/ui/styles"
13)
14
15// newStatusCmd creates the status command.
16func newStatusCmd() *cobra.Command {
17	return &cobra.Command{
18		Use:   "status",
19		Short: "Show Gordon server status",
20		RunE: func(cmd *cobra.Command, args []string) error {
21			handle, err := resolveControlPlane(cliConfigPath)
22			if err != nil {
23				return err
24			}
25			defer handle.close()
26
27			return runStatusCmd(cmd.Context(), handle.plane, cmd.OutOrStdout())
28		},
29	}
30}
31
32func runStatusCmd(ctx context.Context, plane ControlPlane, out io.Writer) error {
33	status, err := plane.GetStatus(ctx)
34	if err != nil {
35		return fmt.Errorf("failed to get status: %w", err)
36	}
37	if status == nil {
38		return fmt.Errorf("failed to get status: empty response")
39	}
40
41	if err := cliWriteLine(out, styles.Theme.Title.Render("Gordon Status")); err != nil {
42		return err
43	}
44	if err := cliWriteLine(out, ""); err != nil {
45		return err
46	}
47
48	if err := cliWriteLine(out, fmt.Sprintf("%s %s", styles.Theme.Bold.Render("Domain:"), status.RegistryDomain)); err != nil {
49		return err
50	}
51	if err := cliWriteLine(out, fmt.Sprintf("%s %d", styles.Theme.Bold.Render("Registry Port:"), status.RegistryPort)); err != nil {
52		return err
53	}
54	if err := cliWriteLine(out, fmt.Sprintf("%s %d", styles.Theme.Bold.Render("Server Port:"), status.ServerPort)); err != nil {
55		return err
56	}
57	if err := cliWriteLine(out, fmt.Sprintf("%s %d", styles.Theme.Bold.Render("Apps:"), status.Apps)); err != nil {
58		return err
59	}
60	if err := cliWriteLine(out, fmt.Sprintf("%s %v", styles.Theme.Bold.Render("Network Isolation:"), status.NetworkIsolation)); err != nil {
61		return err
62	}
63
64	return renderStatusFleet(out, status.ContainerStatus)
65}
66
67func renderStatusFleet(out io.Writer, fleet map[string]string) error {
68	if len(fleet) == 0 {
69		return nil
70	}
71	if err := cliWriteLine(out, ""); err != nil {
72		return err
73	}
74	if err := cliWriteLine(out, styles.Theme.Bold.Render("Container Status:")); err != nil {
75		return err
76	}
77	names := make([]string, 0, len(fleet))
78	for name := range fleet {
79		names = append(names, name)
80	}
81	sort.Strings(names)
82	for _, name := range names {
83		badge := components.ContainerStatusBadge(fleet[name])
84		if err := cliWriteLine(out, fmt.Sprintf("  %s: %s", name, badge)); err != nil {
85			return err
86		}
87	}
88	return nil
89}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close