wgctl/commands/config.command.sh
2026-05-06 23:02:12 +00:00

64 lines
No EOL
1.3 KiB
Bash

#!/usr/bin/env bash
# ============================================
# Lifecycle
# ============================================
function cmd::config::on_load() {
flag::register --name
flag::register --type
}
# ============================================
# Help
# ============================================
function cmd::config::help() {
cat <<EOF
Usage: wgctl config --name <name>
Show the WireGuard config file for a client.
Options:
--name <name> Client name (e.g. phone-nuno)
Examples:
wgctl config --name phone-nuno
wgctl config --name laptop-nuno
EOF
}
# ============================================
# Run
# ============================================
function cmd::config::run() {
local name=""
local type=""
while [[ $# -gt 0 ]]; do
case "$1" in
--name) name="$2"; shift 2 ;;
--type) type="$2"; shift 2 ;;
--help) cmd::config::help; return ;;
*)
log::error "Unknown flag: $1"
cmd::config::help
return 1
;;
esac
done
if [[ -z "$name" ]]; then
log::error "Missing required flag: --name"
return 1
fi
name=$(peers::resolve_and_require "$name" "$type") || return 1
local conf
conf="$(ctx::clients)/${name}.conf"
log::section "Client Config: ${name}"
cat "$conf"
}