<commit_before>package main

import (
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"strings"
	"time"

	api "github.com/armon/consul-api"
	"github.com/hashicorp/consul-template/util"
	"github.com/hashicorp/logutils"
)

// Exit codes are int valuse that represent an exit code for a particular error.
// Sub-systems may check this unique error to determine the cause of an error
// without parsing the output or help text.
const (
	ExitCodeOK int = 0

	// Errors start at 10
	ExitCodeError = 10 + iota
	ExitCodeParseFlagsError
	ExitCodeParseWaitError
	ExitCodeParseConfigError
	ExitCodeRunnerError
	ExitCodeConsulAPIError
	ExitCodeWatcherError
)

type CLI struct {
	// outSteam and errStream are the standard out and standard error streams to
	// write messages from the CLI.
	outStream, errStream io.Writer
}

// Run accepts a slice of arguments and returns an int representing the exit
// status from the command.
func (cli *CLI) Run(args []string) int {
	cli.initLogger()

	// TODO: remove in v0.4.0 (deprecated)
	var address, datacenter string
	var errExit, terminate, reload bool

	var version, once bool
	var config = new(Config)

	// Parse the flags and options
	flags := flag.NewFlagSet(Name, flag.ContinueOnError)
	flags.SetOutput(cli.errStream)
	flags.Usage = func() {
		fmt.Fprintf(cli.errStream, usage, Name)
	}
	flags.StringVar(&config.Consul, "consul", "",
		"address of the Consul instance")
	flags.StringVar(&config.Token, "token", "",
		"a consul API token")
	flags.StringVar(&config.WaitRaw, "wait", "",
		"the minimum(:maximum) to wait before updating the environment")
	flags.StringVar(&config.Path, "config", "",
		"the path to a config file on disk")
	flags.DurationVar(&config.Timeout, "timeout", 0,
		"the time to wait for a process to restart")
	flags.BoolVar(&config.Sanitize, "sanitize", true,
		"remove bad characters from values")
	flags.BoolVar(&config.Upcase, "upcase", true,
		"convert all environment keys to uppercase")
	flags.BoolVar(&once, "once", false,
		"do not run as a daemon")
	flags.BoolVar(&version, "version", false, "display the version")

	// TODO: remove in v0.4.0 (deprecated)
	flags.StringVar(&datacenter, "dc", "",
		"DEPRECATED")
	flags.StringVar(&address, "addr", "",
		"DEPRECATED")
	flags.BoolVar(&errExit, "errexit", false,
		"DEPRECAETD")
	flags.BoolVar(&terminate, "terminate", false,
		"DEPRECAETD")
	flags.BoolVar(&reload, "reload", false,
		"DEPRECATED")

	// If there was a parser error, stop
	if err := flags.Parse(args[1:]); err != nil {
		return cli.handleError(err, ExitCodeParseFlagsError)
	}

	// TODO: remove in v0.4.0 (deprecated)
	if address != "" {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -addr flag is deprecated, please use -consul instead")
		config.Consul = address
	}

	if datacenter != "" {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -dc flag is deprecated, please use the @dc syntax instead")
	}

	if errExit {
		fmt.Fprintf(cli.errStream, "DEPRECATED: the -errexit flag is deprecated")
	}

	if terminate {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -terminate flag is deprecated, use -once instead")
	}

	if reload {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -reload flag is deprecated, use -once instead")
	}

	// If the version was requested, return an "error" containing the version
	// information. This might sound weird, but most *nix applications actually
	// print their version on stderr anyway.<commit_msg>Added newline to Fprintf<commit_after>package main

import (
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"strings"
	"time"

	api "github.com/armon/consul-api"
	"github.com/hashicorp/consul-template/util"
	"github.com/hashicorp/logutils"
)

// Exit codes are int valuse that represent an exit code for a particular error.
// Sub-systems may check this unique error to determine the cause of an error
// without parsing the output or help text.
const (
	ExitCodeOK int = 0

	// Errors start at 10
	ExitCodeError = 10 + iota
	ExitCodeParseFlagsError
	ExitCodeParseWaitError
	ExitCodeParseConfigError
	ExitCodeRunnerError
	ExitCodeConsulAPIError
	ExitCodeWatcherError
)

type CLI struct {
	// outSteam and errStream are the standard out and standard error streams to
	// write messages from the CLI.
	outStream, errStream io.Writer
}

// Run accepts a slice of arguments and returns an int representing the exit
// status from the command.
func (cli *CLI) Run(args []string) int {
	cli.initLogger()

	// TODO: remove in v0.4.0 (deprecated)
	var address, datacenter string
	var errExit, terminate, reload bool

	var version, once bool
	var config = new(Config)

	// Parse the flags and options
	flags := flag.NewFlagSet(Name, flag.ContinueOnError)
	flags.SetOutput(cli.errStream)
	flags.Usage = func() {
		fmt.Fprintf(cli.errStream, usage, Name)
	}
	flags.StringVar(&config.Consul, "consul", "",
		"address of the Consul instance")
	flags.StringVar(&config.Token, "token", "",
		"a consul API token")
	flags.StringVar(&config.WaitRaw, "wait", "",
		"the minimum(:maximum) to wait before updating the environment")
	flags.StringVar(&config.Path, "config", "",
		"the path to a config file on disk")
	flags.DurationVar(&config.Timeout, "timeout", 0,
		"the time to wait for a process to restart")
	flags.BoolVar(&config.Sanitize, "sanitize", true,
		"remove bad characters from values")
	flags.BoolVar(&config.Upcase, "upcase", true,
		"convert all environment keys to uppercase")
	flags.BoolVar(&once, "once", false,
		"do not run as a daemon")
	flags.BoolVar(&version, "version", false, "display the version")

	// TODO: remove in v0.4.0 (deprecated)
	flags.StringVar(&datacenter, "dc", "",
		"DEPRECATED")
	flags.StringVar(&address, "addr", "",
		"DEPRECATED")
	flags.BoolVar(&errExit, "errexit", false,
		"DEPRECAETD")
	flags.BoolVar(&terminate, "terminate", false,
		"DEPRECAETD")
	flags.BoolVar(&reload, "reload", false,
		"DEPRECATED")

	// If there was a parser error, stop
	if err := flags.Parse(args[1:]); err != nil {
		return cli.handleError(err, ExitCodeParseFlagsError)
	}

	// TODO: remove in v0.4.0 (deprecated)
	if address != "" {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -addr flag is deprecated, please use -consul instead\n")
		config.Consul = address
	}

	if datacenter != "" {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -dc flag is deprecated, please use the @dc syntax instead\n")
	}

	if errExit {
		fmt.Fprintf(cli.errStream, "DEPRECATED: the -errexit flag is deprecated\n")
	}

	if terminate {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -terminate flag is deprecated, use -once instead\n")
	}

	if reload {
		fmt.Fprintf(cli.errStream,
			"DEPRECATED: the -reload flag is deprecated, use -once instead\n")
	}

	// If the version was requested, return an "error" containing the version
	// information. This might sound weird, but most *nix applications actually
	// print their version on stderr anyway.
{'fraction_non_alphanumeric': 0.12140248356464572, 'fraction_numerical': 0.004674945215485756, 'mean_word_length': 4.182437547312642, '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': '5569711', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2268, 'n_words': 716}