RunApp creates and starts the application using the component-based architecture.
(ctx context.Context, client *api.Client, cfg *config.Config, configPath string, initialGroup string)
| 15 | |
| 16 | // RunApp creates and starts the application using the component-based architecture. |
| 17 | func RunApp(ctx context.Context, client *api.Client, cfg *config.Config, configPath string, initialGroup string) error { |
| 18 | app := components.NewApp(ctx, client, cfg, configPath, initialGroup) |
| 19 | |
| 20 | metadata := plugins.AvailableMetadata() |
| 21 | catalog := make([]components.PluginInfo, len(metadata)) |
| 22 | for i, entry := range metadata { |
| 23 | catalog[i] = components.PluginInfo{ |
| 24 | ID: entry.ID, |
| 25 | Name: entry.Name, |
| 26 | Description: entry.Description, |
| 27 | } |
| 28 | } |
| 29 | app.SetPluginCatalog(catalog) |
| 30 | |
| 31 | pluginInstances, missing := plugins.EnabledFromConfig(cfg) |
| 32 | if len(missing) > 0 { |
| 33 | fmt.Println(display.IconText("⚠️", fmt.Sprintf("Unknown plugins requested: %s", strings.Join(missing, ", ")), cfg.ShowIcons)) |
| 34 | } |
| 35 | |
| 36 | if err := app.InitializePlugins(ctx, pluginInstances); err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | defer func() { |
| 41 | shutdownCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| 42 | defer cancel() |
| 43 | if err := app.ShutdownPlugins(shutdownCtx); err != nil { |
| 44 | fmt.Println(display.IconText("⚠️", fmt.Sprintf("Failed to shutdown plugins: %v", err), cfg.ShowIcons)) |
| 45 | } |
| 46 | }() |
| 47 | |
| 48 | return app.Run() |
| 49 | } |
no test coverage detected