- core/command_mixins.sh: mixin infrastructure with auto-loader - core/mixins/json_output.mixin.sh: --json flag mixin - core/mixins/no_color.mixin.sh: --no-color flag mixin - commands/mixins/MIXIN_TEMPLATE.mixin.sh: template for new mixins - command::run: reset mixin state, preprocess flags before dispatch - command::_preprocess_flags: nameref-based flag stripping, empty array fix - command::mixin: opt-in registration from on_load - list --json: structured JSON output with envelope - inspect --json: structured JSON peer detail output - json::envelope, json::error_envelope helpers
21 lines
No EOL
482 B
Bash
21 lines
No EOL
482 B
Bash
#!/usr/bin/env bash
|
|
# core/mixins/json_output.mixin.sh
|
|
# Adds --json flag support to any command
|
|
|
|
_COMMAND_JSON=false
|
|
|
|
function command::mixin::json_output::register() {
|
|
flag::register --json
|
|
}
|
|
|
|
function command::mixin::json_output::reset() {
|
|
_COMMAND_JSON=false
|
|
}
|
|
|
|
function command::mixin::json_output::process() {
|
|
[[ "$1" == "--json" ]] && _COMMAND_JSON=true && return 0
|
|
return 1
|
|
}
|
|
|
|
# Public accessor
|
|
function command::json() { [[ "${_COMMAND_JSON:-false}" == "true" ]]; } |