github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/commands/alpha/sync/synccmd.go (about) 1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sync 16 17 import ( 18 "context" 19 "flag" 20 "fmt" 21 22 "github.com/GoogleContainerTools/kpt/commands/alpha/sync/create" 23 "github.com/GoogleContainerTools/kpt/commands/alpha/sync/delete" 24 "github.com/GoogleContainerTools/kpt/commands/alpha/sync/get" 25 "github.com/GoogleContainerTools/kpt/internal/docs/generated/syncdocs" 26 "github.com/GoogleContainerTools/kpt/internal/util/porch" 27 "github.com/spf13/cobra" 28 "k8s.io/cli-runtime/pkg/genericclioptions" 29 "k8s.io/client-go/rest" 30 ) 31 32 func NewCommand(ctx context.Context, version string) *cobra.Command { 33 sync := &cobra.Command{ 34 Use: "sync", 35 Short: "[Alpha] " + syncdocs.SyncShort, 36 Long: "[Alpha] " + syncdocs.SyncLong, 37 RunE: func(cmd *cobra.Command, args []string) error { 38 h, err := cmd.Flags().GetBool("help") 39 if err != nil { 40 return err 41 } 42 if h { 43 return cmd.Help() 44 } 45 return cmd.Usage() 46 }, 47 Hidden: porch.HidePorchCommands, 48 } 49 50 pf := sync.PersistentFlags() 51 52 kubeflags := genericclioptions.NewConfigFlags(true) 53 kubeflags.AddFlags(pf) 54 55 kubeflags.WrapConfigFn = func(rc *rest.Config) *rest.Config { 56 rc.UserAgent = fmt.Sprintf("kpt/%s", version) 57 return rc 58 } 59 60 pf.AddGoFlagSet(flag.CommandLine) 61 62 sync.AddCommand( 63 create.NewCommand(ctx, kubeflags), 64 get.NewCommand(ctx, kubeflags), 65 delete.NewCommand(ctx, kubeflags), 66 ) 67 68 return sync 69 }