1
0
Fork 0
mirror of https://github.com/SamTherapy/dnscrypt.git synced 2024-11-30 16:41:13 +00:00
dnscrypt/cmd/main.go
2023-03-15 18:57:22 +03:00

54 lines
1.7 KiB
Go

// Package main is responsible for the command-line interface.
package main
import (
"os"
"github.com/AdguardTeam/golibs/log"
goFlags "github.com/jessevdk/go-flags"
)
// Options - command-line options
type Options struct {
Generate GenerateArgs `command:"generate" description:"Generates DNSCrypt server configuration"`
LookupStamp LookupStampArgs `command:"lookup-stamp" description:"Performs a DNSCrypt lookup for the specified domain using an sdns:// stamp"`
Lookup LookupArgs `command:"lookup" description:"Performs a DNSCrypt lookup for the specified domain"`
Server ServerArgs `command:"server" description:"Runs a DNSCrypt resolver"`
ConvertWrapper ConvertWrapperArgs `command:"convert-dnscrypt-wrapper" description:"Converting keys generated with dnscrypt-wrapper to yaml config"`
Version struct {
} `command:"version" description:"Prints version"`
}
// VersionString will be set through ldflags, contains current version
var VersionString = "1.0"
func main() {
var opts Options
var parser = goFlags.NewParser(&opts, goFlags.Default)
_, err := parser.Parse()
if err != nil {
if flagsErr, ok := err.(*goFlags.Error); ok && flagsErr.Type == goFlags.ErrHelp {
os.Exit(0)
} else {
os.Exit(1)
}
}
switch parser.Active.Name {
case "version":
log.Printf("dnscrypt version %s\n", VersionString)
case "generate":
generate(opts.Generate)
case "lookup-stamp":
lookupStamp(opts.LookupStamp)
case "lookup":
lookup(opts.Lookup)
case "server":
server(opts.Server)
case "convert-dnscrypt-wrapper":
convertWrapper(opts.ConvertWrapper)
default:
log.Fatalf("unknown command %s", parser.Active.Name)
}
}