@@ -7,43 +7,12 @@ import (
77 "github.com/ory/viper"
88 "github.com/spf13/cobra"
99
10+ "knative.dev/func/cmd/common"
1011 "knative.dev/func/pkg/config"
1112 fn "knative.dev/func/pkg/functions"
1213)
1314
14- type functionLoader interface {
15- Load (path string ) (fn.Function , error )
16- }
17-
18- type functionSaver interface {
19- Save (f fn.Function ) error
20- }
21-
22- type functionLoaderSaver interface {
23- functionLoader
24- functionSaver
25- }
26-
27- type standardLoaderSaver struct {}
28-
29- func (s standardLoaderSaver ) Load (path string ) (fn.Function , error ) {
30- f , err := fn .NewFunction (path )
31- if err != nil {
32- return fn.Function {}, fmt .Errorf ("failed to create new function (path: %q): %w" , path , err )
33- }
34- if ! f .Initialized () {
35- return fn.Function {}, fn .NewErrNotInitialized (f .Root )
36- }
37- return f , nil
38- }
39-
40- func (s standardLoaderSaver ) Save (f fn.Function ) error {
41- return f .Write ()
42- }
43-
44- var defaultLoaderSaver standardLoaderSaver
45-
46- func NewConfigCmd (loadSaver functionLoaderSaver , newClient ClientFactory ) * cobra.Command {
15+ func NewConfigCmd (loadSaver common.FunctionLoaderSaver , newClient ClientFactory ) * cobra.Command {
4716 cmd := & cobra.Command {
4817 Use : "config" ,
4918 Short : "Configure a function" ,
@@ -75,7 +44,7 @@ or from the directory specified with --path.
7544
7645func runConfigCmd (cmd * cobra.Command , args []string ) (err error ) {
7746
78- function , err := initConfigCommand (defaultLoaderSaver )
47+ function , err := initConfigCommand (common . DefaultLoaderSaver )
7948 if err != nil {
8049 return
8150 }
@@ -117,7 +86,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) (err error) {
11786 case "Environment variables" :
11887 err = runAddEnvsPrompt (cmd .Context (), function )
11988 case "Labels" :
120- err = runAddLabelsPrompt (cmd .Context (), function , defaultLoaderSaver )
89+ err = runAddLabelsPrompt (cmd .Context (), function , common . DefaultLoaderSaver )
12190 case "Git" :
12291 err = runConfigGitSetCmd (cmd , NewClient )
12392 }
@@ -128,7 +97,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) (err error) {
12897 case "Environment variables" :
12998 err = runRemoveEnvsPrompt (function )
13099 case "Labels" :
131- err = runRemoveLabelsPrompt (function , defaultLoaderSaver )
100+ err = runRemoveLabelsPrompt (function , common . DefaultLoaderSaver )
132101 case "Git" :
133102 err = runConfigGitRemoveCmd (cmd , NewClient )
134103 }
@@ -163,7 +132,7 @@ func newConfigCmdConfig() configCmdConfig {
163132 }
164133}
165134
166- func initConfigCommand (loader functionLoader ) (fn.Function , error ) {
135+ func initConfigCommand (loader common. FunctionLoader ) (fn.Function , error ) {
167136 config := newConfigCmdConfig ()
168137
169138 function , err := loader .Load (config .Path )
0 commit comments