diff --git a/fabric b/fabric new file mode 100755 index 00000000..fcb4c0f2 Binary files /dev/null and b/fabric differ diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 0dd58007..14172d77 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -32,27 +32,28 @@ func Cli(version string) (err error) { } // Handle setup and server commands - if err = handleSetupAndServerCommands(currentFlags, registry, version); err != nil { + var handled bool + if handled, err = handleSetupAndServerCommands(currentFlags, registry, version); err != nil || handled { return } // Handle configuration commands - if err = handleConfigurationCommands(currentFlags, registry); err != nil { + if handled, err = handleConfigurationCommands(currentFlags, registry); err != nil || handled { return } // Handle listing commands - if err = handleListingCommands(currentFlags, registry.Db, registry); err != nil { + if handled, err = handleListingCommands(currentFlags, registry.Db, registry); err != nil || handled { return } // Handle management commands - if err = handleManagementCommands(currentFlags, registry.Db); err != nil { + if handled, err = handleManagementCommands(currentFlags, registry.Db); err != nil || handled { return } // Handle extension commands - if err = handleExtensionCommands(currentFlags, registry); err != nil { + if handled, err = handleExtensionCommands(currentFlags, registry); err != nil || handled { return } diff --git a/internal/cli/configuration.go b/internal/cli/configuration.go index e794a8a0..6f4e696c 100644 --- a/internal/cli/configuration.go +++ b/internal/cli/configuration.go @@ -5,23 +5,24 @@ import ( ) // handleConfigurationCommands handles configuration-related commands -func handleConfigurationCommands(currentFlags *Flags, registry *core.PluginRegistry) (err error) { +// Returns (handled, error) where handled indicates if a command was processed and should exit +func handleConfigurationCommands(currentFlags *Flags, registry *core.PluginRegistry) (handled bool, err error) { if currentFlags.UpdatePatterns { if err = registry.PatternsLoader.PopulateDB(); err != nil { - return + return true, err } // Save configuration in case any paths were migrated during pattern loading err = registry.SaveEnvFile() - return + return true, err } if currentFlags.ChangeDefaultModel { if err = registry.Defaults.Setup(); err != nil { - return + return true, err } err = registry.SaveEnvFile() - return + return true, err } - return nil + return false, nil } diff --git a/internal/cli/extensions.go b/internal/cli/extensions.go index 0fd0200a..c780947c 100644 --- a/internal/cli/extensions.go +++ b/internal/cli/extensions.go @@ -5,21 +5,22 @@ import ( ) // handleExtensionCommands handles extension-related commands -func handleExtensionCommands(currentFlags *Flags, registry *core.PluginRegistry) (err error) { +// Returns (handled, error) where handled indicates if a command was processed and should exit +func handleExtensionCommands(currentFlags *Flags, registry *core.PluginRegistry) (handled bool, err error) { if currentFlags.ListExtensions { err = registry.TemplateExtensions.ListExtensions() - return + return true, err } if currentFlags.AddExtension != "" { err = registry.TemplateExtensions.RegisterExtension(currentFlags.AddExtension) - return + return true, err } if currentFlags.RemoveExtension != "" { err = registry.TemplateExtensions.RemoveExtension(currentFlags.RemoveExtension) - return + return true, err } - return nil + return false, nil } diff --git a/internal/cli/listing.go b/internal/cli/listing.go index 442516e1..ce279f5b 100644 --- a/internal/cli/listing.go +++ b/internal/cli/listing.go @@ -10,52 +10,53 @@ import ( ) // handleListingCommands handles listing-related commands -func handleListingCommands(currentFlags *Flags, fabricDb *fsdb.Db, registry *core.PluginRegistry) (err error) { +// Returns (handled, error) where handled indicates if a command was processed and should exit +func handleListingCommands(currentFlags *Flags, fabricDb *fsdb.Db, registry *core.PluginRegistry) (handled bool, err error) { if currentFlags.LatestPatterns != "0" { var parsedToInt int if parsedToInt, err = strconv.Atoi(currentFlags.LatestPatterns); err != nil { - return + return true, err } if err = fabricDb.Patterns.PrintLatestPatterns(parsedToInt); err != nil { - return + return true, err } - return + return true, nil } if currentFlags.ListPatterns { err = fabricDb.Patterns.ListNames(currentFlags.ShellCompleteOutput) - return + return true, err } if currentFlags.ListAllModels { var models *ai.VendorsModels if models, err = registry.VendorManager.GetModels(); err != nil { - return + return true, err } models.Print(currentFlags.ShellCompleteOutput) - return + return true, nil } if currentFlags.ListAllContexts { err = fabricDb.Contexts.ListNames(currentFlags.ShellCompleteOutput) - return + return true, err } if currentFlags.ListAllSessions { err = fabricDb.Sessions.ListNames(currentFlags.ShellCompleteOutput) - return + return true, err } if currentFlags.ListStrategies { err = registry.Strategies.ListStrategies(currentFlags.ShellCompleteOutput) - return + return true, err } if currentFlags.ListVendors { err = registry.ListVendors(os.Stdout) - return + return true, err } - return nil + return false, nil } diff --git a/internal/cli/management.go b/internal/cli/management.go index 5819d740..38d8612c 100644 --- a/internal/cli/management.go +++ b/internal/cli/management.go @@ -5,26 +5,27 @@ import ( ) // handleManagementCommands handles management-related commands (delete, print, etc.) -func handleManagementCommands(currentFlags *Flags, fabricDb *fsdb.Db) (err error) { +// Returns (handled, error) where handled indicates if a command was processed and should exit +func handleManagementCommands(currentFlags *Flags, fabricDb *fsdb.Db) (handled bool, err error) { if currentFlags.WipeContext != "" { err = fabricDb.Contexts.Delete(currentFlags.WipeContext) - return + return true, err } if currentFlags.WipeSession != "" { err = fabricDb.Sessions.Delete(currentFlags.WipeSession) - return + return true, err } if currentFlags.PrintSession != "" { err = fabricDb.Sessions.PrintSession(currentFlags.PrintSession) - return + return true, err } if currentFlags.PrintContext != "" { err = fabricDb.Contexts.PrintContext(currentFlags.PrintContext) - return + return true, err } - return nil + return false, nil } diff --git a/internal/cli/setup_server.go b/internal/cli/setup_server.go index d4f8388f..03831195 100644 --- a/internal/cli/setup_server.go +++ b/internal/cli/setup_server.go @@ -6,24 +6,25 @@ import ( ) // handleSetupAndServerCommands handles setup and server-related commands -func handleSetupAndServerCommands(currentFlags *Flags, registry *core.PluginRegistry, version string) (err error) { +// Returns (handled, error) where handled indicates if a command was processed and should exit +func handleSetupAndServerCommands(currentFlags *Flags, registry *core.PluginRegistry, version string) (handled bool, err error) { // if the setup flag is set, run the setup function if currentFlags.Setup { err = registry.Setup() - return + return true, err } if currentFlags.Serve { registry.ConfigureVendors() err = restapi.Serve(registry, currentFlags.ServeAddress, currentFlags.ServeAPIKey) - return + return true, err } if currentFlags.ServeOllama { registry.ConfigureVendors() err = restapi.ServeOllama(registry, currentFlags.ServeAddress, version) - return + return true, err } - return nil + return false, nil }