34 lines
No EOL
1 KiB
Bash
34 lines
No EOL
1 KiB
Bash
#!/usr/bin/env bash
|
|
# commands/mixins/<name>.mixin.sh
|
|
# Template for creating a new mixin
|
|
#
|
|
# 1. Copy this file to core/mixins/ (framework) or commands/mixins/ (wgctl-specific)
|
|
# 2. Replace <name> with your mixin name (e.g. peer_filter, time_filter)
|
|
# 3. Replace <FLAG> with your flag (e.g. --name, --since)
|
|
# 4. Add state variable and accessor function
|
|
# 5. In on_load: command::mixin <name>
|
|
|
|
# State variable
|
|
_COMMAND_<NAME>=false # or "" for string values
|
|
|
|
# Called when command::mixin <name> is used in on_load
|
|
function command::mixin::<name>::register() {
|
|
flag::register --<flag>
|
|
# Add more flag::register calls if needed
|
|
}
|
|
|
|
# Called before each command invocation to reset state
|
|
function command::mixin::<name>::reset() {
|
|
_COMMAND_<NAME>=false
|
|
}
|
|
|
|
# Called for each arg — return 0 if consumed, 1 if not
|
|
function command::mixin::<name>::process() {
|
|
case "$1" in
|
|
--<flag>) _COMMAND_<NAME>=true; return 0 ;;
|
|
esac
|
|
return 1
|
|
}
|
|
|
|
# Public accessor — used by commands
|
|
function command::<name>() { [[ "${_COMMAND_<NAME>:-false}" == "true" ]]; } |