#!/usr/bin/env bash
# commands/group/remove.sh

function cmd::group::remove::on_load() {
  flag::define --name  value "Group name" required label:name
  flag::define --force bool  "Skip confirmation"
}

function cmd::group::remove::run() {
  flag::parse "$@" || return 1
  local name; name=$(flag::value --name)
  local force=false; flag::bool --force && force=true
  [[ -z "$name" ]] && log::error "Missing required flag: --name" && return 1
  group::require_exists "$name" || return 1

  if ! $force; then
    read -r -p "Remove group '${name}'? [y/N] " confirm
    case "$confirm" in [yY]*) ;; *) log::info "Aborted"; return 0 ;; esac
  fi

  rm -f "$(group::path "$name")"
  log::wg_success "Group removed: ${name}"
}
