mirror of
https://github.com/wahyd4/cert-manager.git
synced 2026-08-20 18:46:03 +10:00
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
/*
|
|
Copyright 2021 The cert-manager 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 flags
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"k8s.io/klog/v2"
|
|
|
|
"github.com/spf13/cobra"
|
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
|
)
|
|
|
|
func AddFlags(cmds *cobra.Command) cmdutil.Factory {
|
|
kubeConfigFlags := genericclioptions.NewConfigFlags(true)
|
|
kubeConfigFlags.AddFlags(cmds.PersistentFlags())
|
|
|
|
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(kubeConfigFlags)
|
|
matchVersionKubeConfigFlags.AddFlags(cmds.PersistentFlags())
|
|
|
|
factory := cmdutil.NewFactory(matchVersionKubeConfigFlags)
|
|
|
|
cmds.Flags().AddGoFlagSet(flag.CommandLine)
|
|
flag.CommandLine.Parse([]string{})
|
|
fakefs := flag.NewFlagSet("fake", flag.ExitOnError)
|
|
klog.InitFlags(fakefs)
|
|
if err := fakefs.Parse([]string{"-logtostderr=false"}); err != nil {
|
|
fmt.Fprintf(os.Stderr, "%s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
return factory
|
|
}
|