@@ -16,10 +16,13 @@ import (
16
16
"github.com/spf13/cobra"
17
17
)
18
18
19
- var pluginRegistry string
20
- var clientOS string
21
- var clientArch string
22
- var tag string
19
+ var (
20
+ pluginRegistry string
21
+ clientOS string
22
+ clientArch string
23
+ tag string
24
+ pluginPath string
25
+ )
23
26
24
27
func init () {
25
28
pluginGetCmd := & cobra.Command {
@@ -45,7 +48,9 @@ faas-cli plugin get NAME --registry ghcr.io/openfaasltd`,
45
48
pluginGetCmd .Flags ().StringVar (& clientArch , "arch" , "" , "The architecture to pull the plugin for, give a value or leave blank for auto-detection" )
46
49
pluginGetCmd .Flags ().StringVar (& clientOS , "os" , "" , "The OS to pull the plugin for, give a value or leave blank for auto-detection" )
47
50
pluginGetCmd .Flags ().StringVar (& tag , "version" , "latest" , "Version or SHA for plugin" )
48
- pluginGetCmd .Flags ().BoolVar (& verbose , "verbose" , false , "Verbose output" )
51
+ pluginGetCmd .Flags ().StringVar (& pluginPath , "path" , "$HOME/.openfaas/plugins" , "The path for the plugin" )
52
+
53
+ pluginGetCmd .Flags ().BoolVarP (& verbose , "verbose" , "v" , false , "Verbose output" )
49
54
50
55
pluginCmd .AddCommand (pluginGetCmd )
51
56
}
@@ -81,10 +86,17 @@ func runPluginGetCmd(cmd *cobra.Command, args []string) error {
81
86
}
82
87
83
88
var pluginDir string
84
- if runtime .GOOS == "windows" {
85
- pluginDir = os .Expand ("$HOMEPATH/.openfaas/plugins" , os .Getenv )
89
+
90
+ if cmd .Flags ().Changed ("path" ) {
91
+ pluginPath = strings .ReplaceAll (pluginPath , "$HOME" , os .Getenv ("HOME" ))
92
+
93
+ pluginDir = pluginPath
86
94
} else {
87
- pluginDir = os .ExpandEnv ("$HOME/.openfaas/plugins" )
95
+ if runtime .GOOS == "windows" {
96
+ pluginDir = os .Expand ("$HOMEPATH/.openfaas/plugins" , os .Getenv )
97
+ } else {
98
+ pluginDir = os .ExpandEnv ("$HOME/.openfaas/plugins" )
99
+ }
88
100
}
89
101
90
102
if _ , err := os .Stat (pluginDir ); os .IsNotExist (err ) {
@@ -121,6 +133,7 @@ func runPluginGetCmd(cmd *cobra.Command, args []string) error {
121
133
if err != nil {
122
134
return fmt .Errorf ("failed to open %s: %w" , tmpTar , err )
123
135
}
136
+
124
137
defer tarFile .Close ()
125
138
126
139
if verbose {
@@ -143,7 +156,11 @@ func runPluginGetCmd(cmd *cobra.Command, args []string) error {
143
156
}
144
157
}
145
158
146
- fmt .Printf ("Downloaded in (%ds)\n \n Usage:\n faas-cli %s\n " , int (time .Since (st ).Seconds ()), pluginName )
159
+ if cmd .Flags ().Changed ("path" ) {
160
+ fmt .Printf ("Wrote: %s (%s/%s) in (%s)\n " , path .Join (pluginPath , pluginName ), clientOS , clientArch , time .Since (st ).Round (time .Millisecond ))
161
+ } else {
162
+ fmt .Printf ("Downloaded in (%s)\n \n Usage:\n faas-cli %s\n " , time .Since (st ).Round (time .Millisecond ), pluginName )
163
+ }
147
164
return nil
148
165
}
149
166
0 commit comments