12345678910111213141516171819202122232425 |
- package cmd
- import (
- "github.com/spf13/cobra"
- "os"
- "rinne.dev/doh-resolver/pkg/helpers"
- )
- // Config 存储配置文件
- var Config string
- // RegisterGlobalFlags 注册全局选项(flag)
- func RegisterGlobalFlags(rootCmd *cobra.Command) {
- rootCmd.PersistentFlags().StringVarP(&Config, "config", "c", "config.yaml", "load config file")
- }
- // RegisterDefaultCmd 注册默认命令
- func RegisterDefaultCmd(rootCmd *cobra.Command, subCmd *cobra.Command) {
- cmd, _, err := rootCmd.Find(os.Args[1:])
- firstArg := helpers.FirstElement(os.Args[1:])
- if err == nil && cmd.Use == rootCmd.Use && firstArg != "-h" && firstArg != "--help" {
- args := append([]string{subCmd.Use}, os.Args[1:]...)
- rootCmd.SetArgs(args)
- }
- }
|