@@ -33,12 +33,27 @@ func RunFunc(command string, args ...string) (string, error) {
3333 return Run (cmd )
3434}
3535
36+ // RunFuncWithVersion executes the func CLI with a specific version
37+ // It downloads and caches the version if not already present
38+ func RunFuncWithVersion (version string , command string , args ... string ) (string , error ) {
39+ funcBinary , err := ensureFuncVersion (version )
40+ if err != nil {
41+ return "" , err
42+ }
43+
44+ allArgs := append ([]string {command }, args ... )
45+ cmd := exec .Command (funcBinary , allArgs ... )
46+ return Run (cmd )
47+ }
48+
3649// RunFuncDeploy runs func deploy
3750func RunFuncDeploy (functionDir string , optFns ... FuncDeployOption ) (string , error ) {
3851 opts := & FuncDeployOptions {
3952 // defaults
4053 Registry : Registry (),
4154 RegistryInsecure : IsRegistryInsecure (),
55+ Builder : os .Getenv ("DEFAULT_BUILDER" ),
56+ Deployer : os .Getenv ("DEFAULT_DEPLOYER" ),
4257 }
4358
4459 for _ , optFn := range optFns {
@@ -63,20 +78,11 @@ func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, erro
6378 args = append (args , "--deployer" , opts .Deployer )
6479 }
6580
66- return RunFunc ("deploy" , args ... )
67- }
68-
69- // RunFuncWithVersion executes the func CLI with a specific version
70- // It downloads and caches the version if not already present
71- func RunFuncWithVersion (version string , command string , args ... string ) (string , error ) {
72- funcBinary , err := ensureFuncVersion (version )
73- if err != nil {
74- return "" , err
81+ if opts .CliVersion != "" {
82+ return RunFuncWithVersion (opts .CliVersion , "deploy" , args ... )
7583 }
7684
77- allArgs := append ([]string {command }, args ... )
78- cmd := exec .Command (funcBinary , allArgs ... )
79- return Run (cmd )
85+ return RunFunc ("deploy" , args ... )
8086}
8187
8288type FuncDeployOptions struct {
@@ -85,6 +91,7 @@ type FuncDeployOptions struct {
8591 Namespace string
8692 Builder string
8793 Deployer string
94+ CliVersion string
8895}
8996
9097type FuncDeployOption func (* FuncDeployOptions )
@@ -107,6 +114,12 @@ func WithDeployer(deployer string) FuncDeployOption {
107114 }
108115}
109116
117+ func WithDeployCliVersion (version string ) FuncDeployOption {
118+ return func (opts * FuncDeployOptions ) {
119+ opts .CliVersion = version
120+ }
121+ }
122+
110123// ensureFuncVersion ensures the specified func version is available and returns its path
111124func ensureFuncVersion (version string ) (string , error ) {
112125 projectDir , err := GetProjectDir ()
0 commit comments