<commit_before>package main

import (
	"database/sql"
	"io"
	"os"

	"github.com/BurntSushi/toml"
)

const (
	layout  = "2006-01-02"
	tlayout = "04:05.0"
)

// Horsebase :horsebase.tomlの[horsebase]のパラメータ値
// を保持したオブジェクト
type Horsebase struct {
	Config Config `toml:"config"`
	DbInfo HBDB   `toml:"db"`
	Stdout io.Writer
	Stderr io.Writer
}

// Config :
// horsebase.tomlで定義した設定値
// を保持したオブジェクト
type Config struct {
	RaceHtmlPath  string `toml:"race_html_path"`
	HorseHtmlPath string `toml:"horse_html_path"`
	OldestDate    int    `toml:"oldest_date"`
}

type HBDB struct {
	DbUser string `toml:"dbuser"`
	DbPass string `toml:"dbpass"`
	db     *sql.DB
	tx     *sql.Tx
}

func (hb *Horsebase) New() *Horsebase {

	hb = &Horsebase{
		Stdout: os.Stdout,
		Stderr: os.Stderr,
	}

	_, err := toml.DecodeFile("./file/horsebase.toml", &hb)
	if err != nil {
		PrintError(hb.Stderr, "%s", err)
		os.Exit(1)
	}

	return hb
}

func (hb *Horsebase) Run(args []string) int {

	if len(os.Args) < 2 {
		PrintError(hb.Stderr, "Invalid Argument")
		os.Exit(1)
	}

	param := os.Args[1]

	switch param {
	// DB構築
	// 初回起動
	case "-init_db":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		if err := hb.DbInfo.InitDB(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

		// 血統データ登録
	case "-reg_bloodtype":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		var bt BloodTypeToml
		bt = bt.New()

		if err := bt.Btd.RegistBloodType(hb.DbInfo); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

		// レースデータのURLを取得しracelist.txtに一覧化する
	case "-make_list":
		if err := hb.MakeRaceURLList(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-get_racehtml":
		if err := hb.GetRaceHTML(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

		// 5
	case "-reg_racedata":
		if err := hb.RegistRaceData(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

		//6
	case "-reg_horsedata":
		if err := hb.RegistHorseData(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-drop_db":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		if err := hb.DbInfo.DropDB(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}
	case "-match_bloodtype":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		var bt BloodTypeToml
		bt = bt.New()

		if err := bt.MatchBloodType(hb.DbInfo); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	default:
		PrintError(hb.Stderr, "Invalid Argument")
		return 1
	}

	return 0
}
<commit_msg>-help was added<commit_after>package main

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

	"github.com/BurntSushi/toml"
)

const (
	layout  = "2006-01-02"
	tlayout = "04:05.0"
)

// Horsebase :horsebase.tomlの[horsebase]のパラメータ値
// を保持したオブジェクト
type Horsebase struct {
	Config Config `toml:"config"`
	DbInfo HBDB   `toml:"db"`
	Stdout io.Writer
	Stderr io.Writer
}

// Config :
// horsebase.tomlで定義した設定値
// を保持したオブジェクト
type Config struct {
	RaceHtmlPath  string `toml:"race_html_path"`
	HorseHtmlPath string `toml:"horse_html_path"`
	OldestDate    int    `toml:"oldest_date"`
}

type HBDB struct {
	DbUser string `toml:"dbuser"`
	DbPass string `toml:"dbpass"`
	db     *sql.DB
	tx     *sql.Tx
}

func (hb *Horsebase) New() *Horsebase {

	hb = &Horsebase{
		Stdout: os.Stdout,
		Stderr: os.Stderr,
	}

	_, err := toml.DecodeFile("./file/horsebase.toml", &hb)
	if err != nil {
		PrintError(hb.Stderr, "%s", err)
		os.Exit(1)
	}

	return hb
}

func (hb *Horsebase) Run(args []string) int {

	if len(os.Args) < 2 {
		PrintError(hb.Stderr, "Invalid Argument")
		os.Exit(1)
	}

	param := os.Args[1]

	switch param {
	// DB構築
	// 初回起動
	case "-init_db":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		if err := hb.DbInfo.InitDB(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	// 血統データ登録
	case "-reg_bloodtype":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		var bt BloodTypeToml
		bt = bt.New()

		if err := bt.Btd.RegistBloodType(hb.DbInfo); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	// レースデータのURLを取得しracelist.txtに保存する
	case "-make_list":
		if err := hb.MakeRaceURLList(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-get_racehtml":
		if err := hb.GetRaceHTML(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-reg_racedata":
		if err := hb.RegistRaceData(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-reg_horsedata":
		if err := hb.RegistHorseData(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-drop_db":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		if err := hb.DbInfo.DropDB(); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-match_bloodtype":
		hb.DbInfo = hb.DbInfo.New()
		defer hb.DbInfo.db.Close()

		var bt BloodTypeToml
		bt = bt.New()

		if err := bt.MatchBloodType(hb.DbInfo); err != nil {
			PrintError(hb.Stderr, "%s", err)
			return 1
		}

	case "-help":
		fmt.Println(help)
		return 1

	default:
		PrintError(hb.Stderr, "Invalid Argument")
		return 1
	}

	return 0
}

var help = `usage: horsebase [options]

Options:

  -init_db          Create horsebase DB
  -reg_bloodtype    Store the bloodtype data defined in bloodtype.toml in horsebase DB
  -make_list        Save the URL of the race data in racelist.txt
  -get_racehtml     Gets the HTML form the URL listed in racelist.txt
  -reg_racedata     Scrape HTML and store race data in horsebase DB
  -reg_horsedata    Scrape HTML and store horse data in horsebase DB
  -drop_db          Delete horsebase DB
  -match_bloodtype  Map bloodtype data and stallion data defined in bloodtype.toml
`

{'fraction_non_alphanumeric': 0.15155733426135376, 'fraction_numerical': 0.009918218200800417, 'mean_word_length': 3.067940552016985, 'pattern_counts': {'":': 17, '<': 5, '<?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': '1397660', 'n_tokens_mistral': 2732, 'n_tokens_neox': 2442, 'n_words': 545}