wgctl/core/framework/flag.sh.bak
Nuno Duque Nunes 8ed491313d feat: command framework + logs migration
- core/framework/flag.sh: flag::define, flag::parse, accessors
- core/framework/hook.sh: hook::on, hook::fire, hook::off, hook::has
- core/framework/help.sh: help::section, command::help::auto
- core/framework/command.sh: command::define, command::route, lazy loading
- core restructure: framework/ + app/ separation
- load_command: directory-based command detection
- command::exists: accepts new-style commands
- command::run: routing for new-style, legacy fallback
- commands/logs/: migrated to new framework
  - logs.sh: router + command::define
  - show.sh: flag::define + flag::parse, no manual case blocks
  - clean.sh: flag::define + flag::parse
  - remove.sh: flag::define + flag::parse
  - rotate.sh: flag::define + flag::parse
- logs clean: fix dry_run bool to int conversion
- ctx::json_helper: fixed path after core restructure
- PYTHONPATH: exported in app/core.sh
2026-05-30 03:44:08 +00:00

66 lines
1.3 KiB
Bash

#!/usr/bin/env bash
# ============================================
# Flag Registry
# ============================================
declare -A _REGISTERED_FLAGS=()
# ============================================
# Registration
# ============================================
function flag::register() {
local flag="$1"
_REGISTERED_FLAGS["$flag"]=1
}
function flag::registered() {
[[ -n "${_REGISTERED_FLAGS["$1"]:-}" ]]
}
# ============================================
# Parsing
# ============================================
# Parse flags from args into associative array
# Usage: flag::parse "$@"
# Access: flag::get --name
declare -A _FLAG_VALUES=()
function flag::parse() {
_FLAG_VALUES=()
while [[ $# -gt 0 ]]; do
case "$1" in
--*)
local key="$1"
# Boolean flag (no value follows, or next arg is another flag)
if [[ $# -eq 1 || "$2" == --* ]]; then
_FLAG_VALUES["$key"]="true"
shift
else
_FLAG_VALUES["$key"]="$2"
shift 2
fi
;;
*)
shift
;;
esac
done
}
function flag::get() {
echo "${_FLAG_VALUES["$1"]:-}"
}
function flag::enabled() {
[[ "${_FLAG_VALUES["$1"]:-}" == "true" ]]
}
function flag::set() {
local key="$1"
local value="$2"
_FLAG_VALUES["$key"]="$value"
}