v3.0.0 f19f453

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}
22
23// GetConfigService returns the config service.
24func (l *LocalServices) GetConfigService() in.ConfigService {
25	return l.configSvc
26}
27
28// GetDataDir returns the data directory.
29func (l *LocalServices) GetDataDir() string {
30	return l.dataDir
31}
32
33// HasInternalTLS reports whether a TLS-capable entrypoint enables the internal CA.
34func (l *LocalServices) HasInternalTLS() bool {
35	return l.tlsEnabled
36}
37
38// GetLocalServices creates local services for CLI operations.
39// It loads the config and initializes services without starting the server.
40func GetLocalServices(cliConfigPath string) (*LocalServices, error) {
41	// Set up viper with defaults
42	v := viper.New()
43	v.SetDefault("server.port", 8088)
44	v.SetDefault("server.registry_port", 5000)
45	v.SetDefault("server.data_dir", app.DefaultDataDir())
46
47	// Configure viper with config file paths
48	app.ConfigureViper(v, cliConfigPath)
49
50	// Read config file
51	if err := v.ReadInConfig(); err != nil {
52		if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
53			return nil, fmt.Errorf("failed to read config file: %w", err)
54		}
55		// Config file not found is OK for some operations
56	}
57
58	// Create config service (without event bus for CLI operations)
59	configSvc := config.NewService(v, nil)
60	ctx := context.Background()
61	if err := configSvc.Load(ctx); err != nil {
62		return nil, fmt.Errorf("failed to load configuration: %w", err)
63	}
64
65	dataDir := v.GetString("server.data_dir")
66	if dataDir == "" {
67		dataDir = app.DefaultDataDir()
68	}
69
70	return &LocalServices{
71		configSvc:  configSvc,
72		dataDir:    dataDir,
73		tlsEnabled: hasLocalTLSCapableEntrypoint(v),
74	}, nil
75}
76
77func hasLocalTLSCapableEntrypoint(v *viper.Viper) bool {
78	for _, rawEntryPoint := range v.GetStringMap("entrypoints") {
79		entryPoint, ok := rawEntryPoint.(map[string]any)
80		if !ok {
81			continue
82		}
83		switch strings.TrimSpace(fmt.Sprint(entryPoint["protocol"])) {
84		case "smart_tcp", "tls_mux":
85			return true
86		}
87	}
88	return false
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