<commit_before>package flagfile_test

import (
	"github.com/dolmen-go/flagx/flagfile"
)

var _ flagfile.Loader = flagfile.Lines<commit_msg>flagfile: add test example<commit_after>package flagfile_test

import (
	"flag"
	"fmt"

	"github.com/dolmen-go/flagx/flagfile"
)

var _ flagfile.Loader = flagfile.Lines

func saveCommandLine() func() {
	backup := flag.CommandLine
	flag.CommandLine = flag.NewFlagSet("", flag.ContinueOnError)
	return func() {
		flag.CommandLine = backup
	}
}

func Example() {
	defer saveCommandLine()() // Only for the example context

	flag.Var(flagfile.File(flag.CommandLine, flagfile.Lines), "args", "args from file (one line = one argument)")
	b := flag.Bool("bool", false, "bool test")
	i := flag.Int("int", 0, "int test")
	s := flag.String("string", "", "string test")

	err := flag.CommandLine.Parse([]string{
		"-args", "testdata/args.txt",
	})
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(*b, *i, *s)

	// Output:
	// true 1 foo
}
{'fraction_non_alphanumeric': 0.16597938144329896, 'fraction_numerical': 0.002061855670103093, 'mean_word_length': 4.2771739130434785, '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': '5734255', 'n_tokens_mistral': 366, 'n_tokens_neox': 353, 'n_words': 78}