/* Copyright 2020 The Kruise Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "math/rand" "os" "time" "github.com/openkruise/kruise-tools/cmd/migrate" cmdutil "github.com/openkruise/kruise-tools/cmd/util" "github.com/openkruise/kruise-tools/pkg/utils/logs" "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" ) // noUsageError suppresses usage printing when it occurs // (since cobra doesn't provide a good way to avoid printing // out usage in only certain situations). type noUsageError struct{ error } func main() { rand.Seed(time.Now().UnixNano()) command := newCommand() logs.InitLogs() defer logs.FlushLogs() if err := command.Execute(); err != nil { os.Exit(1) } } func newCommand() *cobra.Command { ioStream := cmdutil.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} cmds := &cobra.Command{ Use: "kruise", Short: "kruise is a command-line tool to use Kruise.", Long: "kruise is a command-line tool to use Kruise.", Run: runHelp, } flags := cmds.PersistentFlags() kubeConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag() kubeConfigFlags.AddFlags(flags) f := cmdutil.NewFactory(kubeConfigFlags) cmds.AddCommand( migrate.NewCmdMigrate(f, ioStream), ) return cmds } func runHelp(cmd *cobra.Command, args []string) { cmd.Help() }