Skip to content

Commit 8e65564

Browse files
authored
refactor: add dynamic env config schema generation (#2237)
1 parent 454ffc9 commit 8e65564

File tree

5 files changed

+892
-0
lines changed

5 files changed

+892
-0
lines changed

Justfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ deploy scope kind *args:
210210
proto-backend:
211211
cd {{ edge_proto_dir }} && go run github.com/bufbuild/buf/cmd/buf@v1.65.0 generate
212212

213+
# Generate the docs config schema JSON.
214+
[group('docs')]
215+
_docs-config output="" source_root=".":
216+
#!/usr/bin/env bash
217+
set -euo pipefail
218+
219+
cmd=(go run -tags exclude_frontend ./backend/cmd config-schema --source-root "{{ source_root }}")
220+
if [ -n "{{ output }}" ]; then
221+
cmd+=(--output "{{ output }}")
222+
fi
223+
224+
"${cmd[@]}"
225+
226+
# Docs targets. Example: just docs config
227+
[group('docs')]
228+
docs target *args:
229+
@just "_docs-{{ target }}" {{ args }}
230+
213231
# Benchmark edge tunnel transport performance (gRPC vs WebSocket) with allocations.
214232

215233
# Usage: just bench-edge-tunnel [count] [benchtime]

backend/cli/config_schema.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/getarcaneapp/arcane/backend/internal/configschema"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var configSchemaCmd = &cobra.Command{
12+
Use: "config-schema",
13+
Short: "Export the config/settings schema for docs",
14+
Long: "Export the canonical JSON schema for runtime config and settings environment overrides",
15+
Run: func(cmd *cobra.Command, args []string) {
16+
outputFile, err := cmd.Flags().GetString("output")
17+
if err != nil {
18+
fmt.Fprintf(os.Stderr, "Error reading --output flag: %v\n", err)
19+
os.Exit(1)
20+
}
21+
22+
sourceRoot, err := cmd.Flags().GetString("source-root")
23+
if err != nil {
24+
fmt.Fprintf(os.Stderr, "Error reading --source-root flag: %v\n", err)
25+
os.Exit(1)
26+
}
27+
28+
doc, err := configschema.GenerateWithSourceRoot(sourceRoot)
29+
if err != nil {
30+
fmt.Fprintf(os.Stderr, "Error generating config schema: %v\n", err)
31+
os.Exit(1)
32+
}
33+
34+
output, err := configschema.MarshalJSON(doc)
35+
if err != nil {
36+
fmt.Fprintf(os.Stderr, "Error encoding config schema: %v\n", err)
37+
os.Exit(1)
38+
}
39+
40+
if outputFile != "" {
41+
if err := os.WriteFile(outputFile, output, 0o600); err != nil {
42+
fmt.Fprintf(os.Stderr, "Error writing file: %v\n", err)
43+
os.Exit(1)
44+
}
45+
fmt.Fprintf(os.Stderr, "Config schema written to %s\n", outputFile)
46+
return
47+
}
48+
49+
fmt.Print(string(output))
50+
},
51+
}
52+
53+
func init() {
54+
configSchemaCmd.Flags().StringP("output", "o", "", "Output file (default: stdout)")
55+
configSchemaCmd.Flags().String("source-root", "", "Repository root or backend source root (default: auto-detect from working directory)")
56+
rootCmd.AddCommand(configSchemaCmd)
57+
}

0 commit comments

Comments
 (0)