#!/usr/bin/env bash
# commands/group/purge-stale.sh

function cmd::group::purge_stale::on_load() {
  flag::define --name  value "Group name (or --all)" label:name
  flag::define --all   bool  "Purge all groups"
  flag::define --force bool  "Skip confirmation"
  flag::define --dry-run bool "Show what would be removed"
  flag::exclusive --name --all
}

function cmd::group::purge_stale::run() {
  flag::parse "$@" || return 1
  local name;    name=$(flag::value --name)
  local all=false force=false dry_run=false
  flag::bool --all     && all=true
  flag::bool --force   && force=true
  flag::bool --dry-run && dry_run=true
  [[ -z "$name" && "$all" == "false" ]] && \
    log::error "Specify --name or --all" && return 1
  cmd::group::_purge_stale_impl "$name" "$all" "$force" "$dry_run"
}
