<commit_before>package init

import (
	"errors"
	"flag"
	"path/filepath"

	"github.com/ghthor/journal/git"
	initialize "github.com/ghthor/journal/init"
)

var Cmd = NewCmd(nil)

type cmd struct {
	flagSet *flag.FlagSet

	wd string // working directory

	noCommit bool
}

func NewCmd(flagSet *flag.FlagSet) *cmd {
	if flagSet == nil {
		flagSet = flag.NewFlagSet("init", flag.ExitOnError)
	}

	c := &cmd{
		flagSet: flagSet,
	}

	c.flagSet.BoolVar(&c.noCommit, "no-commit", false, "don't commit the modifications made by initialization to the repository")

	return c
}

func (c *cmd) SetWd(directory string) {
	c.wd = directory
}

func (c *cmd) Exec(args []string) error {
	c.flagSet.Parse(args)

	a := c.flagSet.Args()

	var path string

	switch len(a) {
	case 0:
		path = c.wd
	case 1:
		path = a[0]
		if !filepath.IsAbs(path) {
			path = filepath.Join(c.wd, path)
		}

	default:
		return errors.New("too many arguments")
	}

	commitable, err := initialize.Journal(path)
	if err != nil {
		return err
	}

	if !c.noCommit {
		git.Commit(commitable)
	}

	return nil
}

func (c cmd) Summary() string {
	return "how to use `init` verb"
}<commit_msg>Added a commit msg sequence and prefix to `init` verb | It follows the standard I set within the `journal/fix` package<commit_after>package init

import (
	"errors"
	"flag"
	"path/filepath"

	"github.com/ghthor/journal/git"
	initialize "github.com/ghthor/journal/init"
)

var Cmd = NewCmd(nil)

type cmd struct {
	flagSet *flag.FlagSet

	wd string // working directory

	noCommit bool
}

func NewCmd(flagSet *flag.FlagSet) *cmd {
	if flagSet == nil {
		flagSet = flag.NewFlagSet("init", flag.ExitOnError)
	}

	c := &cmd{
		flagSet: flagSet,
	}

	c.flagSet.BoolVar(&c.noCommit, "no-commit", false, "don't commit the modifications made by initialization to the repository")

	return c
}

func (c *cmd) SetWd(directory string) {
	c.wd = directory
}

type journalInitCommit struct {
	git.Commitable
}

func (c journalInitCommit) CommitMsg() string {
	return "journal - init - " + c.Commitable.CommitMsg()
}

func (c *cmd) Exec(args []string) error {
	c.flagSet.Parse(args)

	a := c.flagSet.Args()

	var path string

	switch len(a) {
	case 0:
		path = c.wd
	case 1:
		path = a[0]
		if !filepath.IsAbs(path) {
			path = filepath.Join(c.wd, path)
		}

	default:
		return errors.New("too many arguments")
	}

	commitable, err := initialize.Journal(path)
	if err != nil {
		return err
	}

	if !c.noCommit {
		err := git.CommitEmpty(path, "journal - init - begin")
		if err != nil {
			return err
		}

		err = git.Commit(journalInitCommit{commitable})
		if err != nil {
			return err
		}

		err = git.CommitEmpty(path, "journal - init - completed")
		if err != nil {
			return err
		}
	}

	return nil
}

func (c cmd) Summary() string {
	return "how to use `init` verb"
}
{'fraction_non_alphanumeric': 0.13328581610833928, 'fraction_numerical': 0.0021382751247327157, 'mean_word_length': 3.4484944532488115, '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': '2718728', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1055, 'n_words': 288}