<commit_before>package main

import (
	"database/sql"
	"fmt"
	"log"
	"os"

	_ "github.com/denisenkom/go-mssqldb"
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/lib/pq"
	"github.com/spf13/pflag"

	"github.com/go-testfixtures/testfixtures/v3"
)

var version = "master"

const usage = `TODO`

func main() {
	log.SetFlags(0)
	log.SetOutput(os.Stderr)

	var (
		versionFlag bool
		dialect     string
		connString  string
		dir         string
		files       []string
	)

	pflag.BoolVar(&versionFlag, "version", false, "show testfixtures version")
	pflag.StringVarP(&dialect, "dialect", "d", "", "which database system you're using (postgres, timescaledb, mysql, mariadb, sqlite or sqlserver)")
	pflag.StringVarP(&connString, "conn", "c", "", "a database connection string")
	pflag.StringVarP(&dir, "dir", "D", "", "a directory of YAML fixtures to load")
	pflag.StringSliceVarP(&files, "files", "f", nil, "a list of YAML files to load")
	pflag.Parse()

	if versionFlag {
		log.Printf("testfixtures version: %s", version)
		return
	}

	if dialect == "" && connString == "" {
		log.Fatal("testfixtures: both --dialect (-d) and --conn (-c) are required")
		return
	}
	if dir == "" && len(files) == 0 {
		log.Fatal("testfixtures: either --dir (-D) or --files (-f) need to be given")
		return
	}
	if dir != "" && len(files) > 0 {
		log.Fatal("testfixtures: you can use --dir (-D) and --files (-f) together")
		return
	}

	dialect, err := getDialect(dialect)
	if err != nil {
		log.Fatal(err)
		return
	}

	db, err := sql.Open(dialect, connString)
	if err != nil {
		log.Fatalf("testfixtures: could not connect to database: %v", err)
		return
	}
	defer db.Close()

	if err := db.Ping(); err != nil {
		log.Fatalf("testfixtures: could not ping database: %v", err)
		return
	}

	options := []func(*testfixtures.Loader) error{
		testfixtures.Database(db),
		testfixtures.Dialect(dialect),
	}
	if dir != "" {
		options = append(options, testfixtures.Directory(dir))
	} else {
		options = append(options, testfixtures.Files(files...))
	}
	loader, err := testfixtures.New(options...)
	if err != nil {
		log.Fatal(err)
	}
	if err := loader.Load(); err != nil {
		log.Fatal(err)
	}
	log.Printf("testfixtures: fixtures loaded successfully")
}

func getDialect(dialect string) (string, error) {
	switch dialect {
	case "postgres", "postgresql", "timescaledb":
		return "postgres", nil
	case "mysql", "mariadb":
		return "mysql", nil
	case "sqlite", "sqlite3":
		return "sqlite3", nil
	case "mssql", "sqlserver":
		return "mssql", nil
	default:
		return "", fmt.Errorf(`testfixtures: unrecognized dialect "%s"`, dialect)
	}
}
<commit_msg>v3: CLI: Add flags for missing options<commit_after>package main

import (
	"database/sql"
	"fmt"
	"log"
	"os"

	_ "github.com/denisenkom/go-mssqldb"
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/lib/pq"
	"github.com/spf13/pflag"

	"github.com/go-testfixtures/testfixtures/v3"
)

var version = "master"

const usage = `TODO`

func main() {
	log.SetFlags(0)
	log.SetOutput(os.Stderr)

	var (
		versionFlag           bool
		dialect               string
		connString            string
		dir                   string
		files                 []string
		useAlterContraint     bool
		skipResetSequences    bool
		resetSequencesTo      int64
		skipTestDatabaseCheck bool
	)

	pflag.BoolVar(&versionFlag, "version", false, "show testfixtures version")
	pflag.StringVarP(&dialect, "dialect", "d", "", "which database system you're using (postgres, timescaledb, mysql, mariadb, sqlite or sqlserver)")
	pflag.StringVarP(&connString, "conn", "c", "", "a database connection string")
	pflag.StringVarP(&dir, "dir", "D", "", "a directory of YAML fixtures to load")
	pflag.StringSliceVarP(&files, "files", "f", nil, "a list of YAML files to load")
	pflag.BoolVar(&useAlterContraint, "alter-constraint", false, "use ALTER CONSTRAINT to disable referential integrity (PostgreSQL only)")
	pflag.BoolVar(&skipResetSequences, "no-reset-sequences", false, "skip reset of sequences after loading (PostgreSQL only)")
	pflag.Int64Var(&resetSequencesTo, "reset-sequences-to", 0, "sets the number sequences will be reset after loading fixtures (PostgreSQL only, defaults to 10000)")
	pflag.BoolVar(&skipTestDatabaseCheck, "dangerous-no-test-database-check", false, `skips check for "test" in database name (use with caution)`)
	pflag.Parse()

	if versionFlag {
		log.Printf("testfixtures version: %s", version)
		return
	}

	if dialect == "" && connString == "" {
		log.Fatal("testfixtures: both --dialect (-d) and --conn (-c) are required")
		return
	}
	if dir == "" && len(files) == 0 {
		log.Fatal("testfixtures: either --dir (-D) or --files (-f) need to be given")
		return
	}
	if dir != "" && len(files) > 0 {
		log.Fatal("testfixtures: you can use --dir (-D) and --files (-f) together")
		return
	}

	dialect, err := getDialect(dialect)
	if err != nil {
		log.Fatal(err)
		return
	}

	db, err := sql.Open(dialect, connString)
	if err != nil {
		log.Fatalf("testfixtures: could not connect to database: %v", err)
		return
	}
	defer db.Close()

	if err := db.Ping(); err != nil {
		log.Fatalf("testfixtures: could not ping database: %v", err)
		return
	}

	options := []func(*testfixtures.Loader) error{
		testfixtures.Database(db),
		testfixtures.Dialect(dialect),
	}
	if dir != "" {
		options = append(options, testfixtures.Directory(dir))
	} else {
		options = append(options, testfixtures.Files(files...))
	}
	if useAlterContraint {
		options = append(options, testfixtures.UseAlterConstraint())
	}
	if skipResetSequences {
		options = append(options, testfixtures.SkipResetSequences())
	}
	if resetSequencesTo > 0 {
		options = append(options, testfixtures.ResetSequencesTo(resetSequencesTo))
	}
	if skipTestDatabaseCheck {
		options = append(options, testfixtures.DangerousSkipTestDatabaseCheck())
	}

	loader, err := testfixtures.New(options...)
	if err != nil {
		log.Fatal(err)
	}
	if err := loader.Load(); err != nil {
		log.Fatal(err)
	}
	log.Printf("testfixtures: fixtures loaded successfully")
}

func getDialect(dialect string) (string, error) {
	switch dialect {
	case "postgres", "postgresql", "timescaledb":
		return "postgres", nil
	case "mysql", "mariadb":
		return "mysql", nil
	case "sqlite", "sqlite3":
		return "sqlite3", nil
	case "mssql", "sqlserver":
		return "mssql", nil
	default:
		return "", fmt.Errorf(`testfixtures: unrecognized dialect "%s"`, dialect)
	}
}

{'fraction_non_alphanumeric': 0.1522930035999374, 'fraction_numerical': 0.0043825324776960405, 'mean_word_length': 3.980514419329696, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 6, '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': '1056991', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2261, 'n_words': 575}