v3.3.2 9697f9d

config_validate.go RawHistoryFolder

1package cli
2
3import (
4	"fmt"
5	"io"
6
7	"github.com/spf13/cobra"
8
9	"github.com/bnema/gordon/internal/app"
10)
11
12type configDiagnostic struct {
13	Code    string `json:"code"`
14	Key     string `json:"key"`
15	Message string `json:"message"`
16}
17
18type configValidationResult struct {
19	Valid       bool               `json:"valid"`
20	Diagnostics []configDiagnostic `json:"diagnostics"`
21	Scope       string             `json:"scope"`
22}
23
24func newConfigValidateCmd() *cobra.Command {
25	var file string
26	var jsonOut bool
27	cmd := &cobra.Command{
28		Use:   "validate",
29		Short: "Statically validate a local configuration file",
30		Args:  cobra.NoArgs,
31		RunE: func(cmd *cobra.Command, _ []string) error {
32			if remoteFlag != "" {
33				return fmt.Errorf("daemon config validate is local-only; --remote is not supported")
34			}
35			return runConfigValidate(cmd.OutOrStdout(), file, jsonOut)
36		},
37	}
38	cmd.Flags().StringVar(&file, "file", "", "Local candidate configuration file (required)")
39	cmd.Flags().BoolVar(&jsonOut, "json", false, "Output as JSON")
40	_ = cmd.MarkFlagRequired("file")
41	return cmd
42}
43
44func runConfigValidate(out io.Writer, file string, jsonOut bool) error {
45	result := configValidationResult{Valid: true, Diagnostics: []configDiagnostic{}, Scope: "static"}
46	if err := app.ValidateConfigFile(file); err != nil {
47		result.Valid = false
48		result.Diagnostics = []configDiagnostic{{Code: "config-invalid", Message: "configuration failed static validation"}}
49		if jsonOut {
50			if writeErr := writeJSON(out, result); writeErr != nil {
51				return writeErr
52			}
53		}
54		return fmt.Errorf("configuration failed static validation: %w", err)
55	}
56	if jsonOut {
57		return writeJSON(out, result)
58	}
59	return cliWriteLine(out, cliRenderSuccess("Configuration is statically valid; runtime, ACTIVE-state, secret, pull, and listener checks were not performed."))
60}

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