<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"os/signal"
	"runtime"
	"strings"
	"syscall"

	"github.com/gotomgo/overt-flake/flake"
	"github.com/gotomgo/overt-flake/ofsserver"
)

var usage = `Usage: ofsrvr [options]
Options:
    -ip              specify the network interface/address to listen on                 default=0.0.0.0:4444
    -hidtype         specify the type of the hardware ID provider                       default=mac
    -gentype         specify the type of generator used to generate IDs                 default=default
    -epoch           specify the epoch in milliseconds elapsed since Unix Epoch         default=1483228800000
    -waitfor         specify a time at which id generation may start, but not before    default=0
    -auth            specify the sequence of characters that make up the auth token     default=""
    -config          specify a path to a configuration file                             default=""
    -hid             specify a hardware id to use when -hidype == "fixed"               default=""

Notes:
* arguments specified on the command-line override values specified in -config file
* waitfor *must* be specified on the command line

Hid Types:
    simple           simple MAC hardware ID provider
    mac              standard MAC hardware ID provider (default)
    fixed            specifies that a fixed hardware id is used (see -hid)

Generator Types:
    default          the standard overt-flake ID generator

Common Options:
    -help, --help    Show this message
    -v, --version    Show version
`

func showUsage() {
	fmt.Fprintf(os.Stderr, "%s\n", usage)
	os.Exit(0)
}

func showAppVersion() {
	fmt.Fprintf(os.Stderr, `ofsrvr: %s, Runtime: %s, Compiler: %s, Copyright © 2017 Overtone Studios, Inc.`,
		"0.5.0",
		runtime.Compiler,
		runtime.Version())
	fmt.Fprintln(os.Stderr, "")
}

func showError(fmtstr string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, fmtstr, args...)
	fmt.Fprintln(os.Stderr, "")
	os.Exit(-1)
}

func showErrorWithUsage(fmtstr string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, fmtstr, args...)
	fmt.Fprintln(os.Stderr, "")
	fmt.Fprintf(os.Stderr, "%s\n", usage)
	os.Exit(-1)
}

func createHardwareIDProvider(hidType string, fixedID []byte) (flake.HardwareIDProvider, error) {
	var hidProvider flake.HardwareIDProvider

	switch strings.ToLower(hidType) {
	case "mac":
		hidProvider = flake.NewMacHardwareIDProvider()
		break
	case "simple":
		hidProvider = flake.NewSimpleMacHardwareIDProvider()
		break
	case "fixed":
		// A fixed Hardware ID is used. Create a fixed provider
		hidProvider = flake.NewFixedHardwareIDProvider(fixedID)
		break
	default:
		showErrorWithUsage("Unsupported type for Hardware ID provider: %s", hidType)
	}

	return hidProvider, nil
}

func createOvertFlakeIDGenerator(genType string, epoch int64, hardwareID flake.HardwareID, waitForTime int64) (flake.Generator, error) {
	var generator flake.Generator

	switch strings.ToLower(genType) {
	case "default":
		generator = flake.NewGenerator(epoch, hardwareID, os.Getpid(), waitForTime)
		break
	default:
		showErrorWithUsage("Unsupported type for Generator: %s", genType)
	}

	return generator, nil
}

func main() {
	showAppVersion()

	// args that can override configuration
	var argIPAddr string
	var argHidType string
	var argGenType string
	var argEpoch int64<commit_msg>fix issue caused by re-factor<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"os/signal"
	"runtime"
	"strings"
	"syscall"

	"github.com/gotomgo/overt-flake/flake"
	"github.com/gotomgo/overt-flake/ofsserver"
)

var usage = `Usage: ofsrvr [options]
Options:
    -ip              specify the network interface/address to listen on                 default=0.0.0.0:4444
    -hidtype         specify the type of the hardware ID provider                       default=mac
    -gentype         specify the type of generator used to generate IDs                 default=default
    -epoch           specify the epoch in milliseconds elapsed since Unix Epoch         default=1483228800000
    -waitfor         specify a time at which id generation may start, but not before    default=0
    -auth            specify the sequence of characters that make up the auth token     default=""
    -config          specify a path to a configuration file                             default=""
    -hid             specify a hardware id to use when -hidype == "fixed"               default=""

Notes:
* arguments specified on the command-line override values specified in -config file
* waitfor *must* be specified on the command line

Hid Types:
    simple           simple MAC hardware ID provider
    mac              standard MAC hardware ID provider (default)
    fixed            specifies that a fixed hardware id is used (see -hid)

Generator Types:
    default          the standard overt-flake ID generator

Common Options:
    -help, --help    Show this message
    -v, --version    Show version
`

func showUsage() {
	fmt.Fprintf(os.Stderr, "%s\n", usage)
	os.Exit(0)
}

func showAppVersion() {
	fmt.Fprintf(os.Stderr, `ofsrvr: %s, Runtime: %s, Compiler: %s, Copyright © 2017 Overtone Studios, Inc.`,
		"0.5.1",
		runtime.Compiler,
		runtime.Version())
	fmt.Fprintln(os.Stderr, "")
}

func showError(fmtstr string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, fmtstr, args...)
	fmt.Fprintln(os.Stderr, "")
	os.Exit(-1)
}

func showErrorWithUsage(fmtstr string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, fmtstr, args...)
	fmt.Fprintln(os.Stderr, "")
	fmt.Fprintf(os.Stderr, "%s\n", usage)
	os.Exit(-1)
}

func createHardwareIDProvider(hidType string, fixedID []byte) (flake.HardwareIDProvider, error) {
	var hidProvider flake.HardwareIDProvider

	switch strings.ToLower(hidType) {
	case "mac":
		hidProvider = flake.NewMacHardwareIDProvider()
		break
	case "simple":
		hidProvider = flake.NewSimpleMacHardwareIDProvider()
		break
	case "fixed":
		// A fixed Hardware ID is used. Create a fixed provider
		hidProvider = flake.NewFixedHardwareIDProvider(fixedID)
		break
	default:
		showErrorWithUsage("Unsupported type for Hardware ID provider: %s", hidType)
	}

	return hidProvider, nil
}

func createOvertFlakeIDGenerator(genType string, epoch int64, hardwareID flake.HardwareID, waitForTime int64) (flake.Generator, error) {
	var generator flake.Generator

	switch strings.ToLower(genType) {
	case "default":
		generator = flake.NewOvertFlakeGenerator(epoch, hardwareID, os.Getpid(), waitForTime)
		break
	default:
		showErrorWithUsage("Unsupported type for Generator: %s", genType)
	}

	return generator, nil
}

func main() {
	showAppVersion()

	// args that can override configuration
	var argIPAddr string
	var argHidType string
	var argGenType string
	var argEpoch int64
{'fraction_non_alphanumeric': 0.09590868662911355, 'fraction_numerical': 0.011265935369107619, 'mean_word_length': 3.064457831325301, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3640864', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2086, 'n_words': 647}