From 97223eac13b5c9eaddd74b25c97d02656a6a46d9 Mon Sep 17 00:00:00 2001 From: nite07 Date: Sat, 16 Nov 2024 00:51:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20all=20group=20tags=20miss=20=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E5=9C=B0=E5=8C=BA=20fix:=20config=20cannot=20be=20loa?= =?UTF-8?q?ded=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/convert.go | 38 +++++++++++++++++++++++--------------- model/country_code_map.go | 3 +++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/cmd/convert.go b/cmd/convert.go index 34e6b05..894ee70 100755 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -34,9 +34,9 @@ func init() { convertCmd.Flags().StringVarP(&delete, "delete", "d", "", "delete proxies with regex") convertCmd.Flags().StringToStringVarP(&rename, "rename", "r", nil, "rename proxies with regex") convertCmd.Flags().BoolVarP(&group, "group", "g", false, "grouping proxies by country") - convertCmd.Flags().StringVarP(&groupType, "group-type", "G", "selector", "group type, selector or urltest") - convertCmd.Flags().StringVarP(&sortKey, "sort", "S", "tag", "sort key, tag or num") - convertCmd.Flags().StringVarP(&sortType, "sort-type", "T", "asc", "sort type, asc or desc") + convertCmd.Flags().StringVarP(&groupType, "group-type", "G", "", "group type, selector or urltest") + convertCmd.Flags().StringVarP(&sortKey, "sort", "S", "", "sort key, tag or num") + convertCmd.Flags().StringVarP(&sortType, "sort-type", "T", "", "sort type, asc or desc") convertCmd.Flags().StringVarP(&config, "config", "c", "", "configuration file path") RootCmd.AddCommand(convertCmd) } @@ -80,7 +80,7 @@ func convertRun(cmd *cobra.Command, args []string) { func loadConfig() { if config == "" { if wd, err := os.Getwd(); err == nil { - config = filepath.Join(wd, "github.com/nitezs/sub2sing-box.json") + config = filepath.Join(wd, "sub2sing-box.json") if _, err := os.Stat(config); os.IsNotExist(err) { return } @@ -106,29 +106,37 @@ func loadConfig() { } func mergeConfig(cfg model.ConvertRequest) { - if len(subscriptions) == 0 { - subscriptions = cfg.Subscriptions - } - if len(proxies) == 0 { - proxies = cfg.Proxies - } + subscriptions = append(subscriptions, cfg.Subscriptions...) + proxies = append(proxies, cfg.Proxies...) if template == "" { template = cfg.Template } if delete == "" { delete = cfg.Delete } - if len(rename) == 0 { - rename = cfg.Rename + for k, v := range cfg.Rename { + rename[k] = v } if groupType == "" { - groupType = cfg.GroupType + if cfg.GroupType != "" { + groupType = cfg.GroupType + } else { + groupType = "selector" + } } if sortKey == "" { - sortKey = cfg.SortKey + if cfg.SortKey != "" { + sortKey = cfg.SortKey + } else { + sortKey = "tag" + } } if sortType == "" { - sortType = cfg.SortType + if cfg.SortType != "" { + sortType = cfg.SortType + } else { + sortType = "asc" + } } if output == "" { output = cfg.Output diff --git a/model/country_code_map.go b/model/country_code_map.go index aa1550f..86b6b87 100755 --- a/model/country_code_map.go +++ b/model/country_code_map.go @@ -1077,6 +1077,9 @@ func GetContryName(tag string) string { var values []string func IsCountryGroup(tag string) bool { + if tag == "其他地区" { + return true + } return slices.Contains(values, tag) }