<commit_before>// Copyright 2016 Apcera Inc. All rights reserved.

package main

import (
	"flag"
	"os"
	"runtime"
	"strings"

	"fmt"
	natsd "github.com/nats-io/gnatsd/server"
	"github.com/nats-io/stan"
	stand "github.com/nats-io/stan-server/server"
	"github.com/nats-io/stan-server/stores"
)

func main() {

	// Parse flags
	sOpts, nOpts := parseFlags()
	stand.EnableDefaultLogger(&nOpts)
	stand.Noticef("Starting stan-server[%s] version %s", sOpts.ID, stan.Version)
	stand.RunServerWithOpts(&sOpts, &nOpts)

	runtime.Goexit()
}

func parseFlags() (stand.Options, natsd.Options) {
	var showVersion bool
	var debugAndTrace bool
	var showTLSHelp bool
	var configFile string

	stanOpts := stand.DefaultOptions
	flag.StringVar(&stanOpts.ID, "cluster_id", stand.DefaultClusterID, "Cluster ID.")
	flag.StringVar(&stanOpts.StoreType, "store", stores.TypeMemory, fmt.Sprintf("Store type: (%s|%s)", stores.TypeMemory, stores.TypeFile))
	flag.StringVar(&stanOpts.FilestoreDir, "dir", "", "Root directory")
	flag.IntVar(&stanOpts.MaxChannels, "max_channels", stand.DefaultChannelLimit, "Max number of channels")
	flag.IntVar(&stanOpts.MaxSubscriptions, "max_subs", stand.DefaultSubStoreLimit, "Max number of subscriptions per channel")
	flag.IntVar(&stanOpts.MaxMsgs, "max_msgs", stand.DefaultMsgStoreLimit, "Max number of messages per channel")
	flag.Uint64Var(&stanOpts.MaxBytes, "max_bytes", stand.DefaultMsgSizeStoreLimit, "Max messages total size per channel")

	natsOpts := natsd.Options{}

	// TODO: Expose gnatsd parsing into server options
	// (cls) This is a development placeholder until gnatsd
	// options parsing is exposed, if we go that way.
	flag.IntVar(&natsOpts.Port, "port", 0, "Port to listen on.")
	flag.IntVar(&natsOpts.Port, "p", 0, "Port to listen on.")
	flag.StringVar(&natsOpts.Host, "addr", "", "Network host to listen on.")
	flag.StringVar(&natsOpts.Host, "a", "", "Network host to listen on.")
	flag.StringVar(&natsOpts.Host, "net", "", "Network host to listen on.")
	flag.BoolVar(&natsOpts.Debug, "D", false, "Enable Debug logging.")
	flag.BoolVar(&natsOpts.Debug, "debug", false, "Enable Debug logging.")
	flag.BoolVar(&natsOpts.Trace, "V", false, "Enable Trace logging.")
	flag.BoolVar(&natsOpts.Trace, "trace", false, "Enable Trace logging.")
	flag.BoolVar(&debugAndTrace, "DV", false, "Enable Debug and Trace logging.")
	flag.BoolVar(&natsOpts.Logtime, "T", true, "Timestamp log entries.")
	flag.BoolVar(&natsOpts.Logtime, "logtime", true, "Timestamp log entries.")
	flag.StringVar(&natsOpts.Username, "user", "", "Username required for connection.")
	flag.StringVar(&natsOpts.Password, "pass", "", "Password required for connection.")
	flag.StringVar(&natsOpts.Authorization, "auth", "", "Authorization token required for connection.")
	flag.IntVar(&natsOpts.HTTPPort, "m", 0, "HTTP Port for /varz, /connz endpoints.")
	flag.IntVar(&natsOpts.HTTPPort, "http_port", 0, "HTTP Port for /varz, /connz endpoints.")
	flag.IntVar(&natsOpts.HTTPSPort, "ms", 0, "HTTPS Port for /varz, /connz endpoints.")
	flag.IntVar(&natsOpts.HTTPSPort, "https_port", 0, "HTTPS Port for /varz, /connz endpoints.")
	flag.StringVar(&configFile, "c", "", "Configuration file.")
	flag.StringVar(&configFile, "config", "", "Configuration file.")
	flag.StringVar(&natsOpts.PidFile, "P", "", "File to store process pid.")
	flag.StringVar(&natsOpts.PidFile, "pid", "", "File to store process pid.")
	flag.StringVar(&natsOpts.LogFile, "l", "", "File to store logging output.")
	flag.StringVar(&natsOpts.LogFile, "log", "", "File to store logging output.")
	flag.BoolVar(&natsOpts.Syslog, "s", false, "Enable syslog as log method.")
	flag.BoolVar(&natsOpts.Syslog, "syslog", false, "Enable syslog as log method..")
	flag.StringVar(&natsOpts.RemoteSyslog, "r", "", "Syslog server addr (udp://localhost:514).")
	flag.StringVar(&natsOpts.RemoteSyslog, "remote_syslog", "", "Syslog server addr (udp://localhost:514).")
	flag.BoolVar(&showVersion, "version", false, "Print version information.")
	flag.BoolVar(&showVersion, "v", false, "Print version information.")
	flag.IntVar(&natsOpts.ProfPort, "profile", 0, "Profiling HTTP port")
	flag.StringVar(&natsOpts.RoutesStr, "routes", "", "Routes to actively solicit a connection.")
	flag.StringVar(&natsOpts.ClusterListenStr, "cluster", "", "Cluster url from which members can solicit routes.")
	flag.StringVar(&natsOpts.ClusterListenStr, "cluster_listen", "", "Cluster url from which members can solicit routes.")
	flag.BoolVar(&showTLSHelp, "help_tls", false, "TLS help.")
	flag.BoolVar(&natsOpts.TLS, "tls", false, "Enable TLS.")
	flag.BoolVar(&natsOpts.TLSVerify, "tlsverify", false, "Enable TLS with client verification.")
	flag.StringVar(&natsOpts.TLSCert, "tlscert", "", "Server certificate file.")
	flag.StringVar(&natsOpts.TLSKey, "tlskey", "", "Private key for server certificate.")
	flag.StringVar(&natsOpts.TLSCaCert, "tlscacert", "", "Client certificate CA for verification.")

	// Not public per se, will be replaced with dynamic system, but can be used to lower memory footprint when

	flag.Usage = stand.Usage
	flag.Parse()

	// Show version and exit
	if showVersion {
		fmt.Printf("stan-server version %s, ", stan.Version)
		natsd.PrintServerAndExit()
	}

	if showTLSHelp {
		natsd.PrintTLSHelpAndDie()
	}

	// Ensure some options are set based on selected store type<commit_msg>Remove comment.<commit_after>// Copyright 2016 Apcera Inc. All rights reserved.

package main

import (
	"flag"
	"os"
	"runtime"
	"strings"

	"fmt"
	natsd "github.com/nats-io/gnatsd/server"
	"github.com/nats-io/stan"
	stand "github.com/nats-io/stan-server/server"
	"github.com/nats-io/stan-server/stores"
)

func main() {

	// Parse flags
	sOpts, nOpts := parseFlags()
	stand.EnableDefaultLogger(&nOpts)
	stand.Noticef("Starting stan-server[%s] version %s", sOpts.ID, stan.Version)
	stand.RunServerWithOpts(&sOpts, &nOpts)

	runtime.Goexit()
}

func parseFlags() (stand.Options, natsd.Options) {
	var showVersion bool
	var debugAndTrace bool
	var showTLSHelp bool
	var configFile string

	stanOpts := stand.DefaultOptions
	flag.StringVar(&stanOpts.ID, "cluster_id", stand.DefaultClusterID, "Cluster ID.")
	flag.StringVar(&stanOpts.StoreType, "store", stores.TypeMemory, fmt.Sprintf("Store type: (%s|%s)", stores.TypeMemory, stores.TypeFile))
	flag.StringVar(&stanOpts.FilestoreDir, "dir", "", "Root directory")
	flag.IntVar(&stanOpts.MaxChannels, "max_channels", stand.DefaultChannelLimit, "Max number of channels")
	flag.IntVar(&stanOpts.MaxSubscriptions, "max_subs", stand.DefaultSubStoreLimit, "Max number of subscriptions per channel")
	flag.IntVar(&stanOpts.MaxMsgs, "max_msgs", stand.DefaultMsgStoreLimit, "Max number of messages per channel")
	flag.Uint64Var(&stanOpts.MaxBytes, "max_bytes", stand.DefaultMsgSizeStoreLimit, "Max messages total size per channel")

	natsOpts := natsd.Options{}

	// TODO: Expose gnatsd parsing into server options
	// (cls) This is a development placeholder until gnatsd
	// options parsing is exposed, if we go that way.
	flag.IntVar(&natsOpts.Port, "port", 0, "Port to listen on.")
	flag.IntVar(&natsOpts.Port, "p", 0, "Port to listen on.")
	flag.StringVar(&natsOpts.Host, "addr", "", "Network host to listen on.")
	flag.StringVar(&natsOpts.Host, "a", "", "Network host to listen on.")
	flag.StringVar(&natsOpts.Host, "net", "", "Network host to listen on.")
	flag.BoolVar(&natsOpts.Debug, "D", false, "Enable Debug logging.")
	flag.BoolVar(&natsOpts.Debug, "debug", false, "Enable Debug logging.")
	flag.BoolVar(&natsOpts.Trace, "V", false, "Enable Trace logging.")
	flag.BoolVar(&natsOpts.Trace, "trace", false, "Enable Trace logging.")
	flag.BoolVar(&debugAndTrace, "DV", false, "Enable Debug and Trace logging.")
	flag.BoolVar(&natsOpts.Logtime, "T", true, "Timestamp log entries.")
	flag.BoolVar(&natsOpts.Logtime, "logtime", true, "Timestamp log entries.")
	flag.StringVar(&natsOpts.Username, "user", "", "Username required for connection.")
	flag.StringVar(&natsOpts.Password, "pass", "", "Password required for connection.")
	flag.StringVar(&natsOpts.Authorization, "auth", "", "Authorization token required for connection.")
	flag.IntVar(&natsOpts.HTTPPort, "m", 0, "HTTP Port for /varz, /connz endpoints.")
	flag.IntVar(&natsOpts.HTTPPort, "http_port", 0, "HTTP Port for /varz, /connz endpoints.")
	flag.IntVar(&natsOpts.HTTPSPort, "ms", 0, "HTTPS Port for /varz, /connz endpoints.")
	flag.IntVar(&natsOpts.HTTPSPort, "https_port", 0, "HTTPS Port for /varz, /connz endpoints.")
	flag.StringVar(&configFile, "c", "", "Configuration file.")
	flag.StringVar(&configFile, "config", "", "Configuration file.")
	flag.StringVar(&natsOpts.PidFile, "P", "", "File to store process pid.")
	flag.StringVar(&natsOpts.PidFile, "pid", "", "File to store process pid.")
	flag.StringVar(&natsOpts.LogFile, "l", "", "File to store logging output.")
	flag.StringVar(&natsOpts.LogFile, "log", "", "File to store logging output.")
	flag.BoolVar(&natsOpts.Syslog, "s", false, "Enable syslog as log method.")
	flag.BoolVar(&natsOpts.Syslog, "syslog", false, "Enable syslog as log method..")
	flag.StringVar(&natsOpts.RemoteSyslog, "r", "", "Syslog server addr (udp://localhost:514).")
	flag.StringVar(&natsOpts.RemoteSyslog, "remote_syslog", "", "Syslog server addr (udp://localhost:514).")
	flag.BoolVar(&showVersion, "version", false, "Print version information.")
	flag.BoolVar(&showVersion, "v", false, "Print version information.")
	flag.IntVar(&natsOpts.ProfPort, "profile", 0, "Profiling HTTP port")
	flag.StringVar(&natsOpts.RoutesStr, "routes", "", "Routes to actively solicit a connection.")
	flag.StringVar(&natsOpts.ClusterListenStr, "cluster", "", "Cluster url from which members can solicit routes.")
	flag.StringVar(&natsOpts.ClusterListenStr, "cluster_listen", "", "Cluster url from which members can solicit routes.")
	flag.BoolVar(&showTLSHelp, "help_tls", false, "TLS help.")
	flag.BoolVar(&natsOpts.TLS, "tls", false, "Enable TLS.")
	flag.BoolVar(&natsOpts.TLSVerify, "tlsverify", false, "Enable TLS with client verification.")
	flag.StringVar(&natsOpts.TLSCert, "tlscert", "", "Server certificate file.")
	flag.StringVar(&natsOpts.TLSKey, "tlskey", "", "Private key for server certificate.")
	flag.StringVar(&natsOpts.TLSCaCert, "tlscacert", "", "Client certificate CA for verification.")

	flag.Usage = stand.Usage
	flag.Parse()

	// Show version and exit
	if showVersion {
		fmt.Printf("stan-server version %s, ", stan.Version)
		natsd.PrintServerAndExit()
	}

	if showTLSHelp {
		natsd.PrintTLSHelpAndDie()
	}

	// Ensure some options are set based on selected store type
{'fraction_non_alphanumeric': 0.1596399810516343, 'fraction_numerical': 0.0036001894836570347, 'mean_word_length': 5.552451893234016, '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': '5646693', 'n_tokens_mistral': 3536, 'n_tokens_neox': 3575, 'n_words': 903}