@@ -7,15 +7,18 @@ import (
7
7
"context"
8
8
"fmt"
9
9
"os"
10
+ "sort"
10
11
11
12
"github.com/openfaas/faas-cli/proxy"
12
13
"github.com/openfaas/faas-cli/stack"
14
+ "github.com/openfaas/faas-provider/types"
13
15
"github.com/spf13/cobra"
14
16
)
15
17
16
18
var (
17
19
verboseList bool
18
20
token string
21
+ sortOrder string
19
22
)
20
23
21
24
func init () {
@@ -28,6 +31,7 @@ func init() {
28
31
listCmd .Flags ().BoolVar (& tlsInsecure , "tls-no-verify" , false , "Disable TLS validation" )
29
32
listCmd .Flags ().BoolVar (& envsubst , "envsubst" , true , "Substitute environment variables in stack.yml file" )
30
33
listCmd .Flags ().StringVarP (& token , "token" , "k" , "" , "Pass a JWT token to use instead of basic auth" )
34
+ listCmd .Flags ().StringVar (& sortOrder , "sort" , "name" , "Sort the functions by \" name\" or \" invocations\" " )
31
35
32
36
faasCmd .AddCommand (listCmd )
33
37
}
@@ -74,6 +78,12 @@ func runList(cmd *cobra.Command, args []string) error {
74
78
return err
75
79
}
76
80
81
+ if sortOrder == "name" {
82
+ sort .Sort (byName (functions ))
83
+ } else if sortOrder == "invocations" {
84
+ sort .Sort (byInvocations (functions ))
85
+ }
86
+
77
87
if quiet {
78
88
for _ , function := range functions {
79
89
fmt .Printf ("%s\n " , function .Name )
@@ -103,3 +113,15 @@ func runList(cmd *cobra.Command, args []string) error {
103
113
}
104
114
return nil
105
115
}
116
+
117
+ type byName []types.FunctionStatus
118
+
119
+ func (a byName ) Len () int { return len (a ) }
120
+ func (a byName ) Swap (i , j int ) { a [i ], a [j ] = a [j ], a [i ] }
121
+ func (a byName ) Less (i , j int ) bool { return a [i ].Name < a [j ].Name }
122
+
123
+ type byInvocations []types.FunctionStatus
124
+
125
+ func (a byInvocations ) Len () int { return len (a ) }
126
+ func (a byInvocations ) Swap (i , j int ) { a [i ], a [j ] = a [j ], a [i ] }
127
+ func (a byInvocations ) Less (i , j int ) bool { return a [i ].InvocationCount > a [j ].InvocationCount }
0 commit comments