#!/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" ]]; }