<commit_before>//go:generate go run _tools/gen_commands.go

package main

import (
	"flag"
	"fmt"
	"os"
	"runtime"
	"time"

	"github.com/Songmu/prompter"
	"github.com/Songmu/retry"
	"github.com/mackerelio/mackerel-agent/command"
	"github.com/mackerelio/mackerel-agent/config"
	"github.com/mackerelio/mackerel-agent/mackerel"
	"github.com/mackerelio/mackerel-agent/version"
)

/* +main - mackerel-agent

	mackerel-agent [options]

main process of mackerel-agent
*/
func doMain(fs *flag.FlagSet, argv []string) error {
	conf, err := resolveConfig(fs, argv)
	if err != nil {
		return fmt.Errorf("failed to load config: %s", err)
	}
	return start(conf, make(chan struct{}))
}

/* +command init - initialize mackerel-agent.conf with apikey

	init -apikey=<KEY> [-conf=mackerel-agent.conf]

Initialize mackerel-agent.conf with api key.

- The conf file doesn't exist:
    create new file and set the apikey.
- The conf file exists and apikey is unset:
    set the apikey.
- The conf file exists and apikey already set:
    skip initializing. Don't overwrite apikey and exit normally.
- The conf file exists, but the contents of it is invalid toml:
    exit with error.
*/
func doInit(fs *flag.FlagSet, argv []string) error {
	err := doInitialize(fs, argv)
	if _, ok := err.(apikeyAlreadySetError); ok {
		logger.Infof("%s", err)
		return nil
	}
	return err
}

/* +command supervise - supervise mode

	supervise -conf mackerel-agent.conf ...

run as supervise mode enabling configuration reloading and crash recovery
*/
func doSupervise(fs *flag.FlagSet, argv []string) error {
	copiedArgv := make([]string, len(argv))
	copy(copiedArgv, argv)
	conf, err := resolveConfig(fs, argv)
	if err != nil {<commit_msg>supervise mode is not supported on windows<commit_after>//go:generate go run _tools/gen_commands.go

package main

import (
	"flag"
	"fmt"
	"os"
	"runtime"
	"time"

	"github.com/Songmu/prompter"
	"github.com/Songmu/retry"
	"github.com/mackerelio/mackerel-agent/command"
	"github.com/mackerelio/mackerel-agent/config"
	"github.com/mackerelio/mackerel-agent/mackerel"
	"github.com/mackerelio/mackerel-agent/version"
)

/* +main - mackerel-agent

	mackerel-agent [options]

main process of mackerel-agent
*/
func doMain(fs *flag.FlagSet, argv []string) error {
	conf, err := resolveConfig(fs, argv)
	if err != nil {
		return fmt.Errorf("failed to load config: %s", err)
	}
	return start(conf, make(chan struct{}))
}

/* +command init - initialize mackerel-agent.conf with apikey

	init -apikey=<KEY> [-conf=mackerel-agent.conf]

Initialize mackerel-agent.conf with api key.

- The conf file doesn't exist:
    create new file and set the apikey.
- The conf file exists and apikey is unset:
    set the apikey.
- The conf file exists and apikey already set:
    skip initializing. Don't overwrite apikey and exit normally.
- The conf file exists, but the contents of it is invalid toml:
    exit with error.
*/
func doInit(fs *flag.FlagSet, argv []string) error {
	err := doInitialize(fs, argv)
	if _, ok := err.(apikeyAlreadySetError); ok {
		logger.Infof("%s", err)
		return nil
	}
	return err
}

/* +command supervise - supervise mode

	supervise -conf mackerel-agent.conf ...

run as supervise mode enabling configuration reloading and crash recovery
*/
func doSupervise(fs *flag.FlagSet, argv []string) error {
	if runtime.GOOS == "windows" {
		return fmt.Errorf("supervise mode is not supported on windows")
	}
	copiedArgv := make([]string, len(argv))
	copy(copiedArgv, argv)
	conf, err := resolveConfig(fs, argv)
	if err != nil {
{'fraction_non_alphanumeric': 0.12280701754385964, 'fraction_numerical': 0.0, 'mean_word_length': 4.028449502133713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4061516', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1234, 'n_words': 361}