@@ -17,16 +17,12 @@ limitations under the License.
17
17
package main
18
18
19
19
import (
20
- "fmt"
21
- "io/ioutil"
22
20
"log"
23
21
24
22
"github.com/spf13/cobra"
25
23
26
- "sigs.k8s.io/kubebuilder/pkg/scaffold"
27
- "sigs.k8s.io/kubebuilder/pkg/scaffold/input"
28
- "sigs.k8s.io/kubebuilder/pkg/scaffold/project"
29
- "sigs.k8s.io/yaml"
24
+ "sigs.k8s.io/kubebuilder/cmd/internal"
25
+ "sigs.k8s.io/kubebuilder/internal/config"
30
26
)
31
27
32
28
func newEditProjectCmd () * cobra.Command {
@@ -35,31 +31,33 @@ func newEditProjectCmd() *cobra.Command {
35
31
36
32
editProjectCmd := & cobra.Command {
37
33
Use : "edit" ,
38
- Short : "This command will edit the configuration of the PROJECT file " ,
39
- Long : `This command will edit the configuration of the PROJECT file ` ,
34
+ Short : "This command will edit the project configuration " ,
35
+ Long : `This command will edit the project configuration ` ,
40
36
Example : `
41
37
# To enable the multigroup layout/support
42
38
kubebuilder edit --multigroup
43
39
44
40
# To disable the multigroup layout/support
45
41
kubebuilder edit --multigroup=false` ,
46
42
Run : func (cmd * cobra.Command , args []string ) {
47
- dieIfNoProject ()
43
+ internal . DieIfNotConfigured ()
48
44
49
- projectInfo , err := scaffold . LoadProjectFile ( "PROJECT" )
45
+ projectConfig , err := config . Load ( )
50
46
if err != nil {
51
- log .Fatalf ("failed to read the PROJECT file: %v" , err )
47
+ log .Fatalf ("failed to read the configuration file: %v" , err )
52
48
}
53
49
54
- if projectInfo .Version != project .Version2 {
55
- log .Fatalf ("kubebuilder multigroup is for project version: 2," +
56
- " the version of this project is: %s \n " , projectInfo .Version )
57
- }
50
+ if opts .multigroup {
51
+ if ! projectConfig .IsV2 () {
52
+ log .Fatalf ("kubebuilder multigroup is for project version: 2," +
53
+ " the version of this project is: %s \n " , projectConfig .Version )
54
+ }
58
55
59
- // Set MultiGroup Option
60
- projectInfo .MultiGroup = opts .multigroup
56
+ // Set MultiGroup Option
57
+ projectConfig .MultiGroup = true
58
+ }
61
59
62
- err = saveProjectFile ( "PROJECT" , & projectInfo )
60
+ err = projectConfig . Save ( )
63
61
if err != nil {
64
62
log .Fatalf ("error updating project file with resource information : %v" , err )
65
63
}
@@ -72,19 +70,6 @@ func newEditProjectCmd() *cobra.Command {
72
70
return editProjectCmd
73
71
}
74
72
75
- // saveProjectFile saves the given ProjectFile at the given path.
76
- func saveProjectFile (path string , project * input.ProjectFile ) error {
77
- content , err := yaml .Marshal (project )
78
- if err != nil {
79
- return fmt .Errorf ("error marshalling project info %v" , err )
80
- }
81
- err = ioutil .WriteFile (path , content , 0666 )
82
- if err != nil {
83
- return fmt .Errorf ("failed to save project file at %s %v" , path , err )
84
- }
85
- return nil
86
- }
87
-
88
73
type editProjectCmdOptions struct {
89
74
multigroup bool
90
75
}
0 commit comments