v2.7.1 b3a38c8

local.go RawHistoryFolder

1// Package cli implements the CLI adapter for Gordon.
2package cli
3
4import (
5	"context"
6	"fmt"
7	"path/filepath"
8
9	"github.com/bnema/zerowrap"
10	"github.com/spf13/viper"
11
12	"gordon/internal/adapters/out/domainsecrets"
13	"gordon/internal/app"
14	"gordon/internal/boundaries/in"
15	"gordon/internal/usecase/config"
16	secretsSvc "gordon/internal/usecase/secrets"
17)
18
19// LocalServices provides direct access to local services for CLI operations.
20type LocalServices struct {
21	configSvc in.ConfigService
22	secretSvc in.SecretService
23	dataDir   string
24}
25
26// GetConfigService returns the config service.
27func (l *LocalServices) GetConfigService() in.ConfigService {
28	return l.configSvc
29}
30
31// GetSecretService returns the secret service.
32func (l *LocalServices) GetSecretService() in.SecretService {
33	return l.secretSvc
34}
35
36// GetDataDir returns the data directory.
37func (l *LocalServices) GetDataDir() string {
38	return l.dataDir
39}
40
41// GetLocalServices creates local services for CLI operations.
42// It loads the config and initializes services without starting the server.
43func GetLocalServices(configPath string) (*LocalServices, error) {
44	// Set up viper with defaults
45	v := viper.New()
46	v.SetDefault("server.port", 80)
47	v.SetDefault("server.registry_port", 5000)
48	v.SetDefault("server.data_dir", app.DefaultDataDir())
49
50	// Configure viper with config file paths
51	app.ConfigureViper(v, configPath)
52
53	// Read config file
54	if err := v.ReadInConfig(); err != nil {
55		if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
56			return nil, fmt.Errorf("failed to read config file: %w", err)
57		}
58		// Config file not found is OK for some operations
59	}
60
61	// Create a minimal logger for CLI operations
62	log := zerowrap.New(zerowrap.Config{
63		Level:  "warn",
64		Format: "console",
65	})
66
67	// Create config service (without event bus for CLI operations)
68	configSvc := config.NewService(v, nil)
69	ctx := context.Background()
70	if err := configSvc.Load(ctx); err != nil {
71		return nil, fmt.Errorf("failed to load configuration: %w", err)
72	}
73
74	// Determine data directory and env directory
75	dataDir := v.GetString("server.data_dir")
76	if dataDir == "" {
77		dataDir = app.DefaultDataDir()
78	}
79
80	envDir := v.GetString("env.dir")
81	if envDir == "" {
82		envDir = filepath.Join(dataDir, "env")
83	}
84
85	// Create domain secret store and service
86	domainSecretStore, err := domainsecrets.NewFileStore(envDir, log)
87	if err != nil {
88		return nil, fmt.Errorf("failed to create domain secret store: %w", err)
89	}
90	secretSvc := secretsSvc.NewService(domainSecretStore, log)
91
92	return &LocalServices{
93		configSvc: configSvc,
94		secretSvc: secretSvc,
95		dataDir:   dataDir,
96	}, nil
97}

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