MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / handleSetupAndServerCommands

Function handleSetupAndServerCommands

internal/cli/setup_server.go:18–57  ·  view source on GitHub ↗

handleSetupAndServerCommands runs the setup and server commands. It returns handled = true when a command ran and the caller must exit.

(currentFlags *Flags, registry *core.PluginRegistry, version string)

Source from the content-addressed store, hash-verified

16// handleSetupAndServerCommands runs the setup and server commands.
17// It returns handled = true when a command ran and the caller must exit.
18func handleSetupAndServerCommands(currentFlags *Flags, registry *core.PluginRegistry, version string) (handled bool, err error) {
19 if currentFlags.Setup {
20 err = registry.Setup()
21 return true, err
22 }
23
24 // The server handlers do not see the parsed flags. Put the yt-dlp
25 // arguments on the plugin so the /youtube/transcript endpoint uses them.
26 registry.YouTube.YtDlpArgs = currentFlags.YtDlpArgs
27
28 // The flags are parsed before initializeFabric loads
29 // ~/.config/fabric/.env. Read the server variables again, so that
30 // file can set them. A flag or a shell variable is already set and wins.
31 if currentFlags.ServeAPIKey == "" {
32 currentFlags.ServeAPIKey = os.Getenv("FABRIC_API_KEY")
33 }
34 if v := os.Getenv("FABRIC_CORS_ORIGINS"); len(currentFlags.ServeCORSOrigins) == 0 && v != "" {
35 currentFlags.ServeCORSOrigins = strings.Split(v, ",")
36 }
37
38 // Show a warning when the API key is on the command line. Other local
39 // users can see command-line arguments in the process list.
40 if (currentFlags.Serve || currentFlags.ServeOllama) && apiKeyPassedAsArg(os.Args[1:]) {
41 fmt.Fprintln(os.Stderr, i18n.T("server_api_key_arg_warning"))
42 }
43
44 if currentFlags.Serve {
45 registry.ConfigureVendors()
46 err = restapi.Serve(registry, currentFlags.ServeAddress, currentFlags.ServeAPIKey, currentFlags.ServeCORSOrigins)
47 return true, err
48 }
49
50 if currentFlags.ServeOllama {
51 registry.ConfigureVendors()
52 err = serveOllama(registry, currentFlags.ServeAddress, version, currentFlags.ServeAPIKey, currentFlags.ServeCORSOrigins)
53 return true, err
54 }
55
56 return false, nil
57}
58
59// apiKeyPassedAsArg reports whether the REST API key is on the command line,
60// not in the FABRIC_API_KEY environment variable or the .env file.

Calls 4

TFunction · 0.92
apiKeyPassedAsArgFunction · 0.85
ConfigureVendorsMethod · 0.80
SetupMethod · 0.65