feat: CLI-Skeleton mit version/serve/check und Makefile
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NBHF4R9EAejDJUMdwr6C68
This commit is contained in:
parent
bb84607bf8
commit
fbfff90b38
8 changed files with 196 additions and 0 deletions
46
cmd/vpnportal/main.go
Normal file
46
cmd/vpnportal/main.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const usage = `vpnportal — VPN-Konfig-Portal für OPNsense
|
||||
|
||||
Aufruf:
|
||||
vpnportal serve [--config PFAD] Portal starten (Default)
|
||||
vpnportal check [--config PFAD] [--test-auth BENUTZER]
|
||||
vpnportal version
|
||||
|
||||
Optionen:
|
||||
--config PFAD Pfad zur Konfigurationsdatei (Default: /etc/vpnportal/config.yaml)
|
||||
`
|
||||
|
||||
func main() {
|
||||
os.Exit(run(os.Args[1:], os.Stdout, os.Stderr))
|
||||
}
|
||||
|
||||
func run(args []string, stdout, stderr io.Writer) int {
|
||||
cmd := "serve"
|
||||
rest := args
|
||||
if len(args) > 0 && len(args[0]) > 0 && args[0][0] != '-' {
|
||||
cmd, rest = args[0], args[1:]
|
||||
}
|
||||
|
||||
switch cmd {
|
||||
case "version":
|
||||
fmt.Fprintln(stdout, versionString())
|
||||
return 0
|
||||
case "serve":
|
||||
return runServe(rest, stdout, stderr)
|
||||
case "check":
|
||||
return runCheck(rest, stdout, stderr)
|
||||
case "help", "-h", "--help":
|
||||
fmt.Fprint(stdout, usage)
|
||||
return 0
|
||||
default:
|
||||
fmt.Fprintf(stderr, "Unbekanntes Kommando: %s\n\n%s", cmd, usage)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue