local.go RawHistoryFolder

1// Package cli implements the CLI adapter for Gordon.
2package cli
3
4import (
5	"context"
6	"fmt"
7	"strings"
8
9	"github.com/spf13/viper"
10
11	"github.com/bnema/gordon/internal/app"
12	"github.com/bnema/gordon/internal/boundaries/in"
13	"github.com/bnema/gordon/internal/usecase/config"
14)
15
16// LocalServices provides direct access to local services for CLI operations.
17type LocalServices struct {
18	configSvc  in.ConfigService
19	dataDir    string
20	tlsEnabled bool
21	configFile string
22}
23
24// GetConfigService returns the config service.
25func (l *LocalServices) GetConfigService() in.ConfigService {
26	return l.configSvc
27}
28
29// GetDataDir returns the data directory.
30func (l *LocalServices) GetDataDir() string {
31	return l.dataDir
32}
33
34// GetConfigFile returns the config file that was read, or "" when none was found.
35func (l *LocalServices) GetConfigFile() string {
36	return l.configFile
37}
38
39// HasInternalTLS reports whether a TLS-capable entrypoint enables the internal CA.
40func (l *LocalServices) HasInternalTLS() bool {
41	return l.tlsEnabled
42}
43
44// GetLocalServices creates local services for CLI operations.
45// It loads the config and initializes services without starting the server.
46func GetLocalServices(cliConfigPath string) (*LocalServices, error) {
47	// Set up viper with defaults
48	v := viper.New()
49	v.SetDefault("server.port", 8088)
50	v.SetDefault("server.registry_port", 5000)
51	v.SetDefault("server.data_dir", app.DefaultDataDir())
52
53	// Configure viper with config file paths
54	app.ConfigureViper(v, cliConfigPath)
55
56	// Read config file
57	if err := v.ReadInConfig(); err != nil {
58		if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
59			return nil, fmt.Errorf("failed to read config file: %w", err)
60		}
61		// Config file not found is OK for some operations
62	}
63
64	// Create config service (without event bus for CLI operations)
65	configSvc := config.NewService(v, nil)
66	ctx := context.Background()
67	if err := configSvc.Load(ctx); err != nil {
68		return nil, fmt.Errorf("failed to load configuration: %w", err)
69	}
70
71	dataDir := v.GetString("server.data_dir")
72	if dataDir == "" {
73		dataDir = app.DefaultDataDir()
74	}
75
76	return &LocalServices{
77		configSvc:  configSvc,
78		dataDir:    dataDir,
79		tlsEnabled: hasLocalTLSCapableEntrypoint(v),
80		configFile: v.ConfigFileUsed(),
81	}, nil
82}
83
84func hasLocalTLSCapableEntrypoint(v *viper.Viper) bool {
85	for _, rawEntryPoint := range v.GetStringMap("entrypoints") {
86		entryPoint, ok := rawEntryPoint.(map[string]any)
87		if !ok {
88			continue
89		}
90		switch strings.TrimSpace(fmt.Sprint(entryPoint["protocol"])) {
91		case "smart_tcp", "tls_mux":
92			return true
93		}
94	}
95	return false
96}

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 8

Tags 106

↑↓ moveenter openesc close