linstrom/flags.go

60 lines
1.5 KiB
Go
Raw Normal View History

2024-08-28 15:20:38 +00:00
package main
import (
"flag"
"fmt"
"os"
"github.com/rs/zerolog/log"
)
2024-08-28 15:20:38 +00:00
var (
flagLogJson *bool = flag.Bool(
"jsonlogs",
2024-08-28 15:20:38 +00:00
false,
"If set, writes logging messages as json objects instead",
2024-08-28 15:20:38 +00:00
)
flagConfigFile *string = flag.String(
"config",
"config.toml",
"Location of the config file",
2024-08-28 15:20:38 +00:00
)
flagLogLevel *string = flag.String(
"loglevel",
"Info",
"Set the logging level. Options are: Trace, Debug, Info, Warning, Error, Fatal. Capitalisation doesn't matter. Defaults to Info",
)
flagConfigOnly *bool = flag.Bool(
"validate-config",
false,
"If set, the server will only validate the config (or write the default one) and then quit",
)
2024-08-28 15:20:38 +00:00
)
func flagUsage() {
executable, err := os.Executable()
if err != nil {
log.Fatal().Err(err).Msg("Failed to get own path")
}
fmt.Fprintf(os.Stderr, "Usage of %s:\n", executable)
fmt.Fprintln(os.Stderr, "\t-config string")
fmt.Fprintln(os.Stderr, "\t\tLocation of the config file (default: \"config.toml\")")
fmt.Fprintln(os.Stderr, "\t-loglevel string")
fmt.Fprintln(
os.Stderr,
"\t\tSet the logging level. Options are: Trace, Debug, Info, Warning, Error and Fatal. Case insensitive (default: \"Info\")",
)
fmt.Fprintln(os.Stderr, "\t-validate-config")
fmt.Fprintln(
os.Stderr,
"\t\tIf set, the server will only validate the config (or write the default one) and then quit",
)
fmt.Fprintln(os.Stderr, "\t-jsonlogs")
fmt.Fprintln(os.Stderr, "\t\tIf set, writes logging messages as json objects instead")
}
2024-08-28 15:20:38 +00:00
func init() {
flag.Usage = flagUsage
2024-08-28 15:20:38 +00:00
flag.Parse()
}