Ultima attività 1 month ago

Revisione e97e1a574b8d37cf8beee621e04416d16e0d0a98

gistfile1.txt Raw
1#!/usr/bin/env bash
2
3function cmd::inspect::on_load() {
4 flag::register --name
5 flag::register --type
6}
7
8function cmd::inspect::help() {
9 cat <<EOF
10Usage: wgctl inspect --name <name> [--type <type>]
11 wgctl inspect <full-name>
12
13Show detailed information for a single client.
14
15Options:
16 --name <name> Client name
17 --type <type> Device type (optional, combines with --name)
18
19Examples:
20 wgctl inspect --name phone-nuno
21 wgctl inspect --name nuno --type phone
22EOF
23}
24
25function cmd::inspect::run() {
26 local name=""
27 local type=""
28
29 # Support positional argument: wgctl inspect phone-nuno
30 if [[ $# -gt 0 && "$1" != "--"* ]]; then
31 name="$1"
32 shift
33 fi
34
35 while [[ $# -gt 0 ]]; do
36 case "$1" in
37 --name) name="$2"; shift 2 ;;
38 --type) type="$2"; shift 2 ;;
39 --help) cmd::inspect::help; return ;;
40 *)
41 log::error "Unknown flag: $1"
42 cmd::inspect::help
43 return 1
44 ;;
45 esac
46 done
47
48 if [[ -z "$name" ]]; then
49 log::error "Missing required flag: --name"
50 cmd::inspect::help
51 return 1
52 fi
53
54 name=$(peers::resolve_and_require "$name" "$type") || return 1
55
56 load_command list
57 cmd::list::run --name "$name"
58}