mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-02-13 07:25:10 -05:00
CHANGES - Update PrintWithVendor signature to accept default vendor and model - Mark default vendor/model with asterisk in non-shell output - Compare vendor and model case-insensitively when marking - Pass registry defaults to PrintWithVendor from CLI - Add test ensuring default selection appears with asterisk - Keep shell completion output unchanged without default markers
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package ai
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/danielmiessler/fabric/internal/util"
|
|
)
|
|
|
|
func NewVendorsModels() *VendorsModels {
|
|
return &VendorsModels{GroupsItemsSelectorString: util.NewGroupsItemsSelectorString("Available models")}
|
|
}
|
|
|
|
type VendorsModels struct {
|
|
*util.GroupsItemsSelectorString
|
|
}
|
|
|
|
// PrintWithVendor prints models including their vendor on each line.
|
|
// When shellCompleteList is true, output is suitable for shell completion.
|
|
// Default vendor and model are highlighted with an asterisk.
|
|
func (o *VendorsModels) PrintWithVendor(shellCompleteList bool, defaultVendor, defaultModel string) {
|
|
if !shellCompleteList {
|
|
fmt.Printf("\n%v:\n", o.SelectionLabel)
|
|
}
|
|
|
|
var currentItemIndex int
|
|
|
|
sortedGroups := make([]*util.GroupItems[string], len(o.GroupsItems))
|
|
copy(sortedGroups, o.GroupsItems)
|
|
sort.SliceStable(sortedGroups, func(i, j int) bool {
|
|
return strings.ToLower(sortedGroups[i].Group) < strings.ToLower(sortedGroups[j].Group)
|
|
})
|
|
|
|
for _, groupItems := range sortedGroups {
|
|
items := make([]string, len(groupItems.Items))
|
|
copy(items, groupItems.Items)
|
|
sort.SliceStable(items, func(i, j int) bool {
|
|
return strings.ToLower(items[i]) < strings.ToLower(items[j])
|
|
})
|
|
for _, item := range items {
|
|
currentItemIndex++
|
|
if shellCompleteList {
|
|
fmt.Printf("%s|%s\n", groupItems.Group, item)
|
|
} else {
|
|
mark := " "
|
|
if strings.EqualFold(groupItems.Group, defaultVendor) && strings.EqualFold(item, defaultModel) {
|
|
mark = " *"
|
|
}
|
|
fmt.Printf("%s\t[%d]\t%s|%s\n", mark, currentItemIndex, groupItems.Group, item)
|
|
}
|
|
}
|
|
}
|
|
}
|