MCPcopy Create free account
hub / github.com/diillson/chatcli / runDaemonSubcommand

Function runDaemonSubcommand

main.go:314–354  ·  view source on GitHub ↗

runDaemonSubcommand handles the "daemon" subcommand. Standalone because the scheduler daemon does not need an LLMManager (it doesn't run agent tasks until a CLI attaches and delegates a bridge).

(args []string)

Source from the content-addressed store, hash-verified

312// because the scheduler daemon does not need an LLMManager (it doesn't
313// run agent tasks until a CLI attaches and delegates a bridge).
314func runDaemonSubcommand(args []string) {
315 i18n.Init()
316
317 envFilePath := os.Getenv("CHATCLI_DOTENV")
318 if envFilePath == "" {
319 envFilePath = ".env"
320 } else if expanded, err := utils.ExpandPath(envFilePath); err == nil {
321 envFilePath = expanded
322 }
323 _ = godotenv.Load(envFilePath)
324 theme.InitFromEnv()
325
326 logger, err := utils.InitializeLogger()
327 if err != nil {
328 fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err)
329 os.Exit(1)
330 }
331 defer func() {
332 if err := logger.Sync(); err != nil {
333 msg := err.Error()
334 if !strings.Contains(msg, "/dev/stdout") &&
335 !strings.Contains(msg, "/dev/stderr") &&
336 !strings.Contains(msg, "invalid argument") &&
337 !strings.Contains(msg, "inappropriate ioctl") {
338 fmt.Fprintf(os.Stderr, "Error closing logger: %v\n", err)
339 }
340 }
341 }()
342
343 config.InitGlobal(logger)
344 config.Global.Load()
345 utils.ApplyGlobalTLSTrust(logger)
346
347 ctx, cancel := context.WithCancel(context.Background())
348 defer cancel()
349
350 if err := cmd.RunDaemon(ctx, args, logger); err != nil {
351 fmt.Fprintf(os.Stderr, "Error: %v\n", err)
352 os.Exit(1)
353 }
354}

Callers 1

dispatchSubcommandFunction · 0.85

Calls 10

InitFunction · 0.92
ExpandPathFunction · 0.92
InitFromEnvFunction · 0.92
InitializeLoggerFunction · 0.92
InitGlobalFunction · 0.92
ApplyGlobalTLSTrustFunction · 0.92
RunDaemonFunction · 0.92
SyncMethod · 0.80
ErrorMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected