<commit_before>package flags

import (
	"flag"
	"log"
	"strings"
	"time"
)

var (
	stringPtrs   = map[string]*string{}
	boolPtrs     = map[string]*bool{}
	durationPtrs = map[string]*time.Duration{}
	float64Ptrs  = map[string]*float64{}
	intPtrs      = map[string]*int{}
	slicePtrs    = map[string]*[]string{}
)

func ValidateNonZero(names ...string) {
	for _, name := range names {
		// NOTE: Bool flags not supported.
		if stringPtrs[name] == nil && durationPtrs[name] == nil && float64Ptrs[name] == nil && intPtrs[name] == nil && slicePtrs[name] == nil {
			log.Fatalf("%s is not defined", name)
		}
		if stringPtrs[name] != nil && *stringPtrs[name] == "" {
			log.Fatalf("Missing --%s", name)
		}
		if durationPtrs[name] != nil && int64(*durationPtrs[name]) == 0 {
			log.Fatalf("Missing --%s", name)
		}
		if float64Ptrs[name] != nil && *float64Ptrs[name] == 0 {
			log.Fatalf("Missing --%s", name)
		}
		if intPtrs[name] != nil && *intPtrs[name] == 0 {
			log.Fatalf("Missing --%s", name)
		}
		if slicePtrs[name] != nil && len(*slicePtrs[name]) == 0 {
			log.Fatalf("Missing --%s", name)
		}
	}
}

type sliceContainer struct {
	S *[]string
}

func (s *sliceContainer) String() string {
	if s == nil || s.S == nil {
		return ""
	}
	return strings.Join(*s.S, ",")
}

func (s *sliceContainer) Set(value string) error {
	*s.S = strings.Split(value, ",")
	return nil
}

func String(name string, value string, usage string) *string {
	if _, exists := stringPtrs[name]; !exists {
		stringPtrs[name] = flag.String(name, value, usage)
	}

	return stringPtrs[name]
}

func Int(name string, value int, usage string) *int {
	if _, exists := intPtrs[name]; !exists {
		intPtrs[name] = flag.Int(name, value, usage)
	}
<commit_msg>[Flags] Fix Slice not proper setting values when set empty.<commit_after>package flags

import (
	"flag"
	"log"
	"strings"
	"time"
)

var (
	stringPtrs   = map[string]*string{}
	boolPtrs     = map[string]*bool{}
	durationPtrs = map[string]*time.Duration{}
	float64Ptrs  = map[string]*float64{}
	intPtrs      = map[string]*int{}
	slicePtrs    = map[string]*[]string{}
)

func ValidateNonZero(names ...string) {
	for _, name := range names {
		// NOTE: Bool flags not supported.
		if stringPtrs[name] == nil && durationPtrs[name] == nil && float64Ptrs[name] == nil && intPtrs[name] == nil && slicePtrs[name] == nil {
			log.Fatalf("%s is not defined", name)
		}
		if stringPtrs[name] != nil && *stringPtrs[name] == "" {
			log.Fatalf("Missing --%s", name)
		}
		if durationPtrs[name] != nil && int64(*durationPtrs[name]) == 0 {
			log.Fatalf("Missing --%s", name)
		}
		if float64Ptrs[name] != nil && *float64Ptrs[name] == 0 {
			log.Fatalf("Missing --%s", name)
		}
		if intPtrs[name] != nil && *intPtrs[name] == 0 {
			log.Fatalf("Missing --%s", name)
		}
		if slicePtrs[name] != nil && len(*slicePtrs[name]) == 0 {
			log.Fatalf("Missing --%s", name)
		}
	}
}

type sliceContainer struct {
	S *[]string
}

func (s *sliceContainer) String() string {
	if s == nil || s.S == nil {
		return ""
	}
	return strings.Join(*s.S, ",")
}

func (s *sliceContainer) Set(value string) error {
	if value == "" {
		*s.S = nil
	} else {
		*s.S = strings.Split(value, ",")
	}
	return nil
}

func String(name string, value string, usage string) *string {
	if _, exists := stringPtrs[name]; !exists {
		stringPtrs[name] = flag.String(name, value, usage)
	}

	return stringPtrs[name]
}

func Int(name string, value int, usage string) *int {
	if _, exists := intPtrs[name]; !exists {
		intPtrs[name] = flag.Int(name, value, usage)
	}

{'fraction_non_alphanumeric': 0.18557284299858556, 'fraction_numerical': 0.009052333804809052, 'mean_word_length': 3.739946380697051, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '294478', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1328, 'n_words': 312}