mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-02-12 15:05:10 -05:00
### CHANGES - Add `handled` boolean return to command handlers - Modify `handleSetupAndServerCommands` to use `handled` - Update `handleConfigurationCommands` with `handled` logic - Implement `handled` return in `handleExtensionCommands` - Revise `handleListingCommands` to support `handled` return - Adjust `handleManagementCommands` to return `handled`
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/danielmiessler/fabric/internal/core"
|
|
"github.com/danielmiessler/fabric/internal/plugins/ai"
|
|
"github.com/danielmiessler/fabric/internal/plugins/db/fsdb"
|
|
)
|
|
|
|
// handleListingCommands handles listing-related commands
|
|
// 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 true, err
|
|
}
|
|
|
|
if err = fabricDb.Patterns.PrintLatestPatterns(parsedToInt); err != nil {
|
|
return true, err
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
if currentFlags.ListPatterns {
|
|
err = fabricDb.Patterns.ListNames(currentFlags.ShellCompleteOutput)
|
|
return true, err
|
|
}
|
|
|
|
if currentFlags.ListAllModels {
|
|
var models *ai.VendorsModels
|
|
if models, err = registry.VendorManager.GetModels(); err != nil {
|
|
return true, err
|
|
}
|
|
models.Print(currentFlags.ShellCompleteOutput)
|
|
return true, nil
|
|
}
|
|
|
|
if currentFlags.ListAllContexts {
|
|
err = fabricDb.Contexts.ListNames(currentFlags.ShellCompleteOutput)
|
|
return true, err
|
|
}
|
|
|
|
if currentFlags.ListAllSessions {
|
|
err = fabricDb.Sessions.ListNames(currentFlags.ShellCompleteOutput)
|
|
return true, err
|
|
}
|
|
|
|
if currentFlags.ListStrategies {
|
|
err = registry.Strategies.ListStrategies(currentFlags.ShellCompleteOutput)
|
|
return true, err
|
|
}
|
|
|
|
if currentFlags.ListVendors {
|
|
err = registry.ListVendors(os.Stdout)
|
|
return true, err
|
|
}
|
|
|
|
return false, nil
|
|
}
|