1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 15:14:43 -05:00

fix: all group tags miss 其他地区

fix: config cannot be loaded correctly
This commit is contained in:
Nite07 2024-11-16 00:51:00 +08:00
parent 0681136d65
commit 97223eac13
2 changed files with 26 additions and 15 deletions

View File

@ -34,9 +34,9 @@ func init() {
convertCmd.Flags().StringVarP(&delete, "delete", "d", "", "delete proxies with regex") convertCmd.Flags().StringVarP(&delete, "delete", "d", "", "delete proxies with regex")
convertCmd.Flags().StringToStringVarP(&rename, "rename", "r", nil, "rename 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().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(&groupType, "group-type", "G", "", "group type, selector or urltest")
convertCmd.Flags().StringVarP(&sortKey, "sort", "S", "tag", "sort key, tag or num") convertCmd.Flags().StringVarP(&sortKey, "sort", "S", "", "sort key, tag or num")
convertCmd.Flags().StringVarP(&sortType, "sort-type", "T", "asc", "sort type, asc or desc") convertCmd.Flags().StringVarP(&sortType, "sort-type", "T", "", "sort type, asc or desc")
convertCmd.Flags().StringVarP(&config, "config", "c", "", "configuration file path") convertCmd.Flags().StringVarP(&config, "config", "c", "", "configuration file path")
RootCmd.AddCommand(convertCmd) RootCmd.AddCommand(convertCmd)
} }
@ -80,7 +80,7 @@ func convertRun(cmd *cobra.Command, args []string) {
func loadConfig() { func loadConfig() {
if config == "" { if config == "" {
if wd, err := os.Getwd(); err == nil { 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) { if _, err := os.Stat(config); os.IsNotExist(err) {
return return
} }
@ -106,29 +106,37 @@ func loadConfig() {
} }
func mergeConfig(cfg model.ConvertRequest) { func mergeConfig(cfg model.ConvertRequest) {
if len(subscriptions) == 0 { subscriptions = append(subscriptions, cfg.Subscriptions...)
subscriptions = cfg.Subscriptions proxies = append(proxies, cfg.Proxies...)
}
if len(proxies) == 0 {
proxies = cfg.Proxies
}
if template == "" { if template == "" {
template = cfg.Template template = cfg.Template
} }
if delete == "" { if delete == "" {
delete = cfg.Delete delete = cfg.Delete
} }
if len(rename) == 0 { for k, v := range cfg.Rename {
rename = cfg.Rename rename[k] = v
} }
if groupType == "" { if groupType == "" {
groupType = cfg.GroupType if cfg.GroupType != "" {
groupType = cfg.GroupType
} else {
groupType = "selector"
}
} }
if sortKey == "" { if sortKey == "" {
sortKey = cfg.SortKey if cfg.SortKey != "" {
sortKey = cfg.SortKey
} else {
sortKey = "tag"
}
} }
if sortType == "" { if sortType == "" {
sortType = cfg.SortType if cfg.SortType != "" {
sortType = cfg.SortType
} else {
sortType = "asc"
}
} }
if output == "" { if output == "" {
output = cfg.Output output = cfg.Output

View File

@ -1077,6 +1077,9 @@ func GetContryName(tag string) string {
var values []string var values []string
func IsCountryGroup(tag string) bool { func IsCountryGroup(tag string) bool {
if tag == "其他地区" {
return true
}
return slices.Contains(values, tag) return slices.Contains(values, tag)
} }