|
1 | 1 | package cli
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "os" |
5 |
| - "strings" |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "strings" |
6 | 7 |
|
7 |
| - "github.com/spf13/cobra" |
8 |
| - "github.com/spf13/viper" |
9 |
| - "k8s.io/cli-runtime/pkg/genericclioptions" |
| 8 | + "github.com/spf13/cobra" |
| 9 | + "github.com/spf13/viper" |
| 10 | + "k8s.io/cli-runtime/pkg/genericclioptions" |
10 | 11 | )
|
11 | 12 |
|
12 | 13 | var (
|
13 |
| - KubernetesConfigFlags *genericclioptions.ConfigFlags |
| 14 | + KubernetesConfigFlags *genericclioptions.ConfigFlags |
14 | 15 | )
|
15 | 16 |
|
16 | 17 | func RootCmd() *cobra.Command {
|
17 |
| - cmd := &cobra.Command{ |
18 |
| - Use: "pv-mounter", |
19 |
| - Short: "A plugin to mount and clean PVCs", |
20 |
| - Long: `A plugin to mount and clean PVCs using SSHFS.`, |
21 |
| - } |
| 18 | + cmd := &cobra.Command{ |
| 19 | + Use: "pv-mounter", |
| 20 | + Short: "A tool to mount and unmount PVs", |
| 21 | + Long: `A tool to mount and unmount PVs using SSHFS.`, |
| 22 | + } |
22 | 23 |
|
23 |
| - cmd.AddCommand(mountCmd()) |
24 |
| - cmd.AddCommand(cleanCmd()) |
| 24 | + if strings.HasPrefix(filepath.Base(os.Args[0]), "kubectl-") { |
| 25 | + cmd.Use = "kubectl pv-mounter [flags]" |
| 26 | + } |
25 | 27 |
|
26 |
| - return cmd |
| 28 | + cmd.AddCommand(mountCmd()) |
| 29 | + cmd.AddCommand(cleanCmd()) |
| 30 | + |
| 31 | + return cmd |
27 | 32 | }
|
28 | 33 |
|
29 | 34 | func InitAndExecute() {
|
30 |
| - KubernetesConfigFlags = genericclioptions.NewConfigFlags(true) |
31 |
| - KubernetesConfigFlags.AddFlags(RootCmd().PersistentFlags()) |
| 35 | + KubernetesConfigFlags = genericclioptions.NewConfigFlags(true) |
| 36 | + KubernetesConfigFlags.AddFlags(RootCmd().PersistentFlags()) |
32 | 37 |
|
33 |
| - viper.AutomaticEnv() |
34 |
| - viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) |
| 38 | + viper.AutomaticEnv() |
| 39 | + viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) |
35 | 40 |
|
36 |
| - if err := RootCmd().Execute(); err != nil { |
37 |
| - os.Exit(1) |
38 |
| - } |
| 41 | + if err := RootCmd().Execute(); err != nil { |
| 42 | + os.Exit(1) |
| 43 | + } |
39 | 44 | }
|
| 45 | + |
| 46 | + |
0 commit comments