@@ -26,6 +26,7 @@ import (
26
26
"github.com/ugol/jr/pkg/functions"
27
27
"os"
28
28
"os/exec"
29
+ "slices"
29
30
"strings"
30
31
)
31
32
@@ -57,17 +58,21 @@ func doList(cmd *cobra.Command, args []string) {
57
58
noColor , _ := cmd .Flags ().GetBool ("nocolor" )
58
59
59
60
if category && len (args ) > 0 {
61
+ var functionNames []string
60
62
for k , v := range functions .DescriptionMap () {
61
63
if strings .Contains (v .Category , args [0 ]) {
62
- printFunction ( k , isMarkdown , noColor )
64
+ functionNames = append ( functionNames , k )
63
65
}
64
66
}
67
+ sortAndPrint (functionNames , isMarkdown , noColor )
65
68
} else if find && len (args ) > 0 {
69
+ var functionNames []string
66
70
for k , v := range functions .DescriptionMap () {
67
71
if strings .Contains (v .Description , args [0 ]) || strings .Contains (v .Name , args [0 ]) {
68
- printFunction ( k , isMarkdown , noColor )
72
+ functionNames = append ( functionNames , k )
69
73
}
70
74
}
75
+ sortAndPrint (functionNames , isMarkdown , noColor )
71
76
} else if len (args ) == 1 {
72
77
73
78
if run {
@@ -83,15 +88,30 @@ func doList(cmd *cobra.Command, args []string) {
83
88
printFunction (args [0 ], isMarkdown , noColor )
84
89
}
85
90
} else {
86
- count := 0
87
- for k := range functions .FunctionsMap () {
88
- count ++
89
- printFunction (k , isMarkdown , noColor )
91
+
92
+ //l := len(functions.FunctionsMap())
93
+ l := len (functions .DescriptionMap ())
94
+ functionNames := make ([]string , l )
95
+
96
+ i := 0
97
+ for k := range functions .DescriptionMap () {
98
+ functionNames [i ] = k
99
+ i ++
90
100
}
91
- fmt .Println ()
92
- fmt .Printf ("Total functions: %d\n " , count )
101
+ sortAndPrint (functionNames , isMarkdown , noColor )
102
+
103
+ }
104
+ fmt .Println ()
105
+ }
106
+
107
+ func sortAndPrint (functionNames []string , isMarkdown bool , noColor bool ) {
108
+ slices .Sort (functionNames )
109
+ for _ , k := range functionNames {
110
+ printFunction (k , isMarkdown , noColor )
111
+ //fmt.Println(k)
93
112
}
94
113
fmt .Println ()
114
+ fmt .Printf ("Total functions: %d\n " , len (functionNames ))
95
115
}
96
116
97
117
func printFunction (name string , isMarkdown bool , noColor bool ) (functions.FunctionDescription , bool ) {
@@ -104,21 +124,8 @@ func printFunction(name string, isMarkdown bool, noColor bool) (functions.Functi
104
124
Reset = "\033 [0m"
105
125
}
106
126
107
- if ! isMarkdown {
108
-
109
- if found {
110
- fmt .Println ()
111
- fmt .Printf ("%sName: %s%s\n " , Cyan , Reset , f .Name )
112
- fmt .Printf ("%sCategory: %s%s\n " , Cyan , Reset , f .Category )
113
- fmt .Printf ("%sDescription: %s%s\n " , Cyan , Reset , f .Description )
114
- fmt .Printf ("%sParameters: %s%s\n " , Cyan , Reset , f .Parameters )
115
- fmt .Printf ("%sLocalizable: %s%v\n " , Cyan , Reset , f .Localizable )
116
- fmt .Printf ("%sReturn: %s%s\n " , Cyan , Reset , f .Return )
117
- fmt .Printf ("%sExample: %s%s\n " , Cyan , Reset , f .Example )
118
- fmt .Printf ("%sOutput: %s%s\n " , Cyan , Reset , f .Output )
119
- }
120
- } else {
121
- if found {
127
+ if found {
128
+ if isMarkdown {
122
129
fmt .Println ()
123
130
fmt .Printf ("## Name: %s \n " , f .Name )
124
131
fmt .Printf ("**Category:** %s\\ \n " , f .Category )
@@ -133,6 +140,16 @@ func printFunction(name string, isMarkdown bool, noColor bool) (functions.Functi
133
140
fmt .Printf ("**Return:** `%s`\\ \n " , f .Return )
134
141
fmt .Printf ("**Example:** `%s`\\ \n " , f .Example )
135
142
fmt .Printf ("**Output:** `%s`\n " , f .Output )
143
+ } else {
144
+ fmt .Println ()
145
+ fmt .Printf ("%sName: %s%s\n " , Cyan , Reset , f .Name )
146
+ fmt .Printf ("%sCategory: %s%s\n " , Cyan , Reset , f .Category )
147
+ fmt .Printf ("%sDescription: %s%s\n " , Cyan , Reset , f .Description )
148
+ fmt .Printf ("%sParameters: %s%s\n " , Cyan , Reset , f .Parameters )
149
+ fmt .Printf ("%sLocalizable: %s%v\n " , Cyan , Reset , f .Localizable )
150
+ fmt .Printf ("%sReturn: %s%s\n " , Cyan , Reset , f .Return )
151
+ fmt .Printf ("%sExample: %s%s\n " , Cyan , Reset , f .Example )
152
+ fmt .Printf ("%sOutput: %s%s\n " , Cyan , Reset , f .Output )
136
153
}
137
154
}
138
155
return f , found
0 commit comments