github.com/oam-dev/kubevela@v1.9.11/references/cli/export.go (about) 1 /* 2 Copyright 2021 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package cli 18 19 import ( 20 "github.com/spf13/cobra" 21 22 "github.com/oam-dev/kubevela/apis/types" 23 common2 "github.com/oam-dev/kubevela/pkg/utils/common" 24 cmdutil "github.com/oam-dev/kubevela/pkg/utils/util" 25 "github.com/oam-dev/kubevela/references/common" 26 ) 27 28 // NewExportCommand will create command for exporting deploy manifests from an AppFile 29 func NewExportCommand(c common2.Args, ioStream cmdutil.IOStreams) *cobra.Command { 30 appFilePath := new(string) 31 cmd := &cobra.Command{ 32 Use: "export", 33 DisableFlagsInUseLine: true, 34 Short: "Export deploy manifests from appfile", 35 Long: "Export deploy manifests from appfile or application.", 36 Annotations: map[string]string{ 37 types.TagCommandType: types.TypeLegacy, 38 }, 39 RunE: func(cmd *cobra.Command, args []string) error { 40 namespace, err := GetFlagNamespaceOrEnv(cmd, c) 41 if err != nil { 42 return err 43 } 44 o := &common.AppfileOptions{ 45 IO: ioStream, 46 } 47 _, data, err := o.Export(*appFilePath, namespace, true, c) 48 if err != nil { 49 return err 50 } 51 _, err = ioStream.Out.Write(data) 52 return err 53 }, 54 } 55 cmd.SetOut(ioStream.Out) 56 57 addNamespaceAndEnvArg(cmd) 58 cmd.Flags().StringVarP(appFilePath, "file", "f", "", "specify file path for appfile") 59 return cmd 60 }