File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package search
22
33import (
44 "context"
5+ "sort"
6+ "strings"
57 "time"
68
79 "github.com/buildsafedev/bsf/cmd/styles"
@@ -26,11 +28,31 @@ func (i pkgitem) FilterValue() string {
2628 return i .name
2729}
2830
29- func convLPR2Items (packages * buildsafev1.ListPackagesResponse ) []list.Item {
31+ func convLPR2Items (packages * buildsafev1.ListPackagesResponse , args ... string ) []list.Item {
3032 items := make ([]list.Item , 0 , len (packages .Packages ))
31- for _ , name := range packages .Packages {
32- items = append (items , pkgitem {name : name })
33+
34+ if len (args ) == 0 || args [0 ] == "" {
35+ return nil
36+ }
37+
38+ for _ , pkg := range packages .Packages {
39+ if strings .Contains (pkg , args [0 ]) {
40+ items = append (items , pkgitem {name : pkg })
41+ }
3342 }
43+ sort .Slice (items , func (i , j int ) bool {
44+ nameI := items [i ].(pkgitem ).name
45+ nameJ := items [j ].(pkgitem ).name
46+
47+ if strings .HasPrefix (nameI , args [0 ]) && ! strings .HasPrefix (nameJ , args [0 ]) {
48+ return true
49+ }
50+ if ! strings .HasPrefix (nameI , args [0 ]) && strings .HasPrefix (nameJ , args [0 ]) {
51+ return false
52+ }
53+
54+ return nameI < nameJ
55+ })
3456
3557 return items
3658}
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ var SearchCmd = &cobra.Command{
7373 fmt .Println (errorStyle .Render (fmt .Errorf ("error: %v" , err ).Error ()))
7474 os .Exit (1 )
7575 }
76- items := convLPR2Items (packages )
76+ items := convLPR2Items (packages , args ... )
7777 m := InitSearch (items )
7878 if _ , err := tea .NewProgram (m , tea .WithAltScreen ()).Run (); err != nil {
7979 fmt .Println (errorStyle .Render (fmt .Errorf ("error: %v" , err ).Error ()))
You can’t perform that action at this time.
0 commit comments